From f63a7d420e61f0fc3627d738a2780dbe215b474f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 1 Oct 2024 15:27:52 +0500 Subject: [PATCH] style.remove_style to handle IfcFillAreaStyles --- .../ifcopenshell/api/style/remove_style.py | 6 ++++- .../test/api/style/test_remove_style.py | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py b/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py index eb29d58c74..31d21700f6 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py @@ -51,9 +51,13 @@ class Usecase: def execute(self, style: ifcopenshell.entity_instance) -> None: self.purge_inverses(style) - if style.is_a("IfcSurfaceStyle"): + ifc_class = style.is_a() + if ifc_class == "IfcSurfaceStyle": for style_ in style.Styles: ifcopenshell.api.style.remove_surface_style(self.file, style=style_) + elif ifc_class == "IfcFillAreaStyle": + for style_ in style.FillStyles: + ifcopenshell.util.element.remove_deep2(self.file, style_, also_consider=[style]) self.file.remove(style) def purge_inverses(self, style: ifcopenshell.entity_instance) -> None: diff --git a/src/ifcopenshell-python/test/api/style/test_remove_style.py b/src/ifcopenshell-python/test/api/style/test_remove_style.py index e169fe4b95..7282d38606 100644 --- a/src/ifcopenshell-python/test/api/style/test_remove_style.py +++ b/src/ifcopenshell-python/test/api/style/test_remove_style.py @@ -69,6 +69,28 @@ class TestRemoveStyle(test.bootstrap.IFC4): assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 0 assert len(self.file.by_type("IfcStyledRepresentation")) == 0 + def test_remove_fill_area_with_fill_area_style_hatching(self): + element = self.file.create_entity("IfcWall") + material = ifcopenshell.api.material.add_material(self.file) + ifcopenshell.api.material.assign_material(self.file, products=[element], material=material) + curve_style = self.file.create_entity("IfcCurveStyle") + fill_style = self.file.create_entity("IfcFillAreaStyleHatching", HatchLineAppearance=curve_style) + style = self.file.create_entity("IfcFillAreaStyle", FillStyles=[fill_style]) + self.file.create_entity( + "IfcMaterialDefinitionRepresentation", + RepresentedMaterial=material, + Representations=[ + self.file.create_entity( + "IfcStyledRepresentation", + Items=[self.file.create_entity("IfcStyledItem", Styles=[style])], + ) + ], + ) + ifcopenshell.api.style.remove_style(self.file, style) + assert len(self.file.by_type("IfcPresentationStyle")) == 0 + assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 0 + assert len(self.file.by_type("IfcStyledRepresentation")) == 0 + class TestRemoveStyleIFC2X3(test.bootstrap.IFC2X3, TestRemoveStyle): pass