From e040dc4562160d577fed92c2c62f01c9e2348ccf Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 1 Oct 2024 11:36:25 +0500 Subject: [PATCH] get_elements_by_style to support curve styles used in IfcFillAreaStyleHatching --- .../ifcopenshell/util/element.py | 5 +++++ .../test/util/test_element.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 3859b21810..df0b5d8786 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -764,10 +764,15 @@ def get_elements_by_style( style = file.by_type("IfcSurfaceStyle")[0] elements = ifcopenshell.util.element.get_elements_by_style(file, style) """ + is_curve_style = style.is_a("IfcCurveStyle") results = set() inverses = list(ifc_file.get_inverse(style)) while inverses: inverse = inverses.pop() + inverse_class = inverse.is_a() + if is_curve_style and inverse_class in ("IfcFillAreaStyleHatching", "IfcFillAreaStyle"): + inverses.extend(ifc_file.get_inverse(inverse)) + continue if inverse.is_a("IfcPresentationStyleAssignment"): inverses.extend(ifc_file.get_inverse(inverse)) continue diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index 759f6ff0f6..ddb84900a3 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -634,6 +634,24 @@ class TestGetElementsByStyle(test.bootstrap.IFC4): ) assert subject.get_elements_by_style(self.file, style) == {element} + def test_getting_elements_of_a_styled_material_with_curve_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])] + ) + ], + ) + assert subject.get_elements_by_style(self.file, curve_style) == {element} + class TestGetElementsByRepresentation(test.bootstrap.IFC4): def test_getting_elements_of_a_styled_representation_item(self):