mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-15 18:14:08 +00:00
Fixed bug where enumeration values in psets could be empty lists.
This commit is contained in:
@@ -171,7 +171,7 @@ class Usecase:
|
|||||||
self.pset_template = self.settings["pset_template"]
|
self.pset_template = self.settings["pset_template"]
|
||||||
else:
|
else:
|
||||||
# TODO: add IFC2X3 PsetQto template support
|
# TODO: add IFC2X3 PsetQto template support
|
||||||
self.psetqto = ifcopenshell.util.pset.get_template("IFC4")
|
self.psetqto = ifcopenshell.util.pset.get_template(self.file.schema)
|
||||||
self.pset_template = self.psetqto.get_by_name(self.settings["pset"].Name)
|
self.pset_template = self.psetqto.get_by_name(self.settings["pset"].Name)
|
||||||
|
|
||||||
# TODO - Add support for changing property types?
|
# TODO - Add support for changing property types?
|
||||||
@@ -198,16 +198,15 @@ class Usecase:
|
|||||||
].is_a() # Only need the first enum type since all enums are of the same type
|
].is_a() # Only need the first enum type since all enums are of the same type
|
||||||
ifc_val = self.file.create_entity(primary_measure_type, val)
|
ifc_val = self.file.create_entity(primary_measure_type, val)
|
||||||
sel_vals.append(ifc_val)
|
sel_vals.append(ifc_val)
|
||||||
prop.EnumerationValues = tuple(sel_vals)
|
prop.EnumerationValues = tuple(sel_vals) or None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if value.EnumerationReference.EnumerationValues == ():
|
if value.EnumerationReference.EnumerationValues == ():
|
||||||
if self.settings["should_purge"]:
|
if self.settings["should_purge"]:
|
||||||
del self.settings["properties"][prop.Name]
|
del self.settings["properties"][prop.Name]
|
||||||
self.file.remove(prop)
|
self.file.remove(prop)
|
||||||
return
|
return
|
||||||
prop.EnumerationReference.EnumerationValues = ()
|
prop.EnumerationReference.EnumerationValues = None
|
||||||
prop.EnumerationValues = ()
|
prop.EnumerationValues = None
|
||||||
elif isinstance(value, ifcopenshell.entity_instance):
|
elif isinstance(value, ifcopenshell.entity_instance):
|
||||||
prop.EnumerationReference.EnumerationValues = value.EnumerationReference.EnumerationValues
|
prop.EnumerationReference.EnumerationValues = value.EnumerationReference.EnumerationValues
|
||||||
prop.EnumerationValues = value.EnumerationValues
|
prop.EnumerationValues = value.EnumerationValues
|
||||||
@@ -257,7 +256,9 @@ class Usecase:
|
|||||||
)
|
)
|
||||||
# TODO-The following "elif" is temporary code, will need to refactor at some point - vulevukusej
|
# TODO-The following "elif" is temporary code, will need to refactor at some point - vulevukusej
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
for pset_template in self.settings["pset_template"].HasPropertyTemplates:
|
if not value:
|
||||||
|
continue
|
||||||
|
for pset_template in self.pset_template.HasPropertyTemplates:
|
||||||
if pset_template.Name == name:
|
if pset_template.Name == name:
|
||||||
prop_enum = self.file.create_entity(
|
prop_enum = self.file.create_entity(
|
||||||
"IFCPROPERTYENUMERATION",
|
"IFCPROPERTYENUMERATION",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class TestEditPset(test.bootstrap.IFC4):
|
|||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
self.file,
|
self.file,
|
||||||
pset=pset,
|
pset=pset,
|
||||||
properties={"Reference": "reference", "Status": "NEW", "Combustible": True, "ThermalTransmittance": 42},
|
properties={"Reference": "reference", "Status": ["NEW"], "Combustible": True, "ThermalTransmittance": 42},
|
||||||
)
|
)
|
||||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||||
|
|
||||||
@@ -37,8 +37,8 @@ class TestEditPset(test.bootstrap.IFC4):
|
|||||||
assert pset.HasProperties[0].NominalValue.wrappedValue == "reference"
|
assert pset.HasProperties[0].NominalValue.wrappedValue == "reference"
|
||||||
|
|
||||||
assert pset.HasProperties[1].Name == "Status"
|
assert pset.HasProperties[1].Name == "Status"
|
||||||
assert pset.HasProperties[1].NominalValue.is_a("IfcLabel")
|
assert pset.HasProperties[1].EnumerationValues[0].is_a("IfcLabel")
|
||||||
assert pset.HasProperties[1].NominalValue.wrappedValue == "NEW"
|
assert pset.HasProperties[1].EnumerationValues[0].wrappedValue == "NEW"
|
||||||
|
|
||||||
assert pset.HasProperties[2].Name == "Combustible"
|
assert pset.HasProperties[2].Name == "Combustible"
|
||||||
assert pset.HasProperties[2].NominalValue.is_a("IfcBoolean")
|
assert pset.HasProperties[2].NominalValue.is_a("IfcBoolean")
|
||||||
@@ -55,9 +55,9 @@ class TestEditPset(test.bootstrap.IFC4):
|
|||||||
"pset.edit_pset",
|
"pset.edit_pset",
|
||||||
self.file,
|
self.file,
|
||||||
pset=pset,
|
pset=pset,
|
||||||
properties={"Reference": "foo", "Status": "NEW", "Combustible": True, "ThermalTransmittance": 42},
|
properties={"Reference": "foo", "Status": ["NEW"], "Combustible": True, "ThermalTransmittance": 42},
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": None})
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": "bar", "Status": []})
|
||||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||||
|
|
||||||
assert pset.HasProperties[0].Name == "Reference"
|
assert pset.HasProperties[0].Name == "Reference"
|
||||||
@@ -65,7 +65,7 @@ class TestEditPset(test.bootstrap.IFC4):
|
|||||||
assert pset.HasProperties[0].NominalValue.wrappedValue == "bar"
|
assert pset.HasProperties[0].NominalValue.wrappedValue == "bar"
|
||||||
|
|
||||||
assert pset.HasProperties[1].Name == "Status"
|
assert pset.HasProperties[1].Name == "Status"
|
||||||
assert pset.HasProperties[1].NominalValue is None
|
assert pset.HasProperties[1].EnumerationValues is None
|
||||||
|
|
||||||
def test_editing_a_templated_pset_with_automatic_casting_of_primitive_data_types(self):
|
def test_editing_a_templated_pset_with_automatic_casting_of_primitive_data_types(self):
|
||||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
|||||||
Reference in New Issue
Block a user