From e74eb0cc536108e9925e6d30b82890ed66f06249 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 4 Oct 2022 13:41:27 +1100 Subject: [PATCH] Fix bug where unlinking operations were not stored in the undo stack --- src/blenderbim/blenderbim/bim/ifc.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index dd6e05d5d8..bad89dea4c 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -323,6 +323,21 @@ class IfcStore: # TODO Listeners are not re-registered. Does this cause nasty problems to debug later on? # TODO We're handling id_map and guid_map, but what about edited_objs? This might cause big problems. + @staticmethod + def rollback_unlink_element(data): + if "id" not in data or "obj" not in data: + return + obj = bpy.data.objects.get(data["obj"]) + IfcStore.id_map[data["id"]] = obj + if data["guid"]: + IfcStore.guid_map[data["guid"]] = obj + + @staticmethod + def commit_unlink_element(data): + del IfcStore.id_map[data["id"]] + if data["guid"]: + del IfcStore.guid_map[data["guid"]] + @staticmethod def unlink_element(element=None, obj=None): if element is None: @@ -358,6 +373,17 @@ class IfcStore: elif obj: obj.BIMObjectProperties.ifc_definition_id = 0 + if IfcStore.history: + data = {} + if element: + data["id"] = element.id() + data["guid"] = getattr(element, "GlobalId", None) + if obj: + data["obj"] = obj.name + IfcStore.history[-1]["operations"].append( + {"rollback": IfcStore.rollback_unlink_element, "commit": IfcStore.commit_unlink_element, "data": data} + ) + @staticmethod def execute_ifc_operator(operator, context): is_top_level_operator = not bool(IfcStore.current_transaction)