From c7394faf51685f92ab5a4d9d649f7a22e3c93155 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 5 Jun 2023 14:54:41 +0500 Subject: [PATCH] Display units for more pset/qset props #3235 Now current project units displayed for area and volume properties too. https://i.imgur.com/7dgl1pC.png Also added support for imperial units symbols. --- .../blenderbim/bim/module/pset/operator.py | 6 +++++- src/blenderbim/blenderbim/bim/module/pset/ui.py | 2 +- src/blenderbim/blenderbim/bim/prop.py | 12 ++++++++++++ .../ifcopenshell/util/unit.py | 16 ++++++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/pset/operator.py b/src/blenderbim/blenderbim/bim/module/pset/operator.py index 08f890e884..c796a39ecd 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/operator.py +++ b/src/blenderbim/blenderbim/bim/module/pset/operator.py @@ -144,8 +144,12 @@ class EnablePsetEditing(bpy.types.Operator): if prop_template.PrimaryMeasureType in ( "IfcPositiveLengthMeasure", "IfcLengthMeasure", - ) or prop_template.TemplateType in ("Q_LENGTH",): + ) or prop_template.TemplateType == "Q_LENGTH": special_type = "LENGTH" + elif prop_template.PrimaryMeasureType == "IfcAreaMeasure" or prop_template.TemplateType == "Q_AREA": + special_type = "AREA" + elif prop_template.PrimaryMeasureType == "IfcVolumeMeasure" or prop_template.TemplateType == "Q_VOLUME": + special_type = "VOLUME" metadata.special_type = special_type if metadata.data_type == "string": diff --git a/src/blenderbim/blenderbim/bim/module/pset/ui.py b/src/blenderbim/blenderbim/bim/module/pset/ui.py index f677c9158a..cd05f110c3 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/ui.py +++ b/src/blenderbim/blenderbim/bim/module/pset/ui.py @@ -49,7 +49,7 @@ def draw_single_property(prop, layout, copy_operator=None): layout.prop( prop.metadata, value_name, - text=prop.metadata.name, + text=prop.metadata.display_name, ) if prop.metadata.is_uri: op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER") diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index 3aa001bac4..08e2c7d059 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -233,9 +233,21 @@ def set_lenght_value(self, value): self.float_value = value / si_conversion +def get_display_name(self): + name = self.name + if not self.special_type or self.special_type == "LENGTH": + return name + + unit_type = f"{self.special_type}UNIT" + project_unit = ifcopenshell.util.unit.get_project_unit(tool.Ifc.get(), unit_type) + unit_symbol = ifcopenshell.util.unit.get_unit_symbol(project_unit) + return f"{name}, {unit_symbol}" + + class Attribute(PropertyGroup): tooltip = "`Right Click > IFC Description` to read the attribute description and online documentation" name: StringProperty(name="Name") + display_name: StringProperty(name="Display Name", get=get_display_name) description: StringProperty(name="Description") ifc_class: StringProperty(name="Ifc Class") data_type: StringProperty(name="Data Type") diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 25aa251776..e6f436fb8e 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -280,11 +280,20 @@ prefix_symbols = { } unit_symbols = { + # si units "CUBIC_METRE": "m3", "GRAM": "g", "SECOND": "s", "SQUARE_METRE": "m2", "METRE": "m", + # non si units + "cubic inch": "in3", + "cubic foot": "ft3", + "cubic yard": "yd3", + "square inch": "in2", + "square foot": "ft2", + "square yard": "yd2", + "square mile": "mi2", } @@ -442,12 +451,11 @@ def get_symbol_quantity_class(symbol): def get_unit_symbol(unit): + symbol = "" if unit.is_a("IfcSIUnit"): - symbol = "" symbol += prefix_symbols.get(unit.Prefix, "") - symbol += unit_symbols.get(unit.Name.replace("METER", "METRE"), "?") - return symbol - return "?" + symbol += unit_symbols.get(unit.Name.replace("METER", "METRE"), "?") + return symbol def convert_unit(value, from_unit, to_unit):