From 7aa87907d7049a0d4f4a3885f24176dc7b482d42 Mon Sep 17 00:00:00 2001 From: falken10 Date: Mon, 12 May 2025 12:29:00 +0200 Subject: [PATCH] Add local orientation operator and UI toggle for colored dimensions --- .../bonsai/bim/module/geometry/__init__.py | 9 ++++++ .../bonsai/bim/module/geometry/operator.py | 29 +++++++++++++++++++ src/bonsai/bonsai/bim/module/geometry/ui.py | 24 ++++++++++++--- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/__init__.py b/src/bonsai/bonsai/bim/module/geometry/__init__.py index bba979af30..60fad9b4f4 100644 --- a/src/bonsai/bonsai/bim/module/geometry/__init__.py +++ b/src/bonsai/bonsai/bim/module/geometry/__init__.py @@ -77,6 +77,7 @@ classes = ( operator.UpdateItemAttributes, operator.UpdateParametricRepresentation, operator.UpdateRepresentation, + operator.BIM_OT_set_local_orientation, operator.CreateInstance, prop.RepresentationItem, prop.RepresentationItemObject, @@ -134,6 +135,10 @@ def register(): bpy.types.Object.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMObjectGeometryProperties) bpy.types.Scene.BIMGeometryProperties = bpy.props.PointerProperty(type=prop.BIMGeometryProperties) + bpy.types.Scene.show_colored_dimensions = bpy.props.BoolProperty(name="Show Colored Dimensions", description="Show XYZ dimensions in color", default=False, update=ui.BIM_PT_derived_coordinates.update_show_colored_dimensions) + bpy.types.Scene.bonsai_prev_orientation_type = bpy.props.StringProperty(name="Prev Orientation Type") + bpy.types.Scene.bonsai_prev_gizmo_translate = bpy.props.BoolProperty(name="Prev Gizmo Translate") + bpy.types.VIEW3D_MT_object.append(ui.object_menu) bpy.types.OUTLINER_MT_object.append(ui.outliner_menu) bpy.types.VIEW3D_MT_object_context_menu.append(ui.object_menu) @@ -214,3 +219,7 @@ def unregister(): for km, kmi in addon_keymaps: km.keymap_items.remove(kmi) addon_keymaps.clear() + + del bpy.types.Scene.show_colored_dimensions + del bpy.types.Scene._bonsai_prev_orientation_type + del bpy.types.Scene._bonsai_prev_gizmo_translate \ No newline at end of file diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 87e1abeb36..142bcc2cbf 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -3469,3 +3469,32 @@ class CreateInstance(bpy.types.Operator, tool.Ifc.Operator): bpy.ops.bim.hotkey(hotkey="S_A") return {"FINISHED"} + +class BIM_OT_set_local_orientation(bpy.types.Operator): + bl_idname = "bim.set_local_orientation" + bl_label = "Set Local Orientation" + + def execute(self, context): + scene = bpy.context.scene + area_3d = next((area for area in bpy.context.screen.areas if area.type == 'VIEW_3D'), None) + space_3d = next((space for space in area_3d.spaces if space.type == 'VIEW_3D'), None) if area_3d else None + + try: + if context.scene.show_colored_dimensions: + if space_3d: + scene.bonsai_prev_orientation_type = scene.transform_orientation_slots[1].type + scene.bonsai_prev_gizmo_translate = space_3d.show_gizmo_object_translate + scene.transform_orientation_slots[1].type = "LOCAL" + space_3d.show_gizmo_object_translate = True + + # Note: You can't color the text, but you could use custom icons or emojis as a visual cue + else: + if space_3d: + if hasattr(scene, "bonsai_prev_orientation_type"): + scene.transform_orientation_slots[1].type = scene.bonsai_prev_orientation_type + if hasattr(scene, "bonsai_prev_gizmo_translate"): + space_3d.show_gizmo_object_translate = scene.bonsai_prev_gizmo_translate + + except Exception: + self.report({'WARNING'}, "Could not set transform orientation.") + return {'FINISHED'} \ No newline at end of file diff --git a/src/bonsai/bonsai/bim/module/geometry/ui.py b/src/bonsai/bonsai/bim/module/geometry/ui.py index f814cd21d3..dd3e6c9803 100644 --- a/src/bonsai/bonsai/bim/module/geometry/ui.py +++ b/src/bonsai/bonsai/bim/module/geometry/ui.py @@ -515,6 +515,9 @@ class BIM_PT_derived_coordinates(Panel): def poll(cls, context): return context.active_object is not None + def update_show_colored_dimensions(self, context): + bpy.ops.bim.set_local_orientation() + def draw(self, context): if not DerivedCoordinatesData.is_loaded: DerivedCoordinatesData.load() @@ -525,14 +528,27 @@ class BIM_PT_derived_coordinates(Panel): text += "*" row.operator("bim.edit_object_placement", text=text, icon="EXPORT") - row = self.layout.row() + + # --- XYZ Dimensions with checkbox --- + row = self.layout.row(align=True) row.label(text="XYZ Dimensions") + row.prop(context.scene, "show_colored_dimensions", text="Show Locals Gizmo") row = self.layout.row(align=True) row.enabled = False - row.prop(context.active_object, "dimensions", text="X", index=0, slider=True) - row.prop(context.active_object, "dimensions", text="Y", index=1, slider=True) - row.prop(context.active_object, "dimensions", text="Z", index=2, slider=True) + area_3d = next((area for area in context.screen.areas if area.type == 'VIEW_3D'), None) + space_3d = next((space for space in area_3d.spaces if space.type == 'VIEW_3D'), None) + + if context.scene.show_colored_dimensions: + for axis, icon, idx in [("X", 'STRIP_COLOR_01', 0), ("Y", 'STRIP_COLOR_04', 1), ("Z", 'STRIP_COLOR_05', 2)]: + split = row.split(factor=0.30, align=True) + split.label(text=axis, icon=icon) + split.prop(context.active_object, "dimensions", text="", index=idx) + else: + + row.prop(context.active_object, "dimensions", text="X", index=0) + row.prop(context.active_object, "dimensions", text="Y", index=1) + row.prop(context.active_object, "dimensions", text="Z", index=2) row = self.layout.row(align=True) row.label(text="Min Global Z")