mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
#2196 Get psets now handleds inheritance by default
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
def get_psets(element, psets_only=False, qtos_only=False):
|
||||
def get_psets(element, psets_only=False, qtos_only=False, should_inherit=True):
|
||||
psets = {}
|
||||
if element.is_a("IfcTypeObject"):
|
||||
for definition in element.HasPropertySets or []:
|
||||
@@ -34,6 +34,9 @@ def get_psets(element, psets_only=False, qtos_only=False):
|
||||
continue
|
||||
psets[definition.Name] = get_property_definition(definition)
|
||||
elif hasattr(element, "IsDefinedBy"):
|
||||
element_type = ifcopenshell.util.element.get_type(element)
|
||||
if element_type and should_inherit:
|
||||
psets = get_psets(element_type)
|
||||
for relationship in element.IsDefinedBy:
|
||||
if relationship.is_a("IfcRelDefinesByProperties"):
|
||||
definition = relationship.RelatingPropertyDefinition
|
||||
@@ -41,7 +44,7 @@ def get_psets(element, psets_only=False, qtos_only=False):
|
||||
continue
|
||||
if qtos_only and not definition.is_a("IfcElementQuantity"):
|
||||
continue
|
||||
psets[definition.Name] = get_property_definition(definition)
|
||||
psets.setdefault(definition.Name, {}).update(get_property_definition(definition))
|
||||
return psets
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,20 @@ class TestGetPsetsIFC4(test.bootstrap.IFC4):
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"x": "y"})
|
||||
assert subject.get_psets(type_element) == {"name": {"x": "y", "id": pset.id()}}
|
||||
|
||||
def test_getting_inherited_psets(self):
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
type_element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||
ifcopenshell.api.run("type.assign_type", self.file, related_object=element, relating_type=type_element)
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=type_element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 1, "x": 1})
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="name")
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"a": 2, "b": 3})
|
||||
psets = subject.get_psets(element)
|
||||
assert psets["name"]["id"] == pset.id()
|
||||
assert psets["name"]["a"] == 2
|
||||
assert psets["name"]["x"] == 1
|
||||
assert psets["name"]["b"] == 3
|
||||
|
||||
def test_getting_the_psets_of_a_material_as_a_dictionary(self):
|
||||
material = self.file.createIfcMaterial()
|
||||
assert subject.get_psets(material) == {}
|
||||
|
||||
Reference in New Issue
Block a user