From 4040c31583e3509ebf38fcfdd2e43ea74e00a95e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 24 Oct 2024 17:00:38 +0500 Subject: [PATCH] Lock scale for objects with openings Currently there is an UX problem that it's not clear for users when it's possible to use scale or not. We definitely won't be able to safely apply scales for objects with openings, so will try to lock them from the start. --- src/bonsai/bonsai/bim/import_ifc.py | 2 ++ src/bonsai/bonsai/bim/module/void/operator.py | 3 +++ src/bonsai/bonsai/tool/geometry.py | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index bb57ec47a5..4a0dcc4dfc 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -811,6 +811,8 @@ class IfcImporter: obj = bpy.data.objects.new(tool.Loader.get_name(element), mesh) self.link_element(element, obj) + if getattr(element, "HasOpenings", None): + tool.Geometry.lock_scale(obj) if shape: # We use numpy here because Blender mathutils.Matrix is not accurate enough diff --git a/src/bonsai/bonsai/bim/module/void/operator.py b/src/bonsai/bonsai/bim/module/void/operator.py index b9b3534104..498448562a 100644 --- a/src/bonsai/bonsai/bim/module/void/operator.py +++ b/src/bonsai/bonsai/bim/module/void/operator.py @@ -130,6 +130,7 @@ class AddOpening(bpy.types.Operator, tool.Ifc.Operator): # therefore bim.update_representaiton wouldn't work either way. should_sync_changes_first=False, ) + tool.Geometry.lock_scale(voided_obj) if not has_visible_openings: tool.Ifc.unlink(element=element2) @@ -173,6 +174,8 @@ class RemoveOpening(bpy.types.Operator, tool.Ifc.Operator): is_global=True, should_sync_changes_first=False, ) + if building_obj and not getattr(element, "HasOpenings", None): + tool.Geometry.unlock_scale(building_obj) tool.Geometry.clear_cache(element) return {"FINISHED"} diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 0e40bf3238..aee9f154fd 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -136,6 +136,14 @@ class Geometry(bonsai.core.tool.Geometry): obj.lock_rotations_4d = False obj.lock_scale = (False, False, False) + @classmethod + def lock_scale(cls, obj: bpy.types.Object) -> None: + obj.lock_scale = (True, True, True) + + @classmethod + def unlock_scale(cls, obj: bpy.types.Object) -> None: + obj.lock_scale = (False, False, False) + @classmethod def delete_ifc_item(cls, obj: bpy.types.Object) -> None: props = bpy.context.scene.BIMGeometryProperties