mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 00:03:17 +00:00
get_element_by_style to support IfcFillAreaStyleTiles
This commit is contained in:
@@ -764,26 +764,30 @@ def get_elements_by_style(
|
|||||||
style = file.by_type("IfcSurfaceStyle")[0]
|
style = file.by_type("IfcSurfaceStyle")[0]
|
||||||
elements = ifcopenshell.util.element.get_elements_by_style(file, style)
|
elements = ifcopenshell.util.element.get_elements_by_style(file, style)
|
||||||
"""
|
"""
|
||||||
is_curve_style = style.is_a("IfcCurveStyle")
|
|
||||||
results = set()
|
results = set()
|
||||||
inverses = list(ifc_file.get_inverse(style))
|
inverses = list(ifc_file.get_inverse(style))
|
||||||
while inverses:
|
while inverses:
|
||||||
inverse = inverses.pop()
|
inverse = inverses.pop()
|
||||||
inverse_class = inverse.is_a()
|
inverse_class = inverse.is_a()
|
||||||
if is_curve_style and inverse_class in ("IfcFillAreaStyleHatching", "IfcFillAreaStyle"):
|
# IfcPresentationStyleAssignment for < IFC4X3.
|
||||||
inverses.extend(ifc_file.get_inverse(inverse))
|
# IfcFillAreaStyleHatching->IfcFillAreaStyle only for IfcCurveStyle.
|
||||||
continue
|
# IfcFillAreaStyleTiles->IfcFillAreaStyle is not restricted to IfcCurveStyle.
|
||||||
if inverse.is_a("IfcPresentationStyleAssignment"):
|
if inverse_class in (
|
||||||
|
"IfcPresentationStyleAssignment",
|
||||||
|
"IfcFillAreaStyleHatching",
|
||||||
|
"IfcFillAreaStyle",
|
||||||
|
"IfcFillAreaStyleTiles",
|
||||||
|
):
|
||||||
inverses.extend(ifc_file.get_inverse(inverse))
|
inverses.extend(ifc_file.get_inverse(inverse))
|
||||||
continue
|
continue
|
||||||
if not inverse.is_a("IfcStyledItem"):
|
if not inverse.is_a("IfcStyledItem"):
|
||||||
continue
|
continue
|
||||||
if inverse.Item:
|
if geometry_item := inverse.Item:
|
||||||
[
|
for inverse_ in ifc_file.get_inverse(geometry_item):
|
||||||
results.update(get_elements_by_representation(ifc_file, i))
|
if inverse_.is_a("IfcShapeRepresentation"):
|
||||||
for i in ifc_file.get_inverse(inverse.Item)
|
results.update(get_elements_by_representation(ifc_file, inverse_))
|
||||||
if i.is_a("IfcShapeRepresentation")
|
# IfcFillAreaStyleTiles requires .Item to be set.
|
||||||
]
|
inverses.extend(ifc_file.get_inverse(inverse))
|
||||||
else:
|
else:
|
||||||
styled_reps = [i for i in ifc_file.get_inverse(inverse) if i.is_a("IfcStyledRepresentation")]
|
styled_reps = [i for i in ifc_file.get_inverse(inverse) if i.is_a("IfcStyledRepresentation")]
|
||||||
for styled_rep in styled_reps:
|
for styled_rep in styled_reps:
|
||||||
|
|||||||
@@ -652,6 +652,29 @@ class TestGetElementsByStyle(test.bootstrap.IFC4):
|
|||||||
)
|
)
|
||||||
assert subject.get_elements_by_style(self.file, curve_style) == {element}
|
assert subject.get_elements_by_style(self.file, curve_style) == {element}
|
||||||
|
|
||||||
|
def test_getting_elements_of_a_styled_material_with_fill_area_style_tiles(self):
|
||||||
|
# NOTE: Not sure if this the exactly correct way to implement IfcFillAreaStyleTiles
|
||||||
|
# couldn't find any .ifc files implementing it, so taking my best guess.
|
||||||
|
# Ref: https://web.archive.org/web/20220711062839/https://ifcdoctor.com/2022/07/11/graphics-in-ifc/
|
||||||
|
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)
|
||||||
|
tile_style = self.file.create_entity("IfcCurveStyle")
|
||||||
|
tile_curve = self.file.create_entity("IfcGeometricSet")
|
||||||
|
styled_item = self.file.create_entity("IfcStyledItem", Styles=[tile_style], Item=tile_curve)
|
||||||
|
fill_style = self.file.create_entity("IfcFillAreaStyleTiles", Tiles=[styled_item])
|
||||||
|
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, tile_style) == {element}
|
||||||
|
|
||||||
|
|
||||||
class TestGetElementsByRepresentation(test.bootstrap.IFC4):
|
class TestGetElementsByRepresentation(test.bootstrap.IFC4):
|
||||||
def test_getting_elements_of_a_styled_representation_item(self):
|
def test_getting_elements_of_a_styled_representation_item(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user