From a8f0a4807c164827f1afc450329ba84243b229c7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 3 Jul 2021 10:03:22 +1000 Subject: [PATCH] Add undo support for group module operators --- .../bim/module/geometry/operator.py | 5 ++++ .../blenderbim/bim/module/group/operator.py | 25 +++++++++++++++++++ .../blenderbim/bim/module/spatial/operator.py | 5 ++++ .../blenderbim/bim/module/style/operator.py | 4 +++ .../blenderbim/bim/module/type/operator.py | 5 ++++ .../blenderbim/bim/module/void/operator.py | 4 +++ 6 files changed, 48 insertions(+) diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 0b5cd5f698..3b24fdd890 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -59,12 +59,16 @@ class EditObjectPlacement(bpy.types.Operator): class AddRepresentation(bpy.types.Operator): bl_idname = "bim.add_representation" bl_label = "Add Representation" + bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() context_id: bpy.props.IntProperty() ifc_representation_class: bpy.props.StringProperty() profile_set_usage: bpy.props.IntProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object self.file = IfcStore.get_file() @@ -151,6 +155,7 @@ class AddRepresentation(bpy.types.Operator): class SwitchRepresentation(bpy.types.Operator): bl_idname = "bim.switch_representation" bl_label = "Switch Representation" + bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() ifc_definition_id: bpy.props.IntProperty() should_reload: bpy.props.BoolProperty() diff --git a/src/blenderbim/blenderbim/bim/module/group/operator.py b/src/blenderbim/blenderbim/bim/module/group/operator.py index bb75e5eb3d..3b7ed59b70 100644 --- a/src/blenderbim/blenderbim/bim/module/group/operator.py +++ b/src/blenderbim/blenderbim/bim/module/group/operator.py @@ -8,6 +8,7 @@ from ifcopenshell.api.group.data import Data class LoadGroups(bpy.types.Operator): bl_idname = "bim.load_groups" bl_label = "Load Groups" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): props = context.scene.BIMGroupProperties @@ -25,6 +26,7 @@ class LoadGroups(bpy.types.Operator): class DisableGroupEditingUI(bpy.types.Operator): bl_idname = "bim.disable_group_editing_ui" bl_label = "Disable Group Editing UI" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): context.scene.BIMGroupProperties.is_editing = False @@ -34,8 +36,12 @@ class DisableGroupEditingUI(bpy.types.Operator): class AddGroup(bpy.types.Operator): bl_idname = "bim.add_group" bl_label = "Add Group" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): result = ifcopenshell.api.run("group.add_group", IfcStore.get_file()) Data.load(IfcStore.get_file()) bpy.ops.bim.load_groups() @@ -46,8 +52,12 @@ class AddGroup(bpy.types.Operator): class EditGroup(bpy.types.Operator): bl_idname = "bim.edit_group" bl_label = "Edit Group" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): props = context.scene.BIMGroupProperties attributes = {} for attribute in props.group_attributes: @@ -67,9 +77,13 @@ class EditGroup(bpy.types.Operator): class RemoveGroup(bpy.types.Operator): bl_idname = "bim.remove_group" bl_label = "Remove Group" + bl_options = {"REGISTER", "UNDO"} group: bpy.props.IntProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): props = context.scene.BIMGroupProperties self.file = IfcStore.get_file() ifcopenshell.api.run("group.remove_group", self.file, **{"group": self.file.by_id(self.group)}) @@ -81,6 +95,7 @@ class RemoveGroup(bpy.types.Operator): class EnableEditingGroup(bpy.types.Operator): bl_idname = "bim.enable_editing_group" bl_label = "Enable Editing Group" + bl_options = {"REGISTER", "UNDO"} group: bpy.props.IntProperty() def execute(self, context): @@ -106,6 +121,7 @@ class EnableEditingGroup(bpy.types.Operator): class DisableEditingGroup(bpy.types.Operator): bl_idname = "bim.disable_editing_group" bl_label = "Disable Editing Group" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): context.scene.BIMGroupProperties.active_group_id = 0 @@ -115,10 +131,14 @@ class DisableEditingGroup(bpy.types.Operator): class AssignGroup(bpy.types.Operator): bl_idname = "bim.assign_group" bl_label = "Assign Group" + bl_options = {"REGISTER", "UNDO"} product: bpy.props.StringProperty() group: bpy.props.IntProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): product = bpy.data.objects.get(self.product) if self.product else context.active_object self.file = IfcStore.get_file() ifcopenshell.api.run( @@ -136,10 +156,14 @@ class AssignGroup(bpy.types.Operator): class UnassignGroup(bpy.types.Operator): bl_idname = "bim.unassign_group" bl_label = "Unassign Group" + bl_options = {"REGISTER", "UNDO"} product: bpy.props.StringProperty() group: bpy.props.IntProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): product = bpy.data.objects.get(self.product) if self.product else context.active_object self.file = IfcStore.get_file() ifcopenshell.api.run( @@ -157,6 +181,7 @@ class UnassignGroup(bpy.types.Operator): class SelectGroupProducts(bpy.types.Operator): bl_idname = "bim.select_group_products" bl_label = "Select Group Products" + bl_options = {"REGISTER", "UNDO"} group: bpy.props.IntProperty() def execute(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/spatial/operator.py b/src/blenderbim/blenderbim/bim/module/spatial/operator.py index 3ce1dda70f..053a4f9421 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/operator.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/operator.py @@ -9,10 +9,14 @@ from blenderbim.bim.module.spatial.prop import getSpatialContainers class AssignContainer(bpy.types.Operator): bl_idname = "bim.assign_container" bl_label = "Assign Container" + bl_options = {"REGISTER", "UNDO"} relating_structure: bpy.props.IntProperty() related_element: bpy.props.StringProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): self.file = IfcStore.get_file() related_elements = ( [bpy.data.objects.get(self.related_element)] if self.related_element else bpy.context.selected_objects @@ -85,6 +89,7 @@ class ChangeSpatialLevel(bpy.types.Operator): class DisableEditingContainer(bpy.types.Operator): bl_idname = "bim.disable_editing_container" bl_label = "Disable Editing Container" + bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() def execute(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index 0ca1c8af3a..c4aba87149 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -35,9 +35,13 @@ class EditStyle(bpy.types.Operator): class AddStyle(bpy.types.Operator): bl_idname = "bim.add_style" bl_label = "Add Style" + bl_options = {"REGISTER", "UNDO"} material: bpy.props.StringProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): self.file = IfcStore.get_file() material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material settings = get_colour_settings(material) diff --git a/src/blenderbim/blenderbim/bim/module/type/operator.py b/src/blenderbim/blenderbim/bim/module/type/operator.py index 08ed63d9b7..dfb1cce965 100644 --- a/src/blenderbim/blenderbim/bim/module/type/operator.py +++ b/src/blenderbim/blenderbim/bim/module/type/operator.py @@ -11,10 +11,14 @@ from ifcopenshell.api.material.data import Data as MaterialData class AssignType(bpy.types.Operator): bl_idname = "bim.assign_type" bl_label = "Assign Type" + bl_options = {"REGISTER", "UNDO"} relating_type: bpy.props.IntProperty() related_object: bpy.props.StringProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): self.file = IfcStore.get_file() relating_type = self.relating_type or int(context.active_object.BIMTypeProperties.relating_type) related_objects = ( @@ -85,6 +89,7 @@ class EnableEditingType(bpy.types.Operator): class DisableEditingType(bpy.types.Operator): bl_idname = "bim.disable_editing_type" bl_label = "Disable Editing Type" + bl_options = {"REGISTER", "UNDO"} obj: bpy.props.StringProperty() def execute(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/void/operator.py b/src/blenderbim/blenderbim/bim/module/void/operator.py index 27a30eeae5..a25678120b 100644 --- a/src/blenderbim/blenderbim/bim/module/void/operator.py +++ b/src/blenderbim/blenderbim/bim/module/void/operator.py @@ -57,10 +57,14 @@ class AddOpening(bpy.types.Operator): class RemoveOpening(bpy.types.Operator): bl_idname = "bim.remove_opening" bl_label = "Remove Opening" + bl_options = {"REGISTER", "UNDO"} opening_id: bpy.props.IntProperty() obj: bpy.props.StringProperty() def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): obj = bpy.data.objects.get(self.obj) if self.obj else bpy.context.active_object self.file = IfcStore.get_file() for modifier in obj.modifiers: