From b7c390585bf06fb1da81aa229cbce6d3f2089954 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 30 Sep 2024 20:58:16 +0500 Subject: [PATCH] ios - fix error removing other IfcPresentationStyles besides IfcSurfaceStyle --- .../ifcopenshell/api/style/remove_style.py | 13 +++++++------ .../test/api/style/test_remove_style.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py b/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py index bf10cd57ce..fbf0909979 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/remove_style.py @@ -42,18 +42,19 @@ def remove_style(file: ifcopenshell.file, style: ifcopenshell.entity_instance) - usecase = Usecase() usecase.file = file usecase.settings = {"style": style} - return usecase.execute() + return usecase.execute(style) class Usecase: file: ifcopenshell.file settings: dict[str, Any] - def execute(self) -> None: - self.purge_styled_items(self.settings["style"]) - for style in self.settings["style"].Styles or []: - ifcopenshell.api.style.remove_surface_style(self.file, style=style) - self.file.remove(self.settings["style"]) + def execute(self, style: ifcopenshell.entity_instance) -> None: + self.purge_styled_items(style) + if style.is_a("IfcSurfaceStyle"): + for style_ in style.Styles: + ifcopenshell.api.style.remove_surface_style(self.file, style=style_) + self.file.remove(style) def purge_styled_items(self, style: ifcopenshell.entity_instance) -> None: for inverse in self.file.get_inverse(style): 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 c17069e889..1b65a4d573 100644 --- a/src/ifcopenshell-python/test/api/style/test_remove_style.py +++ b/src/ifcopenshell-python/test/api/style/test_remove_style.py @@ -35,6 +35,17 @@ class TestRemoveStyle(test.bootstrap.IFC4): ifcopenshell.api.style.remove_style(self.file, style=style) assert len(list(self.file)) == 0 + def test_remove_non_surface_styles(self): + STYLE_TYPES = [ + "IfcCurveStyle", + "IfcFillAreaStyle", + "IfcTextStyle", + ] + for style_type in STYLE_TYPES: + style = self.file.create_entity(style_type) + ifcopenshell.api.style.remove_style(self.file, style=style) + assert len(self.file.by_type("IfcPresentationStyle")) == 0 + class TestRemoveStyleIFC2X3(test.bootstrap.IFC2X3, TestRemoveStyle): pass