diff --git a/src/bonsai/bonsai/bim/module/geometry/ui.py b/src/bonsai/bonsai/bim/module/geometry/ui.py index 39f1149e29..b5897615b4 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.BIMModelProperties.measure_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/decorator.py b/src/bonsai/bonsai/bim/module/model/decorator.py index 44ed83bf7b..3a65fbc930 100644 --- a/src/bonsai/bonsai/bim/module/model/decorator.py +++ b/src/bonsai/bonsai/bim/module/model/decorator.py @@ -1124,6 +1124,7 @@ class FaceAreaDecorator: self.draw_batch("LINES", data["verts"], decorator_color, data["edges"]) self.draw_batch("TRIS", data["verts"], transparent_color(decorator_color, alpha=0.5), data["tris"]) + class BoundingBoxDecorator: is_installed = False handlers = [] @@ -1143,7 +1144,9 @@ class BoundingBoxDecorator: cls.uninstall() handler = cls() cls.handlers.append( - bpy.types.SpaceView3D.draw_handler_add(handler.draw_bounding_box_wire_cube, (context,), "WINDOW", "POST_VIEW") + bpy.types.SpaceView3D.draw_handler_add( + handler.draw_bounding_box_wire_cube, (context,), "WINDOW", "POST_VIEW" + ) ) cls.handlers.append( bpy.types.SpaceView3D.draw_handler_add(handler.draw_dimension_text, (context,), "WINDOW", "POST_PIXEL") @@ -1163,6 +1166,7 @@ class BoundingBoxDecorator: @staticmethod def get_combined_bounding_box_corners(objects): import mathutils + if not objects: return None, None, None if len(objects) == 1: @@ -1190,9 +1194,18 @@ class BoundingBoxDecorator: mathutils.Vector((max_corner.x, max_corner.y, min_corner.z)), ] edges = [ - (0, 1, "Z"), (1, 2, "Y"), (2, 3, "Z"), (3, 0, "Y"), - (4, 5, "Z"), (5, 6, "Y"), (6, 7, "Z"), (7, 4, "Y"), - (0, 4, "X"), (1, 5, "X"), (2, 6, "X"), (3, 7, "X"), + (0, 1, "Z"), + (1, 2, "Y"), + (2, 3, "Z"), + (3, 0, "Y"), + (4, 5, "Z"), + (5, 6, "Y"), + (6, 7, "Z"), + (7, 4, "Y"), + (0, 4, "X"), + (1, 5, "X"), + (2, 6, "X"), + (3, 7, "X"), ] axis_colors = { "X": (0.956, 0.282, 0.322, 1), @@ -1204,6 +1217,7 @@ class BoundingBoxDecorator: @staticmethod def find_closest_trihedron(corners, edges, region, rv3d): from bpy_extras.view3d_utils import location_3d_to_region_2d + min_y = float("inf") best_origin = None for idx, corner in enumerate(corners): @@ -1243,7 +1257,7 @@ class BoundingBoxDecorator: verts = [top_left, bottom_left, top_right, bottom_right] gpu.state.blend_set("ALPHA") self.draw_batch("TRIS", verts, color, [(0, 1, 2), (1, 2, 3)]) - + def draw_bounding_box_wire_cube(self, context): import gpu from gpu_extras.batch import batch_for_shader @@ -1281,7 +1295,6 @@ class BoundingBoxDecorator: self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height)) self.shader = gpu.shader.from_builtin("UNIFORM_COLOR") - selected_objects = [obj for obj in bpy.context.selected_objects if hasattr(obj, "bound_box")] if not selected_objects: return @@ -1323,4 +1336,4 @@ class BoundingBoxDecorator: text_length = blf.dimensions(font_id, value_str) self.draw_text_background(context, screen_co, text_length) blf.draw(font_id, value_str) - blf.disable(font_id, blf.SHADOW) \ No newline at end of file + blf.disable(font_id, blf.SHADOW) diff --git a/src/bonsai/bonsai/bim/module/model/prop.py b/src/bonsai/bonsai/bim/module/model/prop.py index 101d51133f..d31c74ac4f 100644 --- a/src/bonsai/bonsai/bim/module/model/prop.py +++ b/src/bonsai/bonsai/bim/module/model/prop.py @@ -118,7 +118,7 @@ def update_measure_xyz(self: "BIMModelProperties", context: bpy.types.Context) - 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 @@ -145,6 +145,8 @@ def update_measure_xyz(self: "BIMModelProperties", context: bpy.types.Context) - 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: @@ -281,12 +283,8 @@ class BIMModelProperties(PropertyGroup): 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" - ) + 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", diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index ffd03b04cf..5542ff24d4 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -2787,6 +2787,7 @@ class MeasureFaceAreaTool(bpy.types.Operator, PolylineOperator): FaceAreaDecorator.install(context) return {"RUNNING_MODAL"} + class ClearMeasurement(bpy.types.Operator): bl_idname = "bim.clear_measurement" bl_label = "Clear measurement from the screen"