From a031bffe6c189f746e8ede498e44a0eb1c2ef186 Mon Sep 17 00:00:00 2001 From: Jesusbill Date: Wed, 5 May 2021 14:22:18 +0200 Subject: [PATCH] you can now add, edit and remove structural load cases --- .../bim/module/structural/__init__.py | 6 + .../bim/module/structural/operator.py | 136 ++++++++++++++++++ .../blenderbim/bim/module/structural/prop.py | 8 ++ .../blenderbim/bim/module/structural/ui.py | 53 +++++++ .../structural/add_structural_load_case.py | 25 ++++ .../ifcopenshell/api/structural/data.py | 29 ++++ .../structural/edit_structural_load_case.py | 10 ++ .../structural/remove_structural_load_case.py | 15 ++ 8 files changed, 282 insertions(+) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_load_case.py create mode 100644 src/ifcopenshell-python/ifcopenshell/api/structural/remove_structural_load_case.py diff --git a/src/blenderbim/blenderbim/bim/module/structural/__init__.py b/src/blenderbim/blenderbim/bim/module/structural/__init__.py index a361a238ad..23c81445d0 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/structural/__init__.py @@ -23,6 +23,11 @@ classes = ( operator.EnableEditingStructuralMemberAxis, operator.DisableEditingStructuralMemberAxis, operator.EditStructuralMemberAxis, + operator.AddStructuralLoadCase, + operator.EditStructuralLoadCase, + operator.RemoveStructuralLoadCase, + operator.EnableEditingStructuralLoadCase, + operator.DisableEditingStructuralLoadCase, prop.StructuralAnalysisModel, prop.BIMStructuralProperties, prop.BIMObjectStructuralProperties, @@ -31,6 +36,7 @@ classes = ( ui.BIM_PT_connected_structural_members, ui.BIM_PT_structural_member, ui.BIM_UL_structural_analysis_models, + ui.BIM_PT_structural_load_cases, ) diff --git a/src/blenderbim/blenderbim/bim/module/structural/operator.py b/src/blenderbim/blenderbim/bim/module/structural/operator.py index 5d735ef84c..4fdb84203b 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/operator.py +++ b/src/blenderbim/blenderbim/bim/module/structural/operator.py @@ -436,3 +436,139 @@ class EditStructuralMemberAxis(bpy.types.Operator): ) bpy.ops.bim.disable_editing_structural_member_axis() return {"FINISHED"} + + +class AssignStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.assign_structural_load_case" + bl_label = "Assign Structural Load Case" + work_plan: bpy.props.IntProperty() + load_case: bpy.props.IntProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "aggregate.assign_object", + self.file, + **{ + "relating_object": self.file.by_id(self.work_plan), + "product": self.file.by_id(self.load_case), + }, + ) + Data.load(IfcStore.get_file()) + return {"FINISHED"} + + +class UnassignStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.unassign_structural_load_case" + bl_label = "Unassign Structural Load Case" + work_plan: bpy.props.IntProperty() + load_case: bpy.props.IntProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "aggregate.unassign_object", + self.file, + **{ + "relating_object": self.file.by_id(self.work_plan), + "product": self.file.by_id(self.load_case), + }, + ) + Data.load(IfcStore.get_file()) + return {"FINISHED"} + + +class AddStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.add_structural_load_case" + bl_label = "Add Structural Load Case" + + def execute(self, context): + ifcopenshell.api.run("structural.add_structural_load_case", IfcStore.get_file()) + Data.load(IfcStore.get_file()) + return {"FINISHED"} + + +class EditStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.edit_structural_load_case" + bl_label = "Edit Structural Load Case" + + def execute(self, context): + props = context.scene.BIMStructuralProperties + attributes = {} + for attribute in props.load_case_attributes: + if attribute.is_null: + attributes[attribute.name] = None + else: + if attribute.data_type == "string": + attributes[attribute.name] = attribute.string_value + elif attribute.data_type == "enum": + attributes[attribute.name] = attribute.enum_value + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "structural.edit_structural_load_case", + self.file, + **{"load_case": self.file.by_id(props.active_load_case_id), "attributes": attributes}, + ) + Data.load(IfcStore.get_file()) + bpy.ops.bim.disable_editing_structural_load_case() + return {"FINISHED"} + + +class RemoveStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.remove_structural_load_case" + bl_label = "Remove Structural Load Case" + load_case: bpy.props.IntProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + ifcopenshell.api.run( + "structural.remove_structural_load_case", self.file, load_case=self.file.by_id(self.load_case) + ) + Data.load(self.file) + return {"FINISHED"} + + +class EnableEditingStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.enable_editing_structural_load_case" + bl_label = "Enable Editing Structural Load Case" + load_case: bpy.props.IntProperty() + + def execute(self, context): + self.props = context.scene.BIMStructuralProperties + self.props.active_load_case_id = self.load_case + while len(self.props.load_case_attributes) > 0: + self.props.load_case_attributes.remove(0) + self.enable_editing_structural_load_case() + return {"FINISHED"} + + def enable_editing_structural_load_case(self): + data = Data.load_cases[self.load_case] + print(data) + + for attribute in IfcStore.get_schema().declaration_by_name("IfcStructuralLoadCase").all_attributes(): + if attribute.name() in ["SelfWeightCoefficients", "Coefficient"]: + continue + data_type = ifcopenshell.util.attribute.get_primitive_type(attribute) + if data_type == "entity": + continue + new = self.props.load_case_attributes.add() + new.name = attribute.name() + new.is_null = data[attribute.name()] is None + new.is_optional = attribute.optional() + print(data_type) + new.data_type = data_type + if data_type == "string": + new.string_value = "" if new.is_null else data[attribute.name()] + elif data_type == "enum": + new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute)) + if data[attribute.name()]: + new.enum_value = data[attribute.name()] + + +class DisableEditingStructuralLoadCase(bpy.types.Operator): + bl_idname = "bim.disable_editing_structural_load_case" + bl_label = "Disable Editing Structural Load Case" + + def execute(self, context): + context.scene.BIMStructuralProperties.active_load_case_id = 0 + return {"FINISHED"} \ No newline at end of file diff --git a/src/blenderbim/blenderbim/bim/module/structural/prop.py b/src/blenderbim/blenderbim/bim/module/structural/prop.py index 71709c470d..c05101ea84 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/prop.py +++ b/src/blenderbim/blenderbim/bim/module/structural/prop.py @@ -41,6 +41,12 @@ class BIMStructuralProperties(PropertyGroup): active_structural_analysis_model_index: IntProperty(name="Active Structural Analysis Model Index") active_structural_analysis_model_id: IntProperty(name="Active Structural Analysis Model Id") + # editing_type: StringProperty(name="Editing Type") + # active_load_case_index: IntProperty(name="Active Work Schedules Index") + + load_case_attributes: CollectionProperty(name="Load Case Attributes", type=Attribute) + active_load_case_id: IntProperty(name="Active Load Case Id") + class BIMObjectStructuralProperties(PropertyGroup): boundary_condition_attributes: CollectionProperty(name="Boundary Condition Attributes", type=Attribute) @@ -50,3 +56,5 @@ class BIMObjectStructuralProperties(PropertyGroup): is_editing_axis: BoolProperty(name="Is Editing Axis", default=False) axis_angle: FloatProperty(name="Axis Angle", update=updateAxisAngle) axis_empty: PointerProperty(name="Axis Empty", type=bpy.types.Object) + + # relating_structural_activity: PointerProperty(name="Relating Structural Activity", type=bpy.types.Object) diff --git a/src/blenderbim/blenderbim/bim/module/structural/ui.py b/src/blenderbim/blenderbim/bim/module/structural/ui.py index b1b51edd4d..4f33f899d1 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/ui.py +++ b/src/blenderbim/blenderbim/bim/module/structural/ui.py @@ -261,3 +261,56 @@ class BIM_UL_structural_analysis_models(UIList): op.structural_analysis_model = item.ifc_definition_id op = row.operator("bim.remove_structural_analysis_model", text="", icon="X") op.structural_analysis_model = item.ifc_definition_id + + +class BIM_PT_structural_load_cases(Panel): + bl_label = "IFC Structural Load Cases" + bl_idname = "BIM_PT_structural_load_cases" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + + @classmethod + def poll(cls, context): + return IfcStore.get_file() + + def draw(self, context): + self.props = context.scene.BIMStructuralProperties + + if not Data.is_loaded: + Data.load(IfcStore.get_file()) + + row = self.layout.row() + row.operator("bim.add_structural_load_case", icon="ADD") + + for load_case_id, load_case in Data.load_cases.items(): + self.draw_load_case_ui(load_case_id, load_case) + + def draw_load_case_ui(self, load_case_id, load_case): + row = self.layout.row(align=True) + row.label(text=load_case["Name"] or "Unnamed", icon="CON_CLAMPTO") + + if self.props.active_load_case_id and self.props.active_load_case_id == load_case_id: + row.operator("bim.edit_structural_load_case", text="", icon="CHECKMARK") + row.operator("bim.disable_editing_structural_load_case", text="", icon="CANCEL") + elif self.props.active_load_case_id: + row.operator("bim.remove_structural_load_case", text="", icon="X").load_case = load_case_id + else: + row.operator( + "bim.enable_editing_structural_load_case", text="", icon="GREASEPENCIL" + ).load_case = load_case_id + row.operator("bim.remove_structural_load_case", text="", icon="X").load_case = load_case_id + + if self.props.active_load_case_id == load_case_id: + self.draw_editable_load_case_ui() + + def draw_editable_load_case_ui(self): + for attribute in self.props.load_case_attributes: + row = self.layout.row(align=True) + if attribute.data_type == "string": + row.prop(attribute, "string_value", text=attribute.name) + elif attribute.data_type == "enum": + row.prop(attribute, "enum_value", text=attribute.name) + if attribute.is_optional: + row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="") diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py b/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py new file mode 100644 index 0000000000..e471c75e68 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/add_structural_load_case.py @@ -0,0 +1,25 @@ +import ifcopenshell.api + +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = { + "name": "Unnamed", + "predefined_type": "LOAD_CASE", + "action_type": "NOTDEFINED", + "action_source": "NOTDEFINED", + } + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + load_case = ifcopenshell.api.run( + "root.create_entity", + self.file, + ifc_class="IfcStructuralLoadCase", + predefined_type=self.settings["predefined_type"], + action_type=self.settings["action_type"], + action_source=self.settings["action_source"], + name=self.settings["name"], + ) + return load_case diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/data.py b/src/ifcopenshell-python/ifcopenshell/api/structural/data.py index 0165ab64f9..8b5a567e1c 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/data.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/data.py @@ -6,6 +6,12 @@ class Data: boundary_conditions = {} connects_structural_members = {} + load_cases = {} + # load_case_combinations = {} + # load_groups = {} + # structural_activities = {} + # connects_structural_activities = {} + @classmethod def purge(cls): cls.is_loaded = False @@ -14,6 +20,7 @@ class Data: cls.connections = {} cls.boundary_conditions = {} cls.connects_structural_members = {} + cls.load_cases = {} @classmethod def load(cls, file, product_id=None): @@ -23,6 +30,7 @@ class Data: if product_id: return cls.load_structural_connection(product_id) cls.load_structural_analysis_models() + cls.load_structural_load_cases() cls.is_loaded = True @classmethod @@ -53,6 +61,27 @@ class Data: cls.structural_analysis_models[model.id()] = data + @classmethod + def load_structural_load_cases(cls): + cls.load_cases = {} + + for case in cls._file.by_type("IfcStructuralLoadCase"): + # if case.IsGroupedBy: + # for rel in case.IsGroupedBy: + # for product in rel.RelatedObjects: + # cls.products.setdefault(product.id(), []).append(case.id()) + data = case.get_info() + del data["OwnerHistory"] + + is_grouped_by = [] + for load_group in case.IsGroupedBy or []: + is_grouped_by.append(load_group.id()) + data["IsGroupedBy"] = is_grouped_by + + cls.load_cases[case.id()] = data + + print(data) + @classmethod def load_structural_connection(cls, product_id): cls.connections = {} diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_load_case.py b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_load_case.py new file mode 100644 index 0000000000..85bbd5c934 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_load_case.py @@ -0,0 +1,10 @@ +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"load_case": None, "attributes": {}} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + for name, value in self.settings["attributes"].items(): + setattr(self.settings["load_case"], name, value) diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/remove_structural_load_case.py b/src/ifcopenshell-python/ifcopenshell/api/structural/remove_structural_load_case.py new file mode 100644 index 0000000000..aaae5460b8 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/remove_structural_load_case.py @@ -0,0 +1,15 @@ +import ifcopenshell.api + + +class Usecase: + def __init__(self, file, **settings): + self.file = file + self.settings = {"load_case": None} + for key, value in settings.items(): + self.settings[key] = value + + def execute(self): + # TODO: do a deep purge + for rel in self.settings["load_case"].IsGroupedBy or []: + self.file.remove(rel) + self.file.remove(self.settings["load_case"])