From 2c16247943945f2c2525d6389827daa52c5d381b Mon Sep 17 00:00:00 2001 From: falken10 Date: Tue, 20 May 2025 15:52:37 +0200 Subject: [PATCH] moved to viewport overlays --- src/bonsai/bonsai/bim/module/geometry/ui.py | 2 +- src/bonsai/bonsai/bim/module/model/prop.py | 47 ++++++++++++++++++- .../bonsai/bim/module/project/__init__.py | 7 --- .../bonsai/bim/module/project/operator.py | 41 +--------------- src/bonsai/bonsai/bim/module/project/prop.py | 19 +------- .../bonsai/bim/module/project/workspace.py | 3 +- src/bonsai/bonsai/bim/ui.py | 2 + 7 files changed, 52 insertions(+), 69 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/ui.py b/src/bonsai/bonsai/bim/module/geometry/ui.py index 7b2a9818df..39f1149e29 100644 --- a/src/bonsai/bonsai/bim/module/geometry/ui.py +++ b/src/bonsai/bonsai/bim/module/geometry/ui.py @@ -533,7 +533,7 @@ class BIM_PT_derived_coordinates(Panel): 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 bpy.context.scene.MeasureToolSettings.measurement_type == "XYZ_DIMENSIONS": + if bpy.context.scene.BIMModelProperties.measure_xyz_dimensions: for axis, icon, idx in [("X", "STRIP_COLOR_01", 0), ("Y", "STRIP_COLOR_04", 1), ("Z", "STRIP_COLOR_05", 2)]: row.label(text="", icon=icon) row.prop(context.active_object, "dimensions", text=axis, index=idx) diff --git a/src/bonsai/bonsai/bim/module/model/prop.py b/src/bonsai/bonsai/bim/module/model/prop.py index 6c33a9b419..101d51133f 100644 --- a/src/bonsai/bonsai/bim/module/model/prop.py +++ b/src/bonsai/bonsai/bim/module/model/prop.py @@ -25,7 +25,7 @@ from bonsai.bim.prop import ObjProperty from bonsai.bim.module.model.data import AuthoringData from bpy.types import PropertyGroup, NodeTree from math import pi, radians -from bonsai.bim.module.model.decorator import WallAxisDecorator, SlabDirectionDecorator +from bonsai.bim.module.model.decorator import WallAxisDecorator, SlabDirectionDecorator, BoundingBoxDecorator from bonsai.bim.module.model.door import update_door_modifier_bmesh from bonsai.bim.module.model.window import update_window_modifier_bmesh from bonsai.bim.module.drawing.decoration import CutDecorator @@ -114,6 +114,38 @@ def update_slab_direction_decorator(self: "BIMModelProperties", context: bpy.typ SlabDirectionDecorator.uninstall() +def update_measure_xyz(self: "BIMModelProperties", context: bpy.types.Context) -> None: + 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 area_3d else None + scene = context.scene + + if self.measure_xyz_dimensions: + BoundingBoxDecorator.install(context) + # Save previous state if not already saved + if not self.prev_transform_orientation_slot_type: + self.prev_transform_orientation_slot_type = scene.transform_orientation_slots[1].type + if not self.prev_show_gizmo_object_translate and space_3d: + self.prev_show_gizmo_object_translate = space_3d.show_gizmo_object_translate + # Set new state + if space_3d: + if len(context.selected_objects) == 1: + scene.transform_orientation_slots[1].type = "LOCAL" + else: + scene.transform_orientation_slots[1].type = "GLOBAL" + space_3d.show_gizmo_object_translate = True + else: + BoundingBoxDecorator.uninstall() + # Restore previous state + if space_3d: + prev_orientation = self.prev_transform_orientation_slot_type + if prev_orientation: + scene.transform_orientation_slots[1].type = prev_orientation + self.prev_transform_orientation_slot_type = "" + prev_gizmo = self.prev_show_gizmo_object_translate + if prev_gizmo is not None: + space_3d.show_gizmo_object_translate = prev_gizmo + self.prev_show_gizmo_object_translate = False + def update_cut_decorator(self: "BIMModelProperties", context: bpy.types.Context) -> None: if self.show_cut_decorator: CutDecorator.install(bpy.context) @@ -248,6 +280,19 @@ class BIMModelProperties(PropertyGroup): default=False, update=update_slab_direction_decorator, ) + + prev_transform_orientation_slot_type: bpy.props.StringProperty( + name="Previous Gizmo Orientation Type" + ) + prev_show_gizmo_object_translate: bpy.props.BoolProperty( + name="Previous Gizmo Translate" + ) + + measure_xyz_dimensions: bpy.props.BoolProperty( + name="Measure XYZ Dimensions", + default=False, + update=update_measure_xyz + ) show_cut_decorator: bpy.props.BoolProperty( name="Show Cut Decorator", default=True, diff --git a/src/bonsai/bonsai/bim/module/project/__init__.py b/src/bonsai/bonsai/bim/module/project/__init__.py index de8d1060ed..81bf9e9ec7 100644 --- a/src/bonsai/bonsai/bim/module/project/__init__.py +++ b/src/bonsai/bonsai/bim/module/project/__init__.py @@ -49,7 +49,6 @@ classes = ( operator.LoadProjectElements, operator.MeasureTool, operator.MeasureFaceAreaTool, - operator.MeasureXYZDimensionsTool, operator.ClearMeasurement, operator.NewProject, operator.QueryLinkedElement, @@ -101,10 +100,6 @@ def register(): bpy.types.TOPBAR_MT_file_import.append(ui.file_import_menu) bpy.types.TOPBAR_MT_file.prepend(ui.file_menu) bpy.types.TOPBAR_MT_file_context_menu.prepend(ui.file_menu) - bpy.types.Scene.prev_transform_orientation_slot_type = bpy.props.StringProperty( - name="Previous Gizmo Orientation Type" - ) - bpy.types.Scene.prev_show_gizmo_object_translate = bpy.props.BoolProperty(name="Previous Gizmo Translate") wm = bpy.context.window_manager if wm.keyconfigs.addon: km = wm.keyconfigs.addon.keymaps.get("Window") @@ -125,8 +120,6 @@ def unregister(): bpy.utils.unregister_tool(workspace.ExploreTool) del bpy.types.Scene.BIMProjectProperties del bpy.types.Scene.MeasureToolSettings - del bpy.types.Scene.prev_transform_orientation_slot_type - del bpy.types.Scene.prev_show_gizmo_object_translate bpy.app.handlers.load_post.remove(decorator.toggle_decorations_on_load) bpy.types.TOPBAR_MT_file.remove(ui.file_menu) bpy.types.TOPBAR_MT_file_context_menu.remove(ui.file_menu) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index ef10154572..ffd03b04cf 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -2648,6 +2648,7 @@ class MeasureTool(bpy.types.Operator, PolylineOperator): and event.type in {"RET", "NUMPAD_ENTER", "RIGHTMOUSE"} ) or single_mode: context.workspace.status_text_set(text=None) + self.tool_state.plane_method = None PolylineDecorator.uninstall() tool.Polyline.move_polyline_to_measure(context, self.input_ui) tool.Polyline.clear_polyline() @@ -2800,43 +2801,3 @@ class ClearMeasurement(bpy.types.Operator): MeasureDecorator.uninstall() tool.Blender.update_viewport() return {"FINISHED"} - -from bonsai.bim.module.model.decorator import BoundingBoxDecorator - -class MeasureXYZDimensionsTool(bpy.types.Operator): - bl_idname = "bim.measure_xyz_dimensions_tool" - bl_label = "Show bounding box dimensions" - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - scene = context.scene - 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 area_3d else None - - if scene.MeasureToolSettings.measurement_type == "XYZ_DIMENSIONS": - BoundingBoxDecorator.install(context) - # Save previous state if not already saved - if not scene.get("prev_transform_orientation_slot_type", None): - scene["prev_transform_orientation_slot_type"] = scene.transform_orientation_slots[1].type - if not scene.get("prev_show_gizmo_object_translate", None) and space_3d: - scene["prev_show_gizmo_object_translate"] = space_3d.show_gizmo_object_translate - # Set new state - if space_3d: - if len(context.selected_objects) == 1: - scene.transform_orientation_slots[1].type = "LOCAL" - else: - scene.transform_orientation_slots[1].type = "GLOBAL" - space_3d.show_gizmo_object_translate = True - else: - BoundingBoxDecorator.uninstall() - # Restore previous state - if space_3d: - prev_orientation = scene.get("prev_transform_orientation_slot_type", None) - if prev_orientation: - scene.transform_orientation_slots[1].type = prev_orientation - scene["prev_transform_orientation_slot_type"] = "" - prev_gizmo = scene.get("prev_show_gizmo_object_translate", None) - if prev_gizmo is not None: - space_3d.show_gizmo_object_translate = prev_gizmo - scene["prev_show_gizmo_object_translate"] = None - return {"FINISHED"} \ No newline at end of file diff --git a/src/bonsai/bonsai/bim/module/project/prop.py b/src/bonsai/bonsai/bim/module/project/prop.py index b1ee2ccfb5..68f70a87d7 100644 --- a/src/bonsai/bonsai/bim/module/project/prop.py +++ b/src/bonsai/bonsai/bim/module/project/prop.py @@ -507,32 +507,15 @@ class BIMProjectProperties(PropertyGroup): yield link -prev_measurement_type = "" - - -def measurement_type_update(self, context): - global prev_measurement_type - # We enable/disable the measure_xyz_dimensions_tool depending on the selected type - if prev_measurement_type != self.measurement_type: - bpy.ops.bim.measure_xyz_dimensions_tool() - else: - # toggle to default - self.measurement_type = "POLYLINE" - prev_measurement_type = self.measurement_type - - class MeasureToolSettings(PropertyGroup): measurement_type_items = [ ("SINGLE", "SINGLE", "Single", "FIXED_SIZE", 1), ("POLYLINE", "POLYLINE", "Polyline", "DRIVER_ROTATIONAL_DIFFERENCE", 2), ("POLY_AREA", "POLY_AREA", "Poyline Area", "OUTLINER_DATA_LIGHTPROBE", 3), ("FACE_AREA", "FACE_AREA", "Face Area", "FACESEL", 4), - ("XYZ_DIMENSIONS", "XYZ_DIMENSIONS", "XYZ Dimensions", "ORIENTATION_LOCAL", 5), ] - measurement_type: bpy.props.EnumProperty( - items=measurement_type_items, default="POLYLINE", update=measurement_type_update - ) + measurement_type: bpy.props.EnumProperty(items=measurement_type_items, default="POLYLINE") if TYPE_CHECKING: measurement_type: Literal["SINGLE", "POLYLINE", "AREA"] diff --git a/src/bonsai/bonsai/bim/module/project/workspace.py b/src/bonsai/bonsai/bim/module/project/workspace.py index 29048ef726..b948666e7b 100644 --- a/src/bonsai/bonsai/bim/module/project/workspace.py +++ b/src/bonsai/bonsai/bim/module/project/workspace.py @@ -108,7 +108,6 @@ class ExploreHotkey(bpy.types.Operator): measure_type = bpy.context.scene.MeasureToolSettings.measurement_type if measure_type == "FACE_AREA": bpy.ops.bim.measure_face_area_tool("INVOKE_DEFAULT") - elif measure_type == "XYZ_DIMENSIONS": - pass + else: bpy.ops.bim.measure_tool("INVOKE_DEFAULT", measure_type=measure_type) diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index 1bd9b29422..9160c9e01e 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -1334,6 +1334,8 @@ class BIM_PT_decorators_overlay(Panel): row = col.row(align=True) row.prop(model_props, "show_slab_direction", text="Slab Direction") row = col.row(align=True) + row.prop(model_props, "measure_xyz_dimensions", text="Bounding Box Dimensions") + row = col.row(align=True) row.prop(model_props, "show_cut_decorator", text="Cut Decorator") row.prop(model_props, "show_cut_decorator_fill", text="Fill Cut Decorator")