mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
Fix bug where existing meshes were not deleted when switching representations.
This commit is contained in:
@@ -77,14 +77,20 @@ def switch_representation(
|
|||||||
geometry, obj=None, representation=None, should_reload=True, enable_dynamic_voids=True, is_global=True
|
geometry, obj=None, representation=None, should_reload=True, enable_dynamic_voids=True, is_global=True
|
||||||
):
|
):
|
||||||
representation = geometry.resolve_mapped_representation(representation)
|
representation = geometry.resolve_mapped_representation(representation)
|
||||||
data = geometry.get_representation_data(representation)
|
existing_data = geometry.get_representation_data(representation)
|
||||||
|
|
||||||
if not data or should_reload:
|
if should_reload or not existing_data:
|
||||||
data = geometry.import_representation(obj, representation, enable_dynamic_voids=enable_dynamic_voids)
|
data = geometry.import_representation(obj, representation, enable_dynamic_voids=enable_dynamic_voids)
|
||||||
geometry.rename_object(data, geometry.get_representation_name(representation))
|
geometry.rename_object(data, geometry.get_representation_name(representation))
|
||||||
geometry.link(representation, data)
|
geometry.link(representation, data)
|
||||||
|
else:
|
||||||
|
data = existing_data
|
||||||
|
|
||||||
geometry.change_object_data(obj, data, is_global=is_global)
|
geometry.change_object_data(obj, data, is_global=is_global)
|
||||||
|
|
||||||
|
if should_reload and existing_data:
|
||||||
|
geometry.delete_data(existing_data)
|
||||||
|
|
||||||
geometry.clear_modifiers(obj)
|
geometry.clear_modifiers(obj)
|
||||||
|
|
||||||
if enable_dynamic_voids and geometry.is_body_representation(representation):
|
if enable_dynamic_voids and geometry.is_body_representation(representation):
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class Geometry:
|
|||||||
def change_object_data(cls, obj, data, is_global=False): pass
|
def change_object_data(cls, obj, data, is_global=False): pass
|
||||||
def clear_modifiers(cls, obj): pass
|
def clear_modifiers(cls, obj): pass
|
||||||
def create_dynamic_voids(cls, obj): pass
|
def create_dynamic_voids(cls, obj): pass
|
||||||
|
def delete_data(cls, data): pass
|
||||||
def does_object_have_mesh_with_faces(cls, obj): pass
|
def does_object_have_mesh_with_faces(cls, obj): pass
|
||||||
def duplicate_object_data(cls, obj): pass
|
def duplicate_object_data(cls, obj): pass
|
||||||
def get_cartesian_point_coordinate_offset(cls, obj): pass
|
def get_cartesian_point_coordinate_offset(cls, obj): pass
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
modifier.solver = "EXACT"
|
modifier.solver = "EXACT"
|
||||||
modifier.use_self = True
|
modifier.use_self = True
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_data(cls, data):
|
||||||
|
bpy.data.meshes.remove(data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def does_object_have_mesh_with_faces(cls, obj):
|
def does_object_have_mesh_with_faces(cls, obj):
|
||||||
return bool(isinstance(obj.data, bpy.types.Mesh) and len(obj.data.polygons))
|
return bool(isinstance(obj.data, bpy.types.Mesh) and len(obj.data.polygons))
|
||||||
|
|||||||
@@ -179,9 +179,9 @@ class TestAddRepresentation:
|
|||||||
|
|
||||||
|
|
||||||
class TestSwitchRepresentation:
|
class TestSwitchRepresentation:
|
||||||
def test_switching_to_a_freshly_reloaded_representation(self, geometry):
|
def test_switching_to_a_freshly_loaded_representation(self, geometry):
|
||||||
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
||||||
geometry.get_representation_data("representation").should_be_called().will_return("data")
|
geometry.get_representation_data("representation").should_be_called().will_return(None)
|
||||||
geometry.import_representation(
|
geometry.import_representation(
|
||||||
"obj", "representation", enable_dynamic_voids=True
|
"obj", "representation", enable_dynamic_voids=True
|
||||||
).should_be_called().will_return("new_data")
|
).should_be_called().will_return("new_data")
|
||||||
@@ -201,6 +201,29 @@ class TestSwitchRepresentation:
|
|||||||
is_global=True,
|
is_global=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_switching_to_a_reloaded_representation_and_deleting_the_existing_data(self, geometry):
|
||||||
|
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
||||||
|
geometry.get_representation_data("representation").should_be_called().will_return("existing_data")
|
||||||
|
geometry.import_representation(
|
||||||
|
"obj", "representation", enable_dynamic_voids=True
|
||||||
|
).should_be_called().will_return("new_data")
|
||||||
|
geometry.get_representation_name("representation").should_be_called().will_return("name")
|
||||||
|
geometry.rename_object("new_data", "name").should_be_called()
|
||||||
|
geometry.link("representation", "new_data").should_be_called()
|
||||||
|
geometry.change_object_data("obj", "new_data", is_global=True).should_be_called()
|
||||||
|
geometry.delete_data("existing_data").should_be_called()
|
||||||
|
geometry.clear_modifiers("obj").should_be_called()
|
||||||
|
geometry.is_body_representation("representation").should_be_called().will_return(True)
|
||||||
|
geometry.create_dynamic_voids("obj").should_be_called()
|
||||||
|
subject.switch_representation(
|
||||||
|
geometry,
|
||||||
|
obj="obj",
|
||||||
|
representation="mapped_rep",
|
||||||
|
should_reload=True,
|
||||||
|
enable_dynamic_voids=True,
|
||||||
|
is_global=True,
|
||||||
|
)
|
||||||
|
|
||||||
def test_switching_to_an_existing_representation(self, geometry):
|
def test_switching_to_an_existing_representation(self, geometry):
|
||||||
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
||||||
geometry.get_representation_data("representation").should_be_called().will_return("data")
|
geometry.get_representation_data("representation").should_be_called().will_return("data")
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ class TestCreateDynamicVoids(NewFile):
|
|||||||
assert modifier.use_self is True
|
assert modifier.use_self is True
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeleteData(NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
data = bpy.data.meshes.new("Mesh")
|
||||||
|
subject.delete_data(data)
|
||||||
|
assert not bpy.data.meshes.get("Mesh")
|
||||||
|
|
||||||
|
|
||||||
class TestDoesObjectHaveMeshWithFaces(NewFile):
|
class TestDoesObjectHaveMeshWithFaces(NewFile):
|
||||||
def test_empties_return_false(self):
|
def test_empties_return_false(self):
|
||||||
obj = bpy.data.objects.new("Object", None)
|
obj = bpy.data.objects.new("Object", None)
|
||||||
|
|||||||
Reference in New Issue
Block a user