Add undo support for group module operators

This commit is contained in:
Dion Moult
2021-07-03 10:03:22 +10:00
parent d5539399e8
commit a8f0a4807c
6 changed files with 48 additions and 0 deletions
@@ -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()
@@ -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):
@@ -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):
@@ -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)
@@ -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):
@@ -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: