From c73e34eb8c38aed9c9991a75189b3664cc7193f0 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 20 Apr 2023 10:32:36 +0500 Subject: [PATCH] tool.Qto.convert_to_project_units --- .../bim/module/pset/qto_calculator.py | 30 ++----------------- src/blenderbim/blenderbim/tool/qto.py | 29 ++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/pset/qto_calculator.py b/src/blenderbim/blenderbim/bim/module/pset/qto_calculator.py index fcefe47d97..f08a36006e 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/qto_calculator.py +++ b/src/blenderbim/blenderbim/bim/module/pset/qto_calculator.py @@ -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() diff --git a/src/blenderbim/blenderbim/tool/qto.py b/src/blenderbim/blenderbim/tool/qto.py index d3b79cf3ce..762ceb3c5d 100644 --- a/src/blenderbim/blenderbim/tool/qto.py +++ b/src/blenderbim/blenderbim/tool/qto.py @@ -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 = {}