#2111 New feature to select by style and see style usage

This commit is contained in:
Dion Moult
2022-05-08 18:03:18 +10:00
parent 910d189f35
commit 93fd3f97e3
12 changed files with 242 additions and 51 deletions
+103 -12
View File
@@ -278,7 +278,7 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", self.file)
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material)
assert subject.get_elements_by_material(self.file, material) == [element]
assert subject.get_elements_by_material(self.file, material) == {element}
def test_getting_elements_of_a_material_layer_set(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
@@ -290,9 +290,9 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, material=material_set)
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialLayerSetUsage")
usage = self.file.by_type("IfcMaterialLayerSetUsage")[0]
assert set(subject.get_elements_by_material(self.file, material)) == {element, element_type}
assert set(subject.get_elements_by_material(self.file, material_set)) == {element, element_type}
assert set(subject.get_elements_by_material(self.file, usage)) == {element}
assert subject.get_elements_by_material(self.file, material) == {element, element_type}
assert subject.get_elements_by_material(self.file, material_set) == {element, element_type}
assert subject.get_elements_by_material(self.file, usage) == {element}
def test_getting_elements_of_a_material_profile_set(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
@@ -304,18 +304,20 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
ifcopenshell.api.run("material.assign_material", self.file, product=element_type, material=material_set)
ifcopenshell.api.run("material.assign_material", self.file, product=element, type="IfcMaterialProfileSetUsage")
usage = self.file.by_type("IfcMaterialProfileSetUsage")[0]
assert set(subject.get_elements_by_material(self.file, material)) == {element, element_type}
assert set(subject.get_elements_by_material(self.file, material_set)) == {element, element_type}
assert set(subject.get_elements_by_material(self.file, usage)) == {element}
assert subject.get_elements_by_material(self.file, material) == {element, element_type}
assert subject.get_elements_by_material(self.file, material_set) == {element, element_type}
assert subject.get_elements_by_material(self.file, usage) == {element}
def test_getting_elements_of_a_material_constituent_set(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
material = ifcopenshell.api.run("material.add_material", self.file)
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialConstituentSet")
material_set = ifcopenshell.api.run(
"material.add_material_set", self.file, set_type="IfcMaterialConstituentSet"
)
ifcopenshell.api.run("material.add_constituent", self.file, constituent_set=material_set, material=material)
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
assert set(subject.get_elements_by_material(self.file, material)) == {element}
assert set(subject.get_elements_by_material(self.file, material_set)) == {element}
assert subject.get_elements_by_material(self.file, material) == {element}
assert subject.get_elements_by_material(self.file, material_set) == {element}
def test_getting_elements_of_a_material_list(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
@@ -323,8 +325,97 @@ class TestGetElementsByMaterial(test.bootstrap.IFC4):
material_set = ifcopenshell.api.run("material.add_material_set", self.file, set_type="IfcMaterialList")
ifcopenshell.api.run("material.add_list_item", self.file, material_list=material_set, material=material)
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material_set)
assert set(subject.get_elements_by_material(self.file, material)) == {element}
assert set(subject.get_elements_by_material(self.file, material_set)) == {element}
assert subject.get_elements_by_material(self.file, material) == {element}
assert subject.get_elements_by_material(self.file, material_set) == {element}
class TestGetElementsByStyle(test.bootstrap.IFC4):
def test_getting_elements_of_a_styled_representation_item(self):
element = self.file.createIfcWall()
style = self.file.createIfcSurfaceStyle()
item = self.file.createIfcExtrudedAreaSolid()
self.file.createIfcStyledItem(Item=item, Styles=[style])
element.Representation = self.file.createIfcProductDefinitionShape(
Representations=[self.file.createIfcShapeRepresentation(Items=[item])]
)
assert subject.get_elements_by_style(self.file, style) == {element}
def test_getting_elements_of_a_styled_mapped_representation_item(self):
element = self.file.createIfcWall()
style = self.file.createIfcSurfaceStyle()
item = self.file.createIfcExtrudedAreaSolid()
self.file.createIfcStyledItem(Item=item, Styles=[style])
element.Representation = self.file.createIfcProductDefinitionShape(
Representations=[
self.file.createIfcShapeRepresentation(
Items=[
self.file.createIfcMappedItem(
MappingSource=self.file.createIfcRepresentationMap(
MappedRepresentation=self.file.createIfcShapeRepresentation(Items=[item])
)
)
]
)
]
)
assert subject.get_elements_by_style(self.file, style) == {element}
def test_getting_type_elements_of_a_styled_mapped_representation_item(self):
element = self.file.createIfcWallType()
style = self.file.createIfcSurfaceStyle()
item = self.file.createIfcExtrudedAreaSolid()
self.file.createIfcStyledItem(Item=item, Styles=[style])
element.RepresentationMaps = [
self.file.createIfcRepresentationMap(
MappedRepresentation=self.file.createIfcShapeRepresentation(Items=[item])
)
]
assert subject.get_elements_by_style(self.file, style) == {element}
def test_getting_elements_of_a_styled_material(self):
element = self.file.createIfcWall()
material = ifcopenshell.api.run("material.add_material", self.file)
ifcopenshell.api.run("material.assign_material", self.file, product=element, material=material)
style = self.file.createIfcSurfaceStyle()
self.file.createIfcMaterialDefinitionRepresentation(
RepresentedMaterial=material,
Representations=[
self.file.createIfcStyledRepresentation(Items=[self.file.createIfcStyledItem(Styles=[style])])
],
)
assert subject.get_elements_by_style(self.file, style) == {element}
class TestGetElementsByRepresentation(test.bootstrap.IFC4):
def test_getting_elements_of_a_styled_representation_item(self):
element = self.file.createIfcWall()
representation = self.file.createIfcShapeRepresentation()
element.Representation = self.file.createIfcProductDefinitionShape(Representations=[representation])
assert subject.get_elements_by_representation(self.file, representation) == {element}
def test_getting_elements_of_a_styled_mapped_representation_item(self):
element = self.file.createIfcWall()
representation = self.file.createIfcShapeRepresentation()
element.Representation = self.file.createIfcProductDefinitionShape(
Representations=[
self.file.createIfcShapeRepresentation(
Items=[
self.file.createIfcMappedItem(
MappingSource=self.file.createIfcRepresentationMap(
MappedRepresentation=representation
)
)
]
)
]
)
assert subject.get_elements_by_representation(self.file, representation) == {element}
def test_getting_type_elements_of_a_styled_mapped_representation_item(self):
element = self.file.createIfcWallType()
representation = self.file.createIfcShapeRepresentation()
element.RepresentationMaps = [self.file.createIfcRepresentationMap(MappedRepresentation=representation)]
assert subject.get_elements_by_representation(self.file, representation) == {element}
class TestGetlayers(test.bootstrap.IFC4):