From 8372e12f88fb07ea9891bb63d2e40044ef0d3cf4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 22 Oct 2024 12:05:07 +0500 Subject: [PATCH] deprecate geometry.is_edited in favor of ifc.is_edited --- src/bonsai/bonsai/bim/ui.py | 6 +----- src/bonsai/bonsai/core/geometry.py | 2 +- src/bonsai/bonsai/tool/geometry.py | 4 ++-- src/bonsai/bonsai/tool/ifc.py | 2 +- src/bonsai/test/core/test_geometry.py | 6 +++--- src/bonsai/test/tool/test_geometry.py | 12 ------------ src/bonsai/test/tool/test_ifc.py | 12 ++++++++++++ 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index d8b157c368..e25c9e2a69 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -491,11 +491,7 @@ class BIM_PT_tabs(Panel): op = row.operator("bim.open_uri", text="", icon="QUESTION") op.uri = "https://docs.bonsaibim.org/guides/troubleshooting.html#incompatible-blender-features" - if ( - (o := context.active_object) - and tool.Ifc.get_entity(o) - and [round(x, 4) for x in list(o.matrix_world.to_scale())] != [1, 1, 1] - ): + if (o := context.active_object) and tool.Ifc.get_entity(o) and tool.Geometry.is_scaled(o): box = self.layout.box() box.alert = True row = box.row(align=True) diff --git a/src/bonsai/bonsai/core/geometry.py b/src/bonsai/bonsai/core/geometry.py index d3206a8002..1c06e4e3dd 100644 --- a/src/bonsai/bonsai/core/geometry.py +++ b/src/bonsai/bonsai/core/geometry.py @@ -115,7 +115,7 @@ def switch_representation( :param is_global: replace mesh data for all users of `obj.data`, not just `obj` """ - if should_sync_changes_first and geometry.is_edited(obj) and not geometry.is_box_representation(representation): + if should_sync_changes_first and ifc.is_edited(obj) and not geometry.is_box_representation(representation): representation_id = geometry.get_representation_id(representation) geometry.run_geometry_update_representation(obj=obj) if not geometry.does_representation_id_exist(representation_id): diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 1598da9215..16ad8e006c 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -823,8 +823,8 @@ class Geometry(bonsai.core.tool.Geometry): return isinstance(data, supported_types) @classmethod - def is_edited(cls, obj: bpy.types.Object) -> bool: - return not all([tool.Cad.is_x(o, 1.0) for o in obj.scale]) or obj in IfcStore.edited_objs + def is_scaled(cls, obj: bpy.types.Object) -> bool: + return not all([tool.Cad.is_x(o, 1.0) for o in obj.scale]) @classmethod def is_mapped_representation(cls, representation: ifcopenshell.entity_instance) -> bool: diff --git a/src/bonsai/bonsai/tool/ifc.py b/src/bonsai/bonsai/tool/ifc.py index 10fb71cf3b..b4fc70abb1 100644 --- a/src/bonsai/bonsai/tool/ifc.py +++ b/src/bonsai/bonsai/tool/ifc.py @@ -67,7 +67,7 @@ class Ifc(bonsai.core.tool.Ifc): @classmethod def is_edited(cls, obj: bpy.types.Object) -> bool: - return list(obj.scale) != [1.0, 1.0, 1.0] or obj in IfcStore.edited_objs + return tool.Geometry.is_scaled(obj) or obj in IfcStore.edited_objs @classmethod def is_moved(cls, obj: bpy.types.Object) -> bool: diff --git a/src/bonsai/test/core/test_geometry.py b/src/bonsai/test/core/test_geometry.py index 66e5034f24..c2c35c2fe3 100644 --- a/src/bonsai/test/core/test_geometry.py +++ b/src/bonsai/test/core/test_geometry.py @@ -195,7 +195,7 @@ class TestAddRepresentation: class TestSwitchRepresentation: def test_switching_to_a_representation(self, ifc, geometry): - geometry.is_edited("obj").should_be_called().will_return(False) + ifc.is_edited("obj").should_be_called().will_return(False) geometry.get_object_data("obj").should_be_called().will_return("current_obj_data") geometry.reimport_element_representations("obj", "mapped_rep", apply_openings=True).should_be_called() subject.switch_representation( @@ -210,7 +210,7 @@ class TestSwitchRepresentation: ) def test_updating_a_representation_if_the_blender_object_has_been_edited_prior_to_switching(self, ifc, geometry): - geometry.is_edited("obj").should_be_called().will_return(True) + ifc.is_edited("obj").should_be_called().will_return(True) geometry.is_box_representation("mapped_rep").should_be_called().will_return(False) geometry.get_representation_id("mapped_rep").should_be_called().will_return("representation_id") geometry.run_geometry_update_representation(obj="obj").should_be_called() @@ -228,7 +228,7 @@ class TestSwitchRepresentation: ) def test_not_switching_if_an_updated_representation_is_the_same_one_we_were_going_to_switch_to(self, geometry): - geometry.is_edited("obj").should_be_called().will_return(True) + ifc.is_edited("obj").should_be_called().will_return(True) geometry.is_box_representation("mapped_rep").should_be_called().will_return(False) geometry.get_representation_id("mapped_rep").should_be_called().will_return("representation_id") geometry.run_geometry_update_representation(obj="obj").should_be_called() diff --git a/src/bonsai/test/tool/test_geometry.py b/src/bonsai/test/tool/test_geometry.py index 87f221d1e3..93bb6f17f7 100644 --- a/src/bonsai/test/tool/test_geometry.py +++ b/src/bonsai/test/tool/test_geometry.py @@ -298,18 +298,6 @@ class TestIsBoxRepresentation(NewFile): assert subject.is_box_representation(representation) is False -class TestIsEdited(NewFile): - def test_run(self): - obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh")) - assert subject.is_edited(obj) is False - obj.scale[0] = 2 - assert subject.is_edited(obj) is True - obj.scale[0] = 1 - assert subject.is_edited(obj) is False - tool.Ifc.edit(obj) - assert subject.is_edited(obj) is True - - class TestIsMappedRepresentation(NewFile): def test_run(self): ifc = ifcopenshell.file() diff --git a/src/bonsai/test/tool/test_ifc.py b/src/bonsai/test/tool/test_ifc.py index c68695815a..e291e2fa28 100644 --- a/src/bonsai/test/tool/test_ifc.py +++ b/src/bonsai/test/tool/test_ifc.py @@ -66,6 +66,18 @@ class TestGetSchema(test.bim.bootstrap.NewFile): assert subject.get_schema() == "IFC4" +class TestIsEdited(test.bim.bootstrap.NewFile): + def test_run(self): + obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh")) + assert subject.is_edited(obj) is False + obj.scale[0] = 2 + assert subject.is_edited(obj) is True + obj.scale[0] = 1 + assert subject.is_edited(obj) is False + tool.Ifc.edit(obj) + assert subject.is_edited(obj) is True + + class TestIsMoved(test.bim.bootstrap.NewFile): def test_run(self): ifc = ifcopenshell.file()