mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
WIP refactor sequence module
This commit is contained in:
@@ -59,12 +59,8 @@ class AddWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Add Work Plan"
|
bl_label = "Add Work Plan"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.add_work_plan(tool.Ifc, tool.Sequence)
|
core.add_work_plan(tool.Ifc, tool.Sequence)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EditWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
class EditWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -72,12 +68,8 @@ class EditWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_label = "Edit Work Plan"
|
bl_label = "Edit Work Plan"
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.edit_work_plan(tool.Ifc, tool.Sequence)
|
core.edit_work_plan(tool.Ifc, tool.Sequence)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -86,33 +78,27 @@ class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
work_plan: bpy.props.IntProperty()
|
work_plan: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.remove_work_plan(tool.Ifc, tool.Sequence, work_plan=self.work_plan)
|
core.remove_work_plan(tool.Ifc, tool.Sequence, work_plan=tool.Ifc.get().by_id(self.work_plan))
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingWorkPlan(bpy.types.Operator):
|
class EnableEditingWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.enable_editing_work_plan"
|
bl_idname = "bim.enable_editing_work_plan"
|
||||||
bl_label = "Enable Editing Work Plan"
|
bl_label = "Enable Editing Work Plan"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
work_plan: bpy.props.IntProperty()
|
work_plan: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
core.enable_editing_work_plan(tool.Sequence, work_plan=self.work_plan)
|
core.enable_editing_work_plan(tool.Sequence, work_plan=tool.Ifc.get().by_id(self.work_plan))
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class DisableEditingWorkPlan(bpy.types.Operator):
|
class DisableEditingWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
bl_idname = "bim.disable_editing_work_plan"
|
bl_idname = "bim.disable_editing_work_plan"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
bl_label = "Disable Editing Work Plan"
|
bl_label = "Disable Editing Work Plan"
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
core.disable_editing_work_plan(tool.Sequence)
|
core.disable_editing_work_plan(tool.Sequence)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingWorkPlanSchedules(bpy.types.Operator):
|
class EnableEditingWorkPlanSchedules(bpy.types.Operator):
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class BIM_PT_work_plans(Panel):
|
|||||||
text="{} Work Plans Found".format(SequenceData.number_of_work_plans_loaded),
|
text="{} Work Plans Found".format(SequenceData.number_of_work_plans_loaded),
|
||||||
icon="TEXT",
|
icon="TEXT",
|
||||||
)
|
)
|
||||||
row.operator("bim.add_work_plan", icon="ADD")
|
row.operator("bim.add_work_plan", icon="ADD", text="")
|
||||||
|
|
||||||
for work_plan_id, work_plan in SequenceData.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)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>, 2022 Yassine Oualid <yassine@sigmadimensions.com>
|
# Copyright (C) 2021, 2022 Dion Moult <dion@thinkmoult.com>, Yassine Oualid <yassine@sigmadimensions.com>
|
||||||
#
|
#
|
||||||
# This file is part of BlenderBIM Add-on.
|
# This file is part of BlenderBIM Add-on.
|
||||||
#
|
#
|
||||||
@@ -23,17 +23,12 @@ def add_work_plan(ifc, sequence):
|
|||||||
|
|
||||||
|
|
||||||
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=work_plan)
|
||||||
sequence.load_work_plans()
|
sequence.load_work_plans()
|
||||||
|
|
||||||
|
|
||||||
def load_work_plan_attributes(sequence, work_plan=None):
|
|
||||||
data = sequence.get_ifc_work_plan_attributes(work_plan)
|
|
||||||
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)
|
sequence.load_work_plan_attributes(work_plan)
|
||||||
sequence.enable_editing_work_plan(work_plan)
|
sequence.enable_editing_work_plan(work_plan)
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +39,6 @@ def disable_editing_work_plan(sequence):
|
|||||||
def edit_work_plan(ifc, sequence):
|
def edit_work_plan(ifc, sequence):
|
||||||
work_plan = sequence.get_current_ifc_work_plan()
|
work_plan = sequence.get_current_ifc_work_plan()
|
||||||
attributes = sequence.get_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)
|
||||||
sequence.disable_editing_work_plan()
|
sequence.disable_editing_work_plan()
|
||||||
sequence.load_work_plans()
|
sequence.load_work_plans()
|
||||||
|
|||||||
@@ -423,15 +423,13 @@ class Selector:
|
|||||||
|
|
||||||
@interface
|
@interface
|
||||||
class Sequence:
|
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 disable_editing_work_plan(cls): pass
|
||||||
|
def enable_editing_work_plan(cls, work_plan): pass
|
||||||
|
def export_attributes(cls): pass
|
||||||
def get_current_ifc_work_plan(cls): pass
|
def get_current_ifc_work_plan(cls): pass
|
||||||
def get_ifc_work_plan_attributes(cls): pass
|
def get_ifc_work_plan_attributes(cls): pass
|
||||||
def load_work_plan_attributes(cls): pass
|
def load_work_plan_attributes(cls): pass
|
||||||
def import_attributes(cls): pass
|
def load_work_plans(cls): pass
|
||||||
def export_attributes(cls): pass
|
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
|
|||||||
@@ -26,27 +26,19 @@ import blenderbim.bim.module.sequence.helper as helper
|
|||||||
|
|
||||||
|
|
||||||
class Sequence(blenderbim.core.tool.Sequence):
|
class Sequence(blenderbim.core.tool.Sequence):
|
||||||
@classmethod
|
|
||||||
def get_work_plans(cls):
|
|
||||||
work_plans = {}
|
|
||||||
for work_plan in tool.Ifc.get().by_type("IfcWorkPlan"):
|
|
||||||
work_plans[work_plan.id()] = {"Name": work_plan.Name}
|
|
||||||
return work_plans
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_work_plans(cls):
|
def load_work_plans(cls):
|
||||||
work_plans = tool.Sequence.get_work_plans()
|
|
||||||
props = bpy.context.scene.BIMWorkPlanProperties
|
props = bpy.context.scene.BIMWorkPlanProperties
|
||||||
props.work_plans.clear()
|
props.work_plans.clear()
|
||||||
for ifc_definition_id, work_plan in work_plans.items():
|
for work_plan in tool.Ifc.get().by_type("IfcWorkPlan"):
|
||||||
new = props.work_plans.add()
|
new = props.work_plans.add()
|
||||||
new.ifc_definition_id = ifc_definition_id
|
new.ifc_definition_id = work_plan.id()
|
||||||
new.name = work_plan["Name"] or "Unnamed"
|
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):
|
||||||
if work_plan:
|
if work_plan:
|
||||||
bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = work_plan
|
bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id = work_plan.id()
|
||||||
bpy.context.scene.BIMWorkPlanProperties.editing_type = "ATTRIBUTES"
|
bpy.context.scene.BIMWorkPlanProperties.editing_type = "ATTRIBUTES"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -55,60 +47,34 @@ class Sequence(blenderbim.core.tool.Sequence):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_current_ifc_work_plan(cls):
|
def get_current_ifc_work_plan(cls):
|
||||||
active_work_plan = bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id
|
return tool.Ifc.get().by_id(bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id)
|
||||||
ifc_work_plan = tool.Ifc.get().by_id(active_work_plan)
|
|
||||||
return ifc_work_plan
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_ifc_work_plan_attributes(cls, work_plan):
|
def load_work_plan_attributes(cls, work_plan):
|
||||||
if work_plan:
|
def callback(name, prop, data):
|
||||||
ifc_work_plan = tool.Ifc.get().by_id(work_plan)
|
if name in ["CreationDate", "StartTime", "FinishTime"]:
|
||||||
data = ifc_work_plan.get_info()
|
prop.string_value = "" if prop.is_null else data[name]
|
||||||
del data["OwnerHistory"]
|
return True
|
||||||
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
|
|
||||||
def load_work_plan_attributes(cls, data):
|
|
||||||
props = bpy.context.scene.BIMWorkPlanProperties
|
props = bpy.context.scene.BIMWorkPlanProperties
|
||||||
props.work_plan_attributes.clear()
|
props.work_plan_attributes.clear()
|
||||||
blenderbim.bim.helper.import_attributes(
|
blenderbim.bim.helper.import_attributes2(work_plan, props.work_plan_attributes, callback)
|
||||||
"IfcWorkPlan", props.work_plan_attributes, data, tool.Sequence.import_attributes
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def import_attributes(name, prop, data):
|
|
||||||
if name in ["CreationDate", "StartTime", "FinishTime"]:
|
|
||||||
prop.string_value = "" if prop.is_null else data[name].isoformat()
|
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_work_plan_attributes(cls):
|
def get_work_plan_attributes(cls):
|
||||||
props = bpy.context.scene.BIMWorkPlanProperties
|
def callback(attributes, prop):
|
||||||
attributes = blenderbim.bim.helper.export_attributes(
|
if "Date" in prop.name or "Time" in prop.name:
|
||||||
props.work_plan_attributes, tool.Sequence.export_attributes
|
if prop.is_null:
|
||||||
)
|
attributes[prop.name] = None
|
||||||
return attributes
|
return True
|
||||||
|
attributes[prop.name] = helper.parse_datetime(prop.string_value)
|
||||||
|
return True
|
||||||
|
elif prop.name == "Duration" or prop.name == "TotalFloat":
|
||||||
|
if prop.is_null:
|
||||||
|
attributes[prop.name] = None
|
||||||
|
return True
|
||||||
|
attributes[prop.name] = helper.parse_duration(prop.string_value)
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
props = bpy.context.scene.BIMWorkPlanProperties
|
||||||
def export_attributes(attributes, prop):
|
return blenderbim.bim.helper.export_attributes(props.work_plan_attributes, callback)
|
||||||
if "Date" in prop.name or "Time" in prop.name:
|
|
||||||
if prop.is_null:
|
|
||||||
attributes[prop.name] = None
|
|
||||||
return True
|
|
||||||
attributes[prop.name] = helper.parse_datetime(prop.string_value)
|
|
||||||
return True
|
|
||||||
elif prop.name == "Duration" or prop.name == "TotalFloat":
|
|
||||||
if prop.is_null:
|
|
||||||
attributes[prop.name] = None
|
|
||||||
return True
|
|
||||||
attributes[prop.name] = helper.parse_duration(prop.string_value)
|
|
||||||
return True
|
|
||||||
|
|||||||
Reference in New Issue
Block a user