mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
@@ -719,11 +719,12 @@ class Property(Facet):
|
|||||||
unit = ifcopenshell.util.unit.get_property_unit(prop_entity, inst.wrapped_data.file)
|
unit = ifcopenshell.util.unit.get_property_unit(prop_entity, inst.wrapped_data.file)
|
||||||
if unit and getattr(unit, "Name", None):
|
if unit and getattr(unit, "Name", None):
|
||||||
# TODO support unnamed derived units
|
# TODO support unnamed derived units
|
||||||
|
output_prefix = "KILO" if unit.UnitType == "MASSUNIT" else None
|
||||||
props[pset_name][prop_entity.Name] = ifcopenshell.util.unit.convert(
|
props[pset_name][prop_entity.Name] = ifcopenshell.util.unit.convert(
|
||||||
prop_entity.NominalValue.wrappedValue,
|
prop_entity.NominalValue.wrappedValue,
|
||||||
getattr(unit, "Prefix", None),
|
getattr(unit, "Prefix", None),
|
||||||
unit.Name,
|
unit.Name,
|
||||||
None,
|
output_prefix,
|
||||||
ifcopenshell.util.unit.si_type_names[unit.UnitType],
|
ifcopenshell.util.unit.si_type_names[unit.UnitType],
|
||||||
)
|
)
|
||||||
elif prop_entity.is_a("IfcPhysicalSimpleQuantity"):
|
elif prop_entity.is_a("IfcPhysicalSimpleQuantity"):
|
||||||
|
|||||||
@@ -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 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)
|
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):
|
def setup_ifc(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
ifc.createIfcProject()
|
ifc.createIfcProject()
|
||||||
@@ -1298,7 +1319,8 @@ class TestProperty:
|
|||||||
areaunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="AREAUNIT", prefix="MILLI")
|
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")
|
volumeunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="VOLUMEUNIT", prefix="MILLI")
|
||||||
timeunit = ifcopenshell.api.unit.add_si_unit(ifc, unit_type="TIMEUNIT")
|
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
|
return ifc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user