tool.Qto.convert_to_project_units

This commit is contained in:
Andrej730
2023-04-20 10:32:36 +05:00
parent 4beb7780f8
commit f160516772
2 changed files with 31 additions and 28 deletions
@@ -45,34 +45,8 @@ class QtoCalculator:
else:
self.mapping_dict[key][item] = None
def convert_to_project_units(self, value, qto_name, quantity_name):
ifc_file = tool.Ifc.get()
quantity_to_unit_types = {
"Q_LENGTH": ("LENGTHUNIT", "METRE"),
"Q_AREA": ("AREAUNIT", "SQUARE_METRE"),
"Q_VOLUME": ("VOLUMEUNIT", "CUBIC_METRE"),
}
qt = blenderbim.bim.schema.ifc.psetqto.get_by_name(qto_name)
quantity_type = next(q.TemplateType for q in qt.HasPropertyTemplates if q.Name == quantity_name)
unit_type = quantity_to_unit_types.get(quantity_type, None)
if not unit_type:
return
unit_type, base_unit = unit_type
project_unit = ifcopenshell.util.unit.get_project_unit(ifc_file, unit_type)
if not project_unit:
return
value = ifcopenshell.util.unit.convert(
value,
from_prefix=None,
from_unit=base_unit,
to_prefix=getattr(project_unit, "Prefix", None),
to_unit=project_unit.Name,
)
return value
def calculate_quantity(self, qto_name, quantity_name, obj):
"""calculates the value of the quantity in the project units"""
string = "self.mapping_dict[qto_name][quantity_name](obj"
if isinstance(mapper[qto_name][quantity_name], dict):
args = mapper[qto_name][quantity_name]["args"]
@@ -82,7 +56,7 @@ class QtoCalculator:
string += ")"
value = eval(string)
return self.convert_to_project_units(value, qto_name, quantity_name) or value
return tool.Qto.convert_to_project_units(value, qto_name, quantity_name) or value
def guess_quantity(self, prop_name, alternative_prop_names, obj):
prop_name = prop_name.lower()
+29
View File
@@ -97,6 +97,35 @@ class Qto(blenderbim.core.tool.Qto):
def has_calculator(cls, qto_name, quantity_name):
return bool(mapper.get(qto_name, {}).get(quantity_name, None))
@classmethod
def convert_to_project_units(cls, value, qto_name, quantity_name):
ifc_file = tool.Ifc.get()
quantity_to_unit_types = {
"Q_LENGTH": ("LENGTHUNIT", "METRE"),
"Q_AREA": ("AREAUNIT", "SQUARE_METRE"),
"Q_VOLUME": ("VOLUMEUNIT", "CUBIC_METRE"),
}
qt = blenderbim.bim.schema.ifc.psetqto.get_by_name(qto_name)
quantity_type = next(q.TemplateType for q in qt.HasPropertyTemplates if q.Name == quantity_name)
unit_type = quantity_to_unit_types.get(quantity_type, None)
if not unit_type:
return
unit_type, base_unit = unit_type
project_unit = ifcopenshell.util.unit.get_project_unit(ifc_file, unit_type)
if not project_unit:
return
value = ifcopenshell.util.unit.convert(
value,
from_prefix=None,
from_unit=base_unit,
to_prefix=getattr(project_unit, "Prefix", None),
to_unit=project_unit.Name,
)
return value
@classmethod
def get_guessed_quantities(cls, obj, pset_qto_properties):
calculated_quantities = {}