From bd64f42a54b4a64bcff20ef3d6d3fed3f10bccf9 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 30 Jan 2024 11:40:18 +0500 Subject: [PATCH] remove_representation to consider representation item's layers too and purge layers if they are out of items as they become invalid --- .../api/geometry/remove_representation.py | 1 + .../geometry/test_remove_representation.py | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py index 2f14593b0c..b43853f65c 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/remove_representation.py @@ -47,6 +47,7 @@ class Usecase: for subelement in self.file.traverse(self.settings["representation"]): if subelement.is_a("IfcRepresentationItem"): [styled_items.add(s) for s in subelement.StyledByItem or []] + [presentation_layer_assignments.add(s) for s in subelement.LayerAssignment] # IfcTessellatedFaceSet inverses [textures.add(t) for t in getattr(subelement, "HasTextures", []) or []] [colours.add(t) for t in getattr(subelement, "HasColours", []) or []] 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 bd62f68bd6..a1b52e8eb1 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py +++ b/src/ifcopenshell-python/test/api/geometry/test_remove_representation.py @@ -79,14 +79,14 @@ class TestRemoveRepresentation(test.bootstrap.IFC4): ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) assert len(self.file.by_type("IfcStyledItem")) == 1 - def test_purging_presentation_layers(self): + def test_purging_representation_presentation_layers(self): representation = self.file.createIfcShapeRepresentation() layer = self.file.createIfcPresentationLayerAssignment(AssignedItems=[representation]) ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) assert len(self.file.by_type("IfcPresentationLayerAssignment")) == 0 assert len(self.file.by_type("IfcShapeRepresentation")) == 0 - def test_not_purging_presentation_layers_still_in_use(self): + def test_not_purging_representation_presentation_layers_still_in_use(self): representation = self.file.createIfcShapeRepresentation() representation2 = self.file.createIfcShapeRepresentation() layer = self.file.createIfcPresentationLayerAssignment(AssignedItems=[representation, representation2]) @@ -94,6 +94,23 @@ class TestRemoveRepresentation(test.bootstrap.IFC4): assert len(self.file.by_type("IfcPresentationLayerAssignment")) == 1 assert len(self.file.by_type("IfcShapeRepresentation")) == 1 + def test_purging_representation_item_presentation_layers(self): + item = self.file.createIfcExtrudedAreaSolid() + representation = self.file.createIfcShapeRepresentation(Items=[item]) + layer = self.file.createIfcPresentationLayerAssignment(AssignedItems=[item]) + ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) + assert len(self.file.by_type("IfcPresentationLayerAssignment")) == 0 + assert len(self.file.by_type("IfcExtrudedAreaSolid")) == 0 + + def test_not_purging_representation_item_presentation_layers_still_in_use(self): + item, item2 = self.file.createIfcExtrudedAreaSolid(), self.file.createIfcExtrudedAreaSolid() + representation = self.file.createIfcShapeRepresentation(Items=[item]) + representation2 = self.file.createIfcShapeRepresentation(Items=[item2]) + layer = self.file.createIfcPresentationLayerAssignment(AssignedItems=[item, item2]) + ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation) + assert len(self.file.by_type("IfcPresentationLayerAssignment")) == 1 + assert len(self.file.by_type("IfcExtrudedAreaSolid")) == 1 + def test_not_purging_geometric_representation_contexts(self): context = self.file.createIfcGeometricRepresentationSubContext() representation = self.file.createIfcShapeRepresentation(ContextOfItems=context)