Merge branch 'IfcOpenShell:v0.7.0' into v0.7.0

This commit is contained in:
Carlos Villagrasa
2022-07-28 23:50:10 +02:00
committed by GitHub
5 changed files with 101 additions and 36 deletions
@@ -0,0 +1,44 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>, 2021-2022 Yassine Oualid <yassine@sigmadimensions.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.tool as tool
def refresh():
SequenceData.is_loaded = False
class SequenceData:
is_loaded = False
number_of_work_plans_loaded = 0
number_of_work_schedules_loaded = 0
number_of_tasks_loaded = 0
tasks = {}
@classmethod
def load(cls):
cls.load_work_plans()
cls.is_loaded = True
@classmethod
def load_work_plans(cls):
cls.work_plans = {}
cls.number_of_work_plans_loaded = len(tool.Ifc.get().by_type("IfcWorkPlan"))
for work_plan in tool.Ifc.get().by_type("IfcWorkPlan"):
cls.work_plans[work_plan.id()] = {"Name": work_plan.Name}
@@ -24,6 +24,7 @@ from blenderbim.bim.helper import draw_attributes
from ifcopenshell.api.sequence.data import Data from ifcopenshell.api.sequence.data import Data
from ifcopenshell.api.resource.data import Data as ResourceData from ifcopenshell.api.resource.data import Data as ResourceData
import blenderbim.bim.module.sequence.helper as helper import blenderbim.bim.module.sequence.helper as helper
from blenderbim.bim.module.sequence.data import SequenceData
from datetime import datetime from datetime import datetime
@@ -42,18 +43,18 @@ class BIM_PT_work_plans(Panel):
return file and file.schema != "IFC2X3" return file and file.schema != "IFC2X3"
def draw(self, context): def draw(self, context):
if not Data.is_loaded: if not SequenceData.is_loaded:
Data.load(IfcStore.get_file()) SequenceData.load()
self.props = context.scene.BIMWorkPlanProperties self.props = context.scene.BIMWorkPlanProperties
row = self.layout.row() row = self.layout.row()
row.label( row.label(
text="{} Work Plans Found".format(len(Data.work_plans.items())), text="{} Work Plans Found".format(SequenceData.number_of_work_plans_loaded),
icon="MOD_SIMPLIFY", icon="TEXT",
) )
row.operator("bim.add_work_plan", icon="ADD") row.operator("bim.add_work_plan", icon="ADD")
for work_plan_id, work_plan in Data.work_plans.items(): for work_plan_id, work_plan in SequenceData.work_plans.items():
self.draw_work_plan_ui(work_plan_id, work_plan) self.draw_work_plan_ui(work_plan_id, work_plan)
def draw_work_plan_ui(self, work_plan_id, work_plan): def draw_work_plan_ui(self, work_plan_id, work_plan):
+7 -14
View File
@@ -17,35 +17,28 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
# def load_work_plans(ifc, sequence):
# pass
def add_work_plan(ifc, sequence): def add_work_plan(ifc, sequence):
ifc.run("sequence.add_work_plan") ifc.run("sequence.add_work_plan")
sequence.load_sequence_data() sequence.load_work_plans()
def remove_work_plan(ifc, sequence, work_plan=None): def remove_work_plan(ifc, sequence, work_plan=None):
ifc.run("sequence.remove_work_plan",**{"work_plan": ifc.get().by_id(work_plan)}) ifc.run("sequence.remove_work_plan",**{"work_plan": ifc.get().by_id(work_plan)})
sequence.load_sequence_data() sequence.load_work_plans()
def load_work_plan_attributes(sequence, work_plan=None): def load_work_plan_attributes(sequence, work_plan=None):
data = sequence.get_work_plan_attributes(work_plan) data = sequence.get_ifc_work_plan_attributes(work_plan)
sequence.load_work_plan_attributes(data) sequence.load_work_plan_attributes(data)
def enable_editing_work_plan(sequence, work_plan=None): def enable_editing_work_plan(sequence, work_plan=None):
load_work_plan_attributes(sequence, work_plan) load_work_plan_attributes(sequence, work_plan)
sequence.enable_editing_work_plan(work_plan) sequence.enable_editing_work_plan(work_plan)
print("Yassine Is back in the game")
def disable_editing_work_plan(sequence): def disable_editing_work_plan(sequence):
sequence.disable_editing_work_plan() sequence.disable_editing_work_plan()
def edit_work_plan(ifc, sequence): def edit_work_plan(ifc, sequence):
work_plan = sequence.get_current_work_plan() work_plan = sequence.get_current_ifc_work_plan()
attributes = sequence.get_current_work_plan_attributes() attributes = sequence.get_work_plan_attributes()
ifc.run("sequence.edit_work_plan",**{"work_plan": work_plan, "attributes": attributes}) ifc.run("sequence.edit_work_plan",**{"work_plan": work_plan, "attributes": attributes})
disable_editing_work_plan(sequence) sequence.disable_editing_work_plan()
sequence.load_sequence_data() sequence.load_work_plans()
+13
View File
@@ -421,6 +421,19 @@ class Selector:
def set_active(cls, obj): pass def set_active(cls, obj): pass
@interface
class Sequence:
def get_work_plans(cls): pass
def load_work_plans(cls): pass
def enable_editing_work_plan(cls, work_plan): pass
def disable_editing_work_plan(cls): pass
def get_current_ifc_work_plan(cls): pass
def get_ifc_work_plan_attributes(cls): pass
def load_work_plan_attributes(cls): pass
def import_attributes(cls): pass
def export_attributes(cls): pass
@interface @interface
class Spatial: class Spatial:
def can_contain(cls, structure_obj, element_obj): pass def can_contain(cls, structure_obj, element_obj): pass
+31 -17
View File
@@ -23,7 +23,6 @@ import blenderbim.core.tool
import blenderbim.tool as tool import blenderbim.tool as tool
import blenderbim.bim.helper import blenderbim.bim.helper
import blenderbim.bim.module.sequence.helper as helper import blenderbim.bim.module.sequence.helper as helper
from ifcopenshell.api.sequence.data import Data
class Sequence(blenderbim.core.tool.Sequence): class Sequence(blenderbim.core.tool.Sequence):
@@ -35,8 +34,14 @@ class Sequence(blenderbim.core.tool.Sequence):
return work_plans return work_plans
@classmethod @classmethod
def load_sequence_data(cls): def load_work_plans(cls):
Data.load(tool.Ifc.get()) work_plans = tool.Sequence.get_work_plans()
props = bpy.context.scene.BIMWorkPlanProperties
props.work_plans.clear()
for ifc_definition_id, work_plan in work_plans.items():
new = props.work_plans.add()
new.ifc_definition_id = ifc_definition_id
new.name = work_plan["Name"] or "Unnamed"
@classmethod @classmethod
def enable_editing_work_plan(cls, work_plan): def enable_editing_work_plan(cls, work_plan):
@@ -49,13 +54,28 @@ class Sequence(blenderbim.core.tool.Sequence):
bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = 0 bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = 0
@classmethod @classmethod
def get_work_plan_attributes(cls, work_plan): def get_current_ifc_work_plan(cls):
if Data.is_loaded: active_work_plan = bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id
return Data.work_plans[work_plan] ifc_work_plan = tool.Ifc.get().by_id(active_work_plan)
else: return ifc_work_plan
Data.load(tool.Ifc.get())
return Data.work_plans[work_plan] @classmethod
def get_ifc_work_plan_attributes(cls, work_plan):
if work_plan:
ifc_work_plan = tool.Ifc.get().by_id(work_plan)
data = ifc_work_plan.get_info()
del data["OwnerHistory"]
if data["Creators"]:
data["Creators"] = [p.id() for p in data["Creators"]]
data["CreationDate"] = ifcopenshell.util.date.ifc2datetime(data["CreationDate"])
data["StartTime"] = ifcopenshell.util.date.ifc2datetime(data["StartTime"])
if data["FinishTime"]:
data["FinishTime"] = ifcopenshell.util.date.ifc2datetime(data["FinishTime"])
data["IsDecomposedBy"] = []
for rel in ifc_work_plan.IsDecomposedBy:
data["IsDecomposedBy"].extend([o.id() for o in rel.RelatedObjects])
return data
@classmethod @classmethod
def load_work_plan_attributes(cls, data): def load_work_plan_attributes(cls, data):
props = bpy.context.scene.BIMWorkPlanProperties props = bpy.context.scene.BIMWorkPlanProperties
@@ -68,17 +88,11 @@ class Sequence(blenderbim.core.tool.Sequence):
return True return True
@classmethod @classmethod
def get_current_work_plan_attributes(cls): def get_work_plan_attributes(cls):
props = bpy.context.scene.BIMWorkPlanProperties props = bpy.context.scene.BIMWorkPlanProperties
attributes = blenderbim.bim.helper.export_attributes(props.work_plan_attributes, tool.Sequence.export_attributes) attributes = blenderbim.bim.helper.export_attributes(props.work_plan_attributes, tool.Sequence.export_attributes)
return attributes return attributes
@classmethod
def get_current_work_plan(cls):
active_work_plan = bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id
ifc_work_plan = tool.Ifc.get().by_id(active_work_plan)
return ifc_work_plan
def export_attributes(attributes, prop): def export_attributes(attributes, prop):
if "Date" in prop.name or "Time" in prop.name: if "Date" in prop.name or "Time" in prop.name:
if prop.is_null: if prop.is_null: