From 7f3b7f4e21d49bc052129c28223866fe5e61e0b0 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 5 Jul 2021 16:42:29 +1000 Subject: [PATCH] Implement undo for georeference operators. See #1475. --- .../bim/module/georeference/operator.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/georeference/operator.py b/src/blenderbim/blenderbim/bim/module/georeference/operator.py index 4d0979bfd0..645ae7c4f1 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/operator.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/operator.py @@ -12,6 +12,7 @@ from math import radians, degrees, atan, tan, cos, sin class EnableEditingGeoreferencing(bpy.types.Operator): bl_idname = "bim.enable_editing_georeferencing" bl_label = "Enable Editing Georeferencing" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): self.file = IfcStore.get_file() @@ -55,12 +56,11 @@ class EnableEditingGeoreferencing(bpy.types.Operator): data_type = ifcopenshell.util.attribute.get_primitive_type(attribute) if data_type == "entity" or data_type == "select": continue - print(attribute.name(), data_type) new = props.map_conversion.add() new.name = attribute.name() new.is_null = Data.map_conversion[attribute.name()] is None new.is_optional = attribute.optional() - # Enforce a string data type to prevent data loss in singpe-precision Blender props + # Enforce a string data type to prevent data loss in single-precision Blender props new.data_type = "string" new.string_value = "" if new.is_null else str(Data.map_conversion[attribute.name()]) @@ -76,6 +76,7 @@ class EnableEditingGeoreferencing(bpy.types.Operator): class DisableEditingGeoreferencing(bpy.types.Operator): bl_idname = "bim.disable_editing_georeferencing" bl_label = "Disable Editing Georeferencing" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): props = context.scene.BIMGeoreferenceProperties @@ -86,8 +87,12 @@ class DisableEditingGeoreferencing(bpy.types.Operator): class EditGeoreferencing(bpy.types.Operator): bl_idname = "bim.edit_georeferencing" bl_label = "Edit Georeferencing" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): self.file = IfcStore.get_file() props = context.scene.BIMGeoreferenceProperties @@ -149,6 +154,7 @@ class EditGeoreferencing(bpy.types.Operator): class SetBlenderGridNorth(bpy.types.Operator): bl_idname = "bim.set_blender_grid_north" bl_label = "Set Blender Grid North" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): context.scene.sun_pos_properties.north_offset = -radians( @@ -163,6 +169,7 @@ class SetBlenderGridNorth(bpy.types.Operator): class SetIfcGridNorth(bpy.types.Operator): bl_idname = "bim.set_ifc_grid_north" bl_label = "Set IFC Grid North" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): x_angle = -context.scene.sun_pos_properties.north_offset @@ -174,6 +181,7 @@ class SetIfcGridNorth(bpy.types.Operator): class SetBlenderTrueNorth(bpy.types.Operator): bl_idname = "bim.set_blender_true_north" bl_label = "Set Blender True North" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): context.scene.sun_pos_properties.north_offset = -radians( @@ -188,6 +196,7 @@ class SetBlenderTrueNorth(bpy.types.Operator): class SetIfcTrueNorth(bpy.types.Operator): bl_idname = "bim.set_ifc_true_north" bl_label = "Set IFC True North" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): y_angle = -context.scene.sun_pos_properties.north_offset + radians(90) @@ -199,8 +208,12 @@ class SetIfcTrueNorth(bpy.types.Operator): class RemoveGeoreferencing(bpy.types.Operator): bl_idname = "bim.remove_georeferencing" bl_label = "Remove Georeferencing" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): ifcopenshell.api.run("georeference.remove_georeferencing", IfcStore.get_file()) Data.load(IfcStore.get_file()) return {"FINISHED"} @@ -209,8 +222,12 @@ class RemoveGeoreferencing(bpy.types.Operator): class AddGeoreferencing(bpy.types.Operator): bl_idname = "bim.add_georeferencing" bl_label = "Add Georeferencing" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): + return IfcStore.execute_ifc_operator(self, context) + + def _execute(self, context): ifcopenshell.api.run("georeference.add_georeferencing", IfcStore.get_file()) Data.load(IfcStore.get_file()) return {"FINISHED"} @@ -219,6 +236,7 @@ class AddGeoreferencing(bpy.types.Operator): class ConvertLocalToGlobal(bpy.types.Operator): bl_idname = "bim.convert_local_to_global" bl_label = "Convert Local To Global" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): if not Data.is_loaded: @@ -269,6 +287,7 @@ class ConvertLocalToGlobal(bpy.types.Operator): class ConvertGlobalToLocal(bpy.types.Operator): bl_idname = "bim.convert_global_to_local" bl_label = "Convert Global To Local" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): if not Data.is_loaded: @@ -318,6 +337,7 @@ class ConvertGlobalToLocal(bpy.types.Operator): class GetCursorLocation(bpy.types.Operator): bl_idname = "bim.get_cursor_location" bl_label = "Get Cursor Location" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): props = context.scene.BIMGeoreferenceProperties @@ -330,6 +350,7 @@ class GetCursorLocation(bpy.types.Operator): class SetCursorLocation(bpy.types.Operator): bl_idname = "bim.set_cursor_location" bl_label = "Set Cursor Location" + bl_options = {"REGISTER", "UNDO"} def execute(self, context): props = context.scene.BIMGeoreferenceProperties