mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
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:
@@ -30,10 +30,13 @@ class Usecase:
|
|||||||
styled_items = set()
|
styled_items = set()
|
||||||
presentation_layer_assignments = set()
|
presentation_layer_assignments = set()
|
||||||
textures = set()
|
textures = set()
|
||||||
|
colours = set()
|
||||||
for subelement in self.file.traverse(self.settings["representation"]):
|
for subelement in self.file.traverse(self.settings["representation"]):
|
||||||
if subelement.is_a("IfcRepresentationItem"):
|
if subelement.is_a("IfcRepresentationItem"):
|
||||||
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
||||||
|
# IfcTesselatedFaceSet inverses
|
||||||
[textures.add(t) for t in getattr(subelement, "HasTextures", []) or []]
|
[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"):
|
elif subelement.is_a("IfcRepresentation"):
|
||||||
for inverse in self.file.get_inverse(subelement):
|
for inverse in self.file.get_inverse(subelement):
|
||||||
if inverse.is_a("IfcPresentationLayerAssignment"):
|
if inverse.is_a("IfcPresentationLayerAssignment"):
|
||||||
@@ -42,12 +45,14 @@ class Usecase:
|
|||||||
ifcopenshell.util.element.remove_deep2(
|
ifcopenshell.util.element.remove_deep2(
|
||||||
self.file,
|
self.file,
|
||||||
self.settings["representation"],
|
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"),
|
do_not_delete=self.file.by_type("IfcGeometricRepresentationContext"),
|
||||||
)
|
)
|
||||||
|
|
||||||
for texture in textures:
|
for texture in textures:
|
||||||
ifcopenshell.util.element.remove_deep2(self.file, texture)
|
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", ())
|
to_delete = getattr(self.file, "to_delete", ())
|
||||||
for element in styled_items:
|
for element in styled_items:
|
||||||
|
|||||||
@@ -100,6 +100,14 @@ class TestRemoveRepresentation(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation)
|
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=representation)
|
||||||
assert len(self.file.by_type("IfcGeometricRepresentationContext")) == 1
|
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):
|
def test_purging_texture_coordinates(self):
|
||||||
item = self.file.createIfcTriangulatedFaceSet()
|
item = self.file.createIfcTriangulatedFaceSet()
|
||||||
representation = self.file.createIfcShapeRepresentation(Items=[item])
|
representation = self.file.createIfcShapeRepresentation(Items=[item])
|
||||||
|
|||||||
Reference in New Issue
Block a user