mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
You can now view all assigned project units
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
|
||||
class Data:
|
||||
is_loaded = False
|
||||
units = {}
|
||||
@@ -5,16 +9,41 @@ class Data:
|
||||
@classmethod
|
||||
def purge(cls):
|
||||
cls.is_loaded = False
|
||||
cls.unit_assignment = []
|
||||
cls.units = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls, file):
|
||||
if not file:
|
||||
return
|
||||
unit_assignment = file.by_type("IfcUnitAssignment")
|
||||
cls.file = file
|
||||
unit_assignment = cls.file.by_type("IfcUnitAssignment")
|
||||
if not unit_assignment:
|
||||
return
|
||||
for unit in unit_assignment[0].Units:
|
||||
pass
|
||||
# TODO: implement along with UI
|
||||
cls.unit_assignment.append(unit.id())
|
||||
cls.load_unit(unit)
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def load_unit(cls, unit):
|
||||
if unit.is_a("IfcDerivedUnit"):
|
||||
data = unit.get_info()
|
||||
data["Elements"] = [{"Unit": e.Unit.id(), "Exponent": e.Exponent} for e in unit.Elements]
|
||||
for element in unit.Elements:
|
||||
cls.load_unit(element.Unit)
|
||||
cls.units[unit.id()] = data
|
||||
elif unit.is_a("IfcNamedUnit"):
|
||||
data = unit.get_info()
|
||||
if unit.is_a("IfcSIUnit"):
|
||||
data["Dimensions"] = ifcopenshell.util.unit.get_si_dimensions(unit.Name)
|
||||
else:
|
||||
data["Dimensions"] = unit.Dimensions.get_info()
|
||||
if unit.is_a("IfcConversionBasedUnit"):
|
||||
conversion_factor = unit.ConversionFactor.get_info()
|
||||
cls.load_unit(unit.ConversionFactor.UnitComponent)
|
||||
conversion_factor["UnitComponent"] = unit.ConversionFactor.UnitComponent.id()
|
||||
data["ConversionFactor"] = conversion_factor
|
||||
cls.units[unit.id()] = data
|
||||
elif unit.is_a("IfcMonetaryUnit"):
|
||||
cls.units[unit.id()] = unit.get_info()
|
||||
|
||||
Reference in New Issue
Block a user