mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Fix #1795. New support for conversion based units with offsets, like fahrenheit.
This commit is contained in:
@@ -5,33 +5,29 @@ import ifcopenshell.util.unit
|
||||
class Usecase:
|
||||
def __init__(self, file, **settings):
|
||||
self.file = file
|
||||
self.settings = {"unit_type": "LENGTHUNIT", "name": "METRE", "prefix": None, "conversion_offset": None}
|
||||
self.settings = {"name": "foot", "conversion_offset": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
if self.settings["unit_type"] == "LENGTHUNIT":
|
||||
dimensional_exponents = self.file.createIfcDimensionalExponents(1, 0, 0, 0, 0, 0, 0)
|
||||
si_unit = self.file.createIfcSIUnit(UnitType=self.settings["unit_type"], Name="METRE")
|
||||
elif self.settings["unit_type"] == "AREAUNIT":
|
||||
dimensional_exponents = self.file.createIfcDimensionalExponents(2, 0, 0, 0, 0, 0, 0)
|
||||
si_unit = self.file.createIfcSIUnit(UnitType=self.settings["unit_type"], Name="SQUARE_METRE")
|
||||
elif self.settings["unit_type"] == "VOLUMEUNIT":
|
||||
dimensional_exponents = self.file.createIfcDimensionalExponents(3, 0, 0, 0, 0, 0, 0)
|
||||
si_unit = self.file.createIfcSIUnit(UnitType=self.settings["unit_type"], Name="CUBIC_METRE")
|
||||
unit_type = ifcopenshell.util.unit.imperial_types.get(self.settings["name"], "USERDEFINED")
|
||||
dimensions = ifcopenshell.util.unit.named_dimensions[unit_type]
|
||||
exponents = self.file.createIfcDimensionalExponents(*dimensions)
|
||||
si_name = ifcopenshell.util.unit.si_type_names[unit_type]
|
||||
si_unit = self.file.createIfcSIUnit(UnitType=unit_type, Name=si_name)
|
||||
|
||||
conversion_real = ifcopenshell.util.unit.si_conversions.get(self.settings["name"], 1)
|
||||
value_component = self.file.create_entity("IfcReal", **{"wrappedValue": conversion_real})
|
||||
conversion_factor = self.file.createIfcMeasureWithUnit(value_component, si_unit)
|
||||
|
||||
if self.settings["conversion_offset"]:
|
||||
return self.file.createIfcConversionBasedUnit(
|
||||
dimensional_exponents,
|
||||
self.settings["unit_type"],
|
||||
self.settings["name"],
|
||||
conversion_factor,
|
||||
self.settings["conversion_offset"],
|
||||
conversion_offset = self.settings["conversion_offset"]
|
||||
if not conversion_offset:
|
||||
conversion_offset = ifcopenshell.util.unit.si_offsets.get(self.settings["name"], 0)
|
||||
|
||||
if conversion_offset:
|
||||
return self.file.createIfcConversionBasedUnitWithOffset(
|
||||
exponents, unit_type, self.settings["name"], conversion_factor, conversion_offset,
|
||||
)
|
||||
return self.file.createIfcConversionBasedUnit(
|
||||
dimensional_exponents, self.settings["unit_type"], self.settings["name"], conversion_factor
|
||||
exponents, unit_type, self.settings["name"], conversion_factor
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user