mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 09:26:52 +00:00
Fix #4365
Allowing to add new properties with None values if should_purge is not set to True (and it's False by default)
This commit is contained in:
@@ -278,7 +278,7 @@ class Usecase:
|
|||||||
def add_new_properties(self):
|
def add_new_properties(self):
|
||||||
properties = []
|
properties = []
|
||||||
for name, value in self.settings["properties"].items():
|
for name, value in self.settings["properties"].items():
|
||||||
if value is None:
|
if value is None and self.settings["should_purge"]:
|
||||||
continue
|
continue
|
||||||
unit, value = self.unpack_unit_value(value)
|
unit, value = self.unpack_unit_value(value)
|
||||||
|
|
||||||
@@ -343,8 +343,11 @@ class Usecase:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
primary_measure_type = self.get_primary_measure_type(name, new_value=value)
|
primary_measure_type = self.get_primary_measure_type(name, new_value=value)
|
||||||
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
if value is None:
|
||||||
nominal_value = self.file.create_entity(primary_measure_type, value)
|
nominal_value = value
|
||||||
|
else:
|
||||||
|
value = self.cast_value_to_primary_measure_type(value, primary_measure_type)
|
||||||
|
nominal_value = self.file.create_entity(primary_measure_type, value)
|
||||||
args = {"Name": name, "NominalValue": nominal_value}
|
args = {"Name": name, "NominalValue": nominal_value}
|
||||||
if unit:
|
if unit:
|
||||||
args["Unit"] = unit
|
args["Unit"] = unit
|
||||||
|
|||||||
@@ -84,11 +84,19 @@ class TestEditPset(test.bootstrap.IFC4):
|
|||||||
assert pset.HasProperties[0].NominalValue.is_a("IfcThermalTransmittanceMeasure")
|
assert pset.HasProperties[0].NominalValue.is_a("IfcThermalTransmittanceMeasure")
|
||||||
assert pset.HasProperties[0].NominalValue.wrappedValue == 42
|
assert pset.HasProperties[0].NominalValue.wrappedValue == 42
|
||||||
|
|
||||||
def test_not_adding_a_property_if_it_is_none(self):
|
def test_adding_a_property_if_it_is_none(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")
|
||||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||||
|
# should_purge is false by default
|
||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None})
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None})
|
||||||
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||||
|
assert len(pset.HasProperties) == 1
|
||||||
|
|
||||||
|
def test_not_adding_a_property_if_it_is_none_and_should_purge_is_true(self):
|
||||||
|
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||||
|
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Pset_WallCommon")
|
||||||
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=True)
|
||||||
|
pset = element.IsDefinedBy[0].RelatingPropertyDefinition
|
||||||
assert len(pset.HasProperties) == 0
|
assert len(pset.HasProperties) == 0
|
||||||
|
|
||||||
def test_removing_a_none_property_if_specified(self):
|
def test_removing_a_none_property_if_specified(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user