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.
This commit is contained in:
Andrej730
2023-12-26 11:24:49 +05:00
parent 7df5ef6cd6
commit 3008599eec
2 changed files with 14 additions and 1 deletions
@@ -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:
@@ -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])