mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 21:38:12 +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)
|
return ifcopenshell.util.unit.get_full_unit_name(unit)
|
||||||
|
|
||||||
@classmethod
|
@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())
|
assert (entity := tool.Ifc.schema().declaration_by_name("IfcNamedUnit").as_entity())
|
||||||
declarations = ifcopenshell.util.schema.get_subtypes(entity)
|
declarations = ifcopenshell.util.schema.get_subtypes(entity)
|
||||||
version = tool.Ifc.get_schema()
|
version = tool.Ifc.get_schema()
|
||||||
|
classes = sorted([d.name() for d in declarations]) + ["IfcDerivedUnit", "IfcMonetaryUnit"]
|
||||||
results = [
|
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
|
return results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -120,12 +120,7 @@ class BIM_UL_units(UIList):
|
|||||||
) -> None:
|
) -> None:
|
||||||
props = tool.Unit.get_unit_props()
|
props = tool.Unit.get_unit_props()
|
||||||
if item:
|
if item:
|
||||||
icon = "MOD_MESHDEFORM"
|
icon = tool.Unit.get_icon_for_unit_class(item.ifc_class)
|
||||||
if item.ifc_class == "IfcSIUnit":
|
|
||||||
icon = "SNAP_GRID"
|
|
||||||
elif item.ifc_class == "IfcMonetaryUnit":
|
|
||||||
icon = "COPY_ID"
|
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text=item.unit_type or "No Type", icon=icon)
|
row.label(text=item.unit_type or "No Type", icon=icon)
|
||||||
row.label(text=item.name or "Unnamed")
|
row.label(text=item.name or "Unnamed")
|
||||||
|
|||||||
@@ -206,3 +206,11 @@ class Unit(bonsai.core.tool.Unit):
|
|||||||
precision = 1e-5
|
precision = 1e-5
|
||||||
decimal_places = 5
|
decimal_places = 5
|
||||||
return str(round(precision * round(value / precision), decimal_places))
|
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