Fix #2767. Removing representations now cleans up after orphaned Blender mesh data.

This commit is contained in:
Dion Moult
2023-02-22 16:24:09 +11:00
parent 255c2efe98
commit 855751f026
2 changed files with 7 additions and 3 deletions
+4 -3
View File
@@ -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): def remove_representation(ifc, geometry, obj=None, representation=None):
"""Function will produce orphan mesh data, see #2767. """Consider changing obj representation before using the function,
Also should consider changing obj representation before using the function,
otherwise it will replace object with empty.""" otherwise it will replace object with empty."""
element = ifc.get_entity(obj) element = ifc.get_entity(obj)
type = geometry.get_element_type(element) type = geometry.get_element_type(element)
data = None
if type and (geometry.is_mapped_representation(representation) or geometry.is_type_product(element)): if type and (geometry.is_mapped_representation(representation) or geometry.is_type_product(element)):
representation = geometry.resolve_mapped_representation(representation) representation = geometry.resolve_mapped_representation(representation)
data = geometry.get_representation_data(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) geometry.replace_object_with_empty(obj)
ifc.run("geometry.unassign_representation", product=element, representation=representation) ifc.run("geometry.unassign_representation", product=element, representation=representation)
ifc.run("geometry.remove_representation", representation=representation) ifc.run("geometry.remove_representation", representation=representation)
if data:
geometry.delete_data(data)
def select_connection(geometry, connection=None): def select_connection(geometry, connection=None):
@@ -315,6 +315,7 @@ class TestRemoveRepresentation:
geometry.replace_object_with_empty("type_obj").should_be_called() 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.unassign_representation", product="type", representation="representation").should_be_called()
ifc.run("geometry.remove_representation", 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") subject.remove_representation(ifc, geometry, obj="obj", representation="mapped_rep")
def test_removing_an_unused_mapped_representation(self, ifc, geometry): def test_removing_an_unused_mapped_representation(self, ifc, geometry):
@@ -337,6 +338,7 @@ class TestRemoveRepresentation:
"geometry.unassign_representation", product="element", representation="representation" "geometry.unassign_representation", product="element", representation="representation"
).should_be_called() ).should_be_called()
ifc.run("geometry.remove_representation", 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") subject.remove_representation(ifc, geometry, obj="obj", representation="representation")
def test_removing_an_actively_used_representation(self, ifc, geometry): def test_removing_an_actively_used_representation(self, ifc, geometry):
@@ -351,6 +353,7 @@ class TestRemoveRepresentation:
"geometry.unassign_representation", product="element", representation="representation" "geometry.unassign_representation", product="element", representation="representation"
).should_be_called() ).should_be_called()
ifc.run("geometry.remove_representation", 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") subject.remove_representation(ifc, geometry, obj="obj", representation="representation")
def test_removing_an_unused_representation(self, ifc, geometry): def test_removing_an_unused_representation(self, ifc, geometry):