Fix #2488. Copying objects now copy deep instead of adding afresh (and losing parametric data and openings).

This commit is contained in:
Dion Moult
2022-10-09 18:09:22 +11:00
parent 232252f61d
commit bdbd874fa8
8 changed files with 55 additions and 56 deletions
+6 -14
View File
@@ -40,25 +40,17 @@ class TestCopyClass:
root.is_opening_element("element").should_be_called().will_return(False)
subject.copy_class(ifc, collector, geometry, root, obj="obj")
def test_copy_with_new_geometry_added_afresh_for_speed(self, ifc, collector, geometry, root):
def test_copy_with_new_geometry_copied_from_the_old(self, ifc, collector, geometry, root):
# Originally, geometry was added fresh from the Blender mesh instead of
# copied. This was faster (though I cannot recreate it now) but had the
# bigger problem of not preserving non-mesh geometry and openings.
ifc.get_entity("obj").should_be_called().will_return("original_element")
root.get_object_representation("obj").should_be_called().will_return("representation")
ifc.run("root.copy_class", product="original_element").should_be_called().will_return("element")
ifc.link("element", "obj").should_be_called()
root.get_element_type("element").should_be_called().will_return("type")
root.does_type_have_representations("type").should_be_called().will_return(False)
root.get_representation_context("representation").should_be_called().will_return("context")
geometry.get_ifc_representation_class("element", "representation").should_be_called().will_return(
"ifc_representation_class"
)
geometry.get_profile_set_usage("element").should_be_called().will_return("profile_set_usage")
root.run_geometry_add_representation(
obj="obj",
context="context",
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
).should_be_called()
root.copy_representation("original_element", "element").should_be_called()
collector.assign("obj").should_be_called()
root.is_opening_element("element").should_be_called().will_return(False)
subject.copy_class(ifc, collector, geometry, root, obj="obj")
@@ -74,7 +66,7 @@ class TestCopyClass:
root.is_opening_element("element").should_be_called().will_return(False)
subject.copy_class(ifc, collector, geometry, root, obj="obj")
def test_copied_openings_have_dynamic_voids_added(self, ifc, collector, root):
def test_copied_openings_are_tracked_for_special_visualiation(self, ifc, collector, root):
ifc.get_entity("obj").should_be_called().will_return("original_element")
root.get_object_representation("obj").should_be_called().will_return(None)
ifc.run("root.copy_class", product="original_element").should_be_called().will_return("element")
+18
View File
@@ -37,6 +37,24 @@ class TestAddTrackedOpening(NewFile):
assert props.openings[0].obj == obj
class TestCopyRepresentation(NewFile):
def test_copying_a_product(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
source = ifc.createIfcWall(Representation=ifc.createIfcProductDefinitionShape())
dest = ifc.createIfcWall()
subject.copy_representation(source, dest)
assert dest.Representation.is_a("IfcProductDefinitionShape")
def test_copying_a_type_product(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
source = ifc.createIfcWallType(RepresentationMaps=[ifc.createIfcRepresentationMap()])
dest = ifc.createIfcWallType()
subject.copy_representation(source, dest)
assert dest.RepresentationMaps[0].is_a("IfcRepresentationMap")
class TestDoesTypeHaveRepresentations(NewFile):
def test_run(self):
ifc = ifcopenshell.file()