Fix MASSUNIT bug (#7173)

* add exception

* black
This commit is contained in:
Christoph Mellüh
2025-10-05 06:31:06 +02:00
committed by GitHub
parent add5132dec
commit 2d8383efc6
2 changed files with 25 additions and 2 deletions
+2 -1
View File
@@ -719,11 +719,12 @@ class Property(Facet):
unit = ifcopenshell.util.unit.get_property_unit(prop_entity, inst.wrapped_data.file)
if unit and getattr(unit, "Name", None):
# TODO support unnamed derived units
output_prefix = "KILO" if unit.UnitType == "MASSUNIT" else None
props[pset_name][prop_entity.Name] = ifcopenshell.util.unit.convert(
prop_entity.NominalValue.wrappedValue,
getattr(unit, "Prefix", None),
unit.Name,
None,
output_prefix,
ifcopenshell.util.unit.si_type_names[unit.UnitType],
)
elif prop_entity.is_a("IfcPhysicalSimpleQuantity"):
+23 -1
View File
@@ -1290,6 +1290,27 @@ class TestProperty:
run("Properties can be overriden by an occurrence 1/2", facet=facet, inst=wall, expected=True)
run("Properties can be overriden by an occurrence 2/2", facet=facet, inst=wall_type, expected=False)
ifc = self.setup_ifc()
element = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall")
pset = ifcopenshell.api.pset.add_pset(ifc, product=element, name="Foo_Bar")
prop = ifc.create_entity(
"IfcPropertySingleValue", Name="Foo", NominalValue=ifc.create_entity("IfcMassMeasure", 6.0)
)
ifcopenshell.api.pset.edit_pset(ifc, pset=pset, properties={"Foo": prop})
restriction = Restriction(options={"minExclusive": 5.0}, base="double")
facet = Property(propertySet="Foo_Bar", baseName="Foo", value=restriction, dataType="IfcMassMeasure")
run("MASSUNIT uses Kg instead of g", facet=facet, inst=element, expected=True)
prop.NominalValue = ifc.create_entity("IfcMassMeasure", 4.0)
run("MASSUNIT uses Kg instead of g", facet=facet, inst=element, expected=False)
# add Gram as Unit to force conversion
gram_unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="MASSUNIT")
prop.Unit = gram_unit
prop.NominalValue = ifc.create_entity("IfcMassMeasure", 6000.0)
run("MASSUNIT uses Kg instead of g", facet=facet, inst=element, expected=True)
prop.NominalValue = ifc.create_entity("IfcMassMeasure", 6.0)
run("MASSUNIT uses Kg instead of g", facet=facet, inst=element, expected=False)
def setup_ifc(self):
ifc = ifcopenshell.file()
ifc.createIfcProject()
@@ -1298,7 +1319,8 @@ class TestProperty:
areaunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="AREAUNIT", prefix="MILLI")
volumeunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="VOLUMEUNIT", prefix="MILLI")
timeunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="TIMEUNIT")
ifcopenshell.api.unit.assign_unit(ifc, units=[lengthunit, areaunit, volumeunit, timeunit])
mass_unit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="MASSUNIT", prefix="KILO")
ifcopenshell.api.unit.assign_unit(ifc, units=[lengthunit, areaunit, volumeunit, timeunit, mass_unit])
return ifc