moved to viewport overlays

This commit is contained in:
falken10
2025-05-20 15:52:37 +02:00
committed by Bruno Perdigão
parent 53fc7bce0c
commit 2c16247943
7 changed files with 52 additions and 69 deletions
+1 -1
View File
@@ -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)
+46 -1
View File
@@ -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,
@@ -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)
@@ -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"}
+1 -18
View File
@@ -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"]
@@ -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)
+2
View File
@@ -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")