deprecate geometry.is_edited

in favor of ifc.is_edited
This commit is contained in:
Andrej730
2024-10-22 12:05:07 +05:00
parent 76869b0b02
commit 8372e12f88
7 changed files with 20 additions and 24 deletions
+1 -5
View File
@@ -491,11 +491,7 @@ class BIM_PT_tabs(Panel):
op = row.operator("bim.open_uri", text="", icon="QUESTION") op = row.operator("bim.open_uri", text="", icon="QUESTION")
op.uri = "https://docs.bonsaibim.org/guides/troubleshooting.html#incompatible-blender-features" op.uri = "https://docs.bonsaibim.org/guides/troubleshooting.html#incompatible-blender-features"
if ( if (o := context.active_object) and tool.Ifc.get_entity(o) and tool.Geometry.is_scaled(o):
(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]
):
box = self.layout.box() box = self.layout.box()
box.alert = True box.alert = True
row = box.row(align=True) row = box.row(align=True)
+1 -1
View File
@@ -115,7 +115,7 @@ def switch_representation(
:param is_global: replace mesh data for all users of `obj.data`, not just `obj` :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) representation_id = geometry.get_representation_id(representation)
geometry.run_geometry_update_representation(obj=obj) geometry.run_geometry_update_representation(obj=obj)
if not geometry.does_representation_id_exist(representation_id): if not geometry.does_representation_id_exist(representation_id):
+2 -2
View File
@@ -823,8 +823,8 @@ class Geometry(bonsai.core.tool.Geometry):
return isinstance(data, supported_types) return isinstance(data, supported_types)
@classmethod @classmethod
def is_edited(cls, obj: bpy.types.Object) -> bool: def is_scaled(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 return not all([tool.Cad.is_x(o, 1.0) for o in obj.scale])
@classmethod @classmethod
def is_mapped_representation(cls, representation: ifcopenshell.entity_instance) -> bool: def is_mapped_representation(cls, representation: ifcopenshell.entity_instance) -> bool:
+1 -1
View File
@@ -67,7 +67,7 @@ class Ifc(bonsai.core.tool.Ifc):
@classmethod @classmethod
def is_edited(cls, obj: bpy.types.Object) -> bool: 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 @classmethod
def is_moved(cls, obj: bpy.types.Object) -> bool: def is_moved(cls, obj: bpy.types.Object) -> bool:
+3 -3
View File
@@ -195,7 +195,7 @@ class TestAddRepresentation:
class TestSwitchRepresentation: class TestSwitchRepresentation:
def test_switching_to_a_representation(self, ifc, geometry): 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.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() geometry.reimport_element_representations("obj", "mapped_rep", apply_openings=True).should_be_called()
subject.switch_representation( 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): 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.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.get_representation_id("mapped_rep").should_be_called().will_return("representation_id")
geometry.run_geometry_update_representation(obj="obj").should_be_called() 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): 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.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.get_representation_id("mapped_rep").should_be_called().will_return("representation_id")
geometry.run_geometry_update_representation(obj="obj").should_be_called() geometry.run_geometry_update_representation(obj="obj").should_be_called()
-12
View File
@@ -298,18 +298,6 @@ class TestIsBoxRepresentation(NewFile):
assert subject.is_box_representation(representation) is False 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): class TestIsMappedRepresentation(NewFile):
def test_run(self): def test_run(self):
ifc = ifcopenshell.file() ifc = ifcopenshell.file()
+12
View File
@@ -66,6 +66,18 @@ class TestGetSchema(test.bim.bootstrap.NewFile):
assert subject.get_schema() == "IFC4" 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): class TestIsMoved(test.bim.bootstrap.NewFile):
def test_run(self): def test_run(self):
ifc = ifcopenshell.file() ifc = ifcopenshell.file()