get_elements_by_style to support curve styles used in IfcFillAreaStyleHatching

This commit is contained in:
Andrej730
2024-10-01 11:36:25 +05:00
parent 55726b3d50
commit e040dc4562
2 changed files with 23 additions and 0 deletions
@@ -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
@@ -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):