From d654110fc1959a3d5862b2a3bca026f7cbb2a3a1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 1 Aug 2022 11:23:35 +1000 Subject: [PATCH] Support removing representations from IFC models that do not correctly follow the convention that mapped representations come from types --- src/blenderbim/blenderbim/core/geometry.py | 4 ++-- src/blenderbim/test/core/test_geometry.py | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/core/geometry.py b/src/blenderbim/blenderbim/core/geometry.py index 65742a684e..e4ac978016 100644 --- a/src/blenderbim/blenderbim/core/geometry.py +++ b/src/blenderbim/blenderbim/core/geometry.py @@ -120,8 +120,8 @@ def get_representation_ifc_parameters(geometry, obj=None, should_sync_changes_fi def remove_representation(ifc, geometry, obj=None, representation=None): element = ifc.get_entity(obj) - if geometry.is_mapped_representation(representation) or geometry.is_type_product(element): - type = geometry.get_element_type(element) + type = geometry.get_element_type(element) + 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) if data and geometry.has_data_users(data): diff --git a/src/blenderbim/test/core/test_geometry.py b/src/blenderbim/test/core/test_geometry.py index a22267cf8f..4eee95cc11 100644 --- a/src/blenderbim/test/core/test_geometry.py +++ b/src/blenderbim/test/core/test_geometry.py @@ -320,9 +320,9 @@ class TestGetRepresentationIfcParameters: class TestRemoveRepresentation: def test_removing_an_actively_used_mapped_representation_by_remapping_usages_to_an_empty(self, ifc, geometry): ifc.get_entity("obj").should_be_called().will_return("element") + geometry.get_element_type("element").should_be_called().will_return("type") geometry.is_mapped_representation("mapped_rep").should_be_called().will_return(False) geometry.is_type_product("element").should_be_called().will_return(True) - geometry.get_element_type("element").should_be_called().will_return("type") geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation") geometry.get_representation_data("representation").should_be_called().will_return("data") geometry.has_data_users("data").should_be_called().will_return(True) @@ -337,16 +337,29 @@ class TestRemoveRepresentation: def test_removing_an_unused_mapped_representation(self, ifc, geometry): ifc.get_entity("obj").should_be_called().will_return("element") - geometry.is_mapped_representation("mapped_rep").should_be_called().will_return(True) geometry.get_element_type("element").should_be_called().will_return("type") + geometry.is_mapped_representation("mapped_rep").should_be_called().will_return(True) geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation") geometry.get_representation_data("representation").should_be_called().will_return(None) ifc.run("geometry.unassign_representation", product="type", representation="representation").should_be_called() ifc.run("geometry.remove_representation", representation="representation").should_be_called() subject.remove_representation(ifc, geometry, obj="obj", representation="mapped_rep") + def test_remove_a_mapped_representation_by_an_element_with_no_type(self, ifc, geometry): + ifc.get_entity("obj").should_be_called().will_return("element") + geometry.get_element_type("element").should_be_called().will_return(None) + geometry.get_representation_data("representation").should_be_called().will_return("data") + geometry.has_data_users("data").should_be_called().will_return(True) + geometry.replace_object_with_empty("obj").should_be_called() + ifc.run( + "geometry.unassign_representation", product="element", representation="representation" + ).should_be_called() + ifc.run("geometry.remove_representation", representation="representation").should_be_called() + subject.remove_representation(ifc, geometry, obj="obj", representation="representation") + def test_removing_an_actively_used_representation(self, ifc, geometry): ifc.get_entity("obj").should_be_called().will_return("element") + geometry.get_element_type("element").should_be_called().will_return("type") geometry.is_mapped_representation("representation").should_be_called().will_return(False) geometry.is_type_product("element").should_be_called().will_return(False) geometry.get_representation_data("representation").should_be_called().will_return("data") @@ -360,6 +373,7 @@ class TestRemoveRepresentation: def test_removing_an_unused_representation(self, ifc, geometry): ifc.get_entity("obj").should_be_called().will_return("element") + geometry.get_element_type("element").should_be_called().will_return("type") geometry.is_mapped_representation("representation").should_be_called().will_return(False) geometry.is_type_product("element").should_be_called().will_return(False) geometry.get_representation_data("representation").should_be_called().will_return(None)