From 855751f02641d22277287b0473355a9b31e46ad1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 22 Feb 2023 16:24:09 +1100 Subject: [PATCH] Fix #2767. Removing representations now cleans up after orphaned Blender mesh data. --- src/blenderbim/blenderbim/core/geometry.py | 7 ++++--- src/blenderbim/test/core/test_geometry.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/core/geometry.py b/src/blenderbim/blenderbim/core/geometry.py index 8e28ce4601..4a28f11ce3 100644 --- a/src/blenderbim/blenderbim/core/geometry.py +++ b/src/blenderbim/blenderbim/core/geometry.py @@ -118,13 +118,12 @@ def get_representation_ifc_parameters(geometry, obj=None, should_sync_changes_fi def remove_representation(ifc, geometry, obj=None, representation=None): - """Function will produce orphan mesh data, see #2767. - - Also should consider changing obj representation before using the function, + """Consider changing obj representation before using the function, otherwise it will replace object with empty.""" element = ifc.get_entity(obj) type = geometry.get_element_type(element) + data = None if type and (geometry.is_mapped_representation(representation) or geometry.is_type_product(element)): representation = geometry.resolve_mapped_representation(representation) data = geometry.get_representation_data(representation) @@ -144,6 +143,8 @@ def remove_representation(ifc, geometry, obj=None, representation=None): geometry.replace_object_with_empty(obj) ifc.run("geometry.unassign_representation", product=element, representation=representation) ifc.run("geometry.remove_representation", representation=representation) + if data: + geometry.delete_data(data) def select_connection(geometry, connection=None): diff --git a/src/blenderbim/test/core/test_geometry.py b/src/blenderbim/test/core/test_geometry.py index 9d3cc60471..4d28c32f8d 100644 --- a/src/blenderbim/test/core/test_geometry.py +++ b/src/blenderbim/test/core/test_geometry.py @@ -315,6 +315,7 @@ class TestRemoveRepresentation: geometry.replace_object_with_empty("type_obj").should_be_called() ifc.run("geometry.unassign_representation", product="type", representation="representation").should_be_called() ifc.run("geometry.remove_representation", representation="representation").should_be_called() + geometry.delete_data("data").should_be_called() subject.remove_representation(ifc, geometry, obj="obj", representation="mapped_rep") def test_removing_an_unused_mapped_representation(self, ifc, geometry): @@ -337,6 +338,7 @@ class TestRemoveRepresentation: "geometry.unassign_representation", product="element", representation="representation" ).should_be_called() ifc.run("geometry.remove_representation", representation="representation").should_be_called() + geometry.delete_data("data").should_be_called() subject.remove_representation(ifc, geometry, obj="obj", representation="representation") def test_removing_an_actively_used_representation(self, ifc, geometry): @@ -351,6 +353,7 @@ class TestRemoveRepresentation: "geometry.unassign_representation", product="element", representation="representation" ).should_be_called() ifc.run("geometry.remove_representation", representation="representation").should_be_called() + geometry.delete_data("data").should_be_called() subject.remove_representation(ifc, geometry, obj="obj", representation="representation") def test_removing_an_unused_representation(self, ifc, geometry):