mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 03:14:23 +00:00
Units UI - match icons in enum with icons in ui list
To build a visual association Example (previously enum had no icons) https://files.catbox.moe/0ks3jj.png https://files.catbox.moe/y1yrv5.png
This commit is contained in:
@@ -61,23 +61,21 @@ class UnitsData:
|
||||
return ifcopenshell.util.unit.get_full_unit_name(unit)
|
||||
|
||||
@classmethod
|
||||
def unit_classes(cls):
|
||||
def unit_classes(cls) -> tool.Blender.BLENDER_ENUM_ITEMS:
|
||||
assert (entity := tool.Ifc.schema().declaration_by_name("IfcNamedUnit").as_entity())
|
||||
declarations = ifcopenshell.util.schema.get_subtypes(entity)
|
||||
version = tool.Ifc.get_schema()
|
||||
classes = sorted([d.name() for d in declarations]) + ["IfcDerivedUnit", "IfcMonetaryUnit"]
|
||||
results = [
|
||||
(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted([d.name() for d in declarations])
|
||||
(
|
||||
c,
|
||||
c,
|
||||
get_entity_doc(version, c).get("description", ""),
|
||||
tool.Unit.get_icon_for_unit_class(c),
|
||||
i,
|
||||
)
|
||||
for i, c in enumerate(classes)
|
||||
]
|
||||
results.extend(
|
||||
[
|
||||
("IfcDerivedUnit", "IfcDerivedUnit", get_entity_doc(version, "IfcDerivedUnit").get("description", "")),
|
||||
(
|
||||
"IfcMonetaryUnit",
|
||||
"IfcMonetaryUnit",
|
||||
get_entity_doc(version, "IfcMonetaryUnit").get("description", ""),
|
||||
),
|
||||
]
|
||||
)
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -120,12 +120,7 @@ class BIM_UL_units(UIList):
|
||||
) -> None:
|
||||
props = tool.Unit.get_unit_props()
|
||||
if item:
|
||||
icon = "MOD_MESHDEFORM"
|
||||
if item.ifc_class == "IfcSIUnit":
|
||||
icon = "SNAP_GRID"
|
||||
elif item.ifc_class == "IfcMonetaryUnit":
|
||||
icon = "COPY_ID"
|
||||
|
||||
icon = tool.Unit.get_icon_for_unit_class(item.ifc_class)
|
||||
row = layout.row(align=True)
|
||||
row.label(text=item.unit_type or "No Type", icon=icon)
|
||||
row.label(text=item.name or "Unnamed")
|
||||
|
||||
@@ -206,3 +206,11 @@ class Unit(bonsai.core.tool.Unit):
|
||||
precision = 1e-5
|
||||
decimal_places = 5
|
||||
return str(round(precision * round(value / precision), decimal_places))
|
||||
|
||||
@classmethod
|
||||
def get_icon_for_unit_class(cls, ifc_class: str) -> str:
|
||||
if ifc_class == "IfcSIUnit":
|
||||
return "SNAP_GRID"
|
||||
elif ifc_class == "IfcMonetaryUnit":
|
||||
return "COPY_ID"
|
||||
return "MOD_MESHDEFORM"
|
||||
|
||||
Reference in New Issue
Block a user