style.assign_representation_styles to replace previously assigned styles

as probably in the most cases user would want 1 style per 1 representation item

After this it's finally possible in BBIM to assign styles to representation items through the materials: https://imgur.com/a/cgiJ1KV
This commit is contained in:
Andrej730
2024-02-22 13:41:34 +05:00
parent 0d251260d8
commit dd27107be8
2 changed files with 91 additions and 25 deletions
@@ -38,14 +38,22 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
)
assert item.StyledByItem[0].Styles == (style,)
# reusing existing styled item
style2 = self.file.createIfcSurfaceStyle()
# reusing existing styled item for different style type
style2 = self.file.createIfcFillAreaStyle()
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, styles=[style2], shape_representation=representation
)
assert item.StyledByItem[0].Styles == (style, style2)
assert len(self.file.by_type("IfcStyledItem")) == 1
# replacing existing style of the same type
style3 = self.file.createIfcSurfaceStyle()
ifcopenshell.api.run(
"style.assign_representation_styles", self.file, styles=[style3], shape_representation=representation
)
assert item.StyledByItem[0].Styles == (style2, style3)
assert len(self.file.by_type("IfcStyledItem")) == 1
def test_assign_using_style_assignment(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
product_shape = self.file.createIfcProductDefinitionShape()
@@ -68,8 +76,8 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
assert style_assignment.Styles == (style,)
assert item.StyledByItem[0].Styles == (style_assignment,)
# reusing existing styled item and style assignment
style2 = self.file.createIfcSurfaceStyle()
# reusing existing styled item for different style type
style2 = self.file.createIfcFillAreaStyle()
ifcopenshell.api.run(
"style.assign_representation_styles",
self.file,
@@ -83,6 +91,21 @@ class TestAssignRepresentationStyles(test.bootstrap.IFC4):
assert item.StyledByItem[0].Styles[0].Styles == (style, style2)
assert len(self.file.by_type("IfcStyledItem")) == 1
# replacing existing style of the same type
style3 = self.file.createIfcSurfaceStyle()
ifcopenshell.api.run(
"style.assign_representation_styles",
self.file,
styles=[style3],
shape_representation=representation,
should_use_presentation_style_assignment=True,
)
assert len(self.file.by_type("IfcPresentationStyleAssignment")) == 1
assert item.StyledByItem[0].Styles == (style_assignment,)
assert item.StyledByItem[0].Styles[0].Styles == (style2, style3)
assert len(self.file.by_type("IfcStyledItem")) == 1
class TestAssignRepresentationStylesIFC2X3(test.bootstrap.IFC2X3):
def test_run(self):