From 0fbe4d80c728ad91581fcd07b19f35dac765b8d3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 26 Dec 2023 11:24:49 +0500 Subject: [PATCH] Clean up IfcIndexedColourMap removing representation #4138 Because we wasn't removing colour map, remove_representation was producing orphaned IfcPolygonalFaceSet that were referred by colour map. --- .../ifcopenshell/api/geometry/remove_representation.py | 7 ++++++- .../test/api/geometry/test_remove_representation.py | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py index ea6d79fe1c..f926351cf4 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py @@ -30,10 +30,13 @@ class Usecase: styled_items = set() presentation_layer_assignments = set() textures = set() + colours = set() for subelement in self.file.traverse(self.settings["representation"]): if subelement.is_a("IfcRepresentationItem"): [styled_items.add(s) for s in subelement.StyledByItem or []] + # IfcTesselatedFaceSet inverses [textures.add(t) for t in getattr(subelement, "HasTextures", []) or []] + [colours.add(t) for t in getattr(subelement, "HasColours", []) or []] elif subelement.is_a("IfcRepresentation"): for inverse in self.file.get_inverse(subelement): if inverse.is_a("IfcPresentationLayerAssignment"): @@ -42,12 +45,14 @@ class Usecase: ifcopenshell.util.element.remove_deep2( self.file, self.settings["representation"], - also_consider=list(styled_items | presentation_layer_assignments), + also_consider=list(styled_items | presentation_layer_assignments | colours), do_not_delete=self.file.by_type("IfcGeometricRepresentationContext"), ) for texture in textures: ifcopenshell.util.element.remove_deep2(self.file, texture) + for colour in colours: + ifcopenshell.util.element.remove_deep2(self.file, colour) to_delete = getattr(self.file, "to_delete", ()) for element in styled_items: diff --git a/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py b/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py index 53b6acc0e1..bd62f68bd6 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py +++ b/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py @@ -100,6 +100,14 @@ class TestRemoveRepresentation(test.bootstrap.IFC4): ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1 + def test_purging_colour_map(self): + item = self.file.createIfcTriangulatedFaceSet() + representation = self.file.createIfcShapeRepresentation(Items=[item]) + colour = self.file.createIfcIndexedColourMap(Colours=self.file.createIfcColourRgbList(), MappedTo=item) + ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) + assert len(self.file.by_type("IfcIndexedColourMap")) == 0 + assert len(self.file.by_type("IfcColourRgbList")) == 0 + def test_purging_texture_coordinates(self): item = self.file.createIfcTriangulatedFaceSet() representation = self.file.createIfcShapeRepresentation(Items=[item])