mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +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_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
core.add_work_plan(tool.Ifc, tool.Sequence)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
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_label = "Edit Work Plan"
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
core.edit_work_plan(tool.Ifc, tool.Sequence)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||
@@ -86,33 +78,27 @@ class RemoveWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
work_plan: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
core.remove_work_plan(tool.Ifc, tool.Sequence, work_plan=self.work_plan)
|
||||
return {"FINISHED"}
|
||||
core.remove_work_plan(tool.Ifc, tool.Sequence, work_plan=tool.Ifc.get().by_id(self.work_plan))
|
||||
|
||||
|
||||
class EnableEditingWorkPlan(bpy.types.Operator):
|
||||
class EnableEditingWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.enable_editing_work_plan"
|
||||
bl_label = "Enable Editing Work Plan"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
work_plan: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
core.enable_editing_work_plan(tool.Sequence, work_plan=self.work_plan)
|
||||
return {"FINISHED"}
|
||||
def _execute(self, context):
|
||||
core.enable_editing_work_plan(tool.Sequence, work_plan=tool.Ifc.get().by_id(self.work_plan))
|
||||
|
||||
|
||||
class DisableEditingWorkPlan(bpy.types.Operator):
|
||||
class DisableEditingWorkPlan(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.disable_editing_work_plan"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_label = "Disable Editing Work Plan"
|
||||
|
||||
def execute(self, context):
|
||||
def _execute(self, context):
|
||||
core.disable_editing_work_plan(tool.Sequence)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
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),
|
||||
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():
|
||||
self.draw_work_plan_ui(work_plan_id, work_plan)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# 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.
|
||||
#
|
||||
@@ -23,17 +23,12 @@ def add_work_plan(ifc, sequence):
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
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):
|
||||
load_work_plan_attributes(sequence, work_plan)
|
||||
sequence.load_work_plan_attributes(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):
|
||||
work_plan = sequence.get_current_ifc_work_plan()
|
||||
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.load_work_plans()
|
||||
|
||||
@@ -423,15 +423,13 @@ class Selector:
|
||||
|
||||
@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 enable_editing_work_plan(cls, work_plan): pass
|
||||
def export_attributes(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
|
||||
def load_work_plans(cls): pass
|
||||
|
||||
|
||||
@interface
|
||||
|
||||
@@ -26,27 +26,19 @@ import blenderbim.bim.module.sequence.helper as helper
|
||||
|
||||
|
||||
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
|
||||
def load_work_plans(cls):
|
||||
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():
|
||||
for work_plan in tool.Ifc.get().by_type("IfcWorkPlan"):
|
||||
new = props.work_plans.add()
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
new.name = work_plan["Name"] or "Unnamed"
|
||||
new.ifc_definition_id = work_plan.id()
|
||||
new.name = work_plan.Name or "Unnamed"
|
||||
|
||||
@classmethod
|
||||
def enable_editing_work_plan(cls, 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"
|
||||
|
||||
@classmethod
|
||||
@@ -55,60 +47,34 @@ class Sequence(blenderbim.core.tool.Sequence):
|
||||
|
||||
@classmethod
|
||||
def get_current_ifc_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
|
||||
return tool.Ifc.get().by_id(bpy.context.scene.BIMWorkPlanProperties.active_work_plan_id)
|
||||
|
||||
@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
|
||||
def load_work_plan_attributes(cls, work_plan):
|
||||
def callback(name, prop, data):
|
||||
if name in ["CreationDate", "StartTime", "FinishTime"]:
|
||||
prop.string_value = "" if prop.is_null else data[name]
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def load_work_plan_attributes(cls, data):
|
||||
props = bpy.context.scene.BIMWorkPlanProperties
|
||||
props.work_plan_attributes.clear()
|
||||
blenderbim.bim.helper.import_attributes(
|
||||
"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
|
||||
blenderbim.bim.helper.import_attributes2(work_plan, props.work_plan_attributes, callback)
|
||||
|
||||
@classmethod
|
||||
def get_work_plan_attributes(cls):
|
||||
props = bpy.context.scene.BIMWorkPlanProperties
|
||||
attributes = blenderbim.bim.helper.export_attributes(
|
||||
props.work_plan_attributes, tool.Sequence.export_attributes
|
||||
)
|
||||
return attributes
|
||||
def callback(attributes, prop):
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def export_attributes(attributes, prop):
|
||||
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
|
||||
props = bpy.context.scene.BIMWorkPlanProperties
|
||||
return blenderbim.bim.helper.export_attributes(props.work_plan_attributes, callback)
|
||||
|
||||
Reference in New Issue
Block a user