copy_representation: preserve MappedRepresentation structure for IfcTypeProduct

Incorporates the per-map copy logic from build-0.8.5 that preserves nested
MappedRepresentation structure instead of blindly using copy_deep, while
retaining HasShapeAspects and StyledByItem handling from this branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ryan Schultz
2026-03-16 11:39:59 -05:00
parent 2f7ed0ea52
commit d45fc0601d
+29 -13
View File
@@ -124,17 +124,33 @@ class Root(bonsai.core.tool.Root):
if not source.RepresentationMaps:
return copied_entities
new_representation_maps = []
for map in source.RepresentationMaps:
new_map = ifcopenshell.util.element.copy_deep(
tool.Ifc.get(),
map,
exclude=["IfcGeometricRepresentationContext"],
exclude_callback=exclude_callback,
copied_entities=copied_entities,
)
# Copy representation maps while preserving mapped representation structures
new_maps = []
for rep_map in source.RepresentationMaps:
source_rep = rep_map.MappedRepresentation
for aspect in map.HasShapeAspects:
# Copy the map itself
new_map = ifcopenshell.util.element.copy(tool.Ifc.get(), rep_map)
# Handle the mapped representation - preserve mapping structure if present
if (source_rep.RepresentationType == 'MappedRepresentation' and
len(source_rep.Items) == 1 and
source_rep.Items[0].is_a("IfcMappedItem")):
# This is a mapped representation - preserve the structure
new_rep = ifcopenshell.util.element.copy(tool.Ifc.get(), source_rep)
new_rep.Items = [ifcopenshell.util.element.copy(tool.Ifc.get(), item) for item in source_rep.Items]
new_map.MappedRepresentation = new_rep
else:
# Not a mapped representation - use copy_deep as before
new_map.MappedRepresentation = ifcopenshell.util.element.copy_deep(
tool.Ifc.get(),
source_rep,
exclude=["IfcGeometricRepresentationContext"],
exclude_callback=exclude_callback,
copied_entities=copied_entities,
)
for aspect in rep_map.HasShapeAspects:
ifcopenshell.util.element.copy_deep(
tool.Ifc.get(),
aspect,
@@ -143,15 +159,15 @@ class Root(bonsai.core.tool.Root):
copied_entities=copied_entities,
)
for item in map.MappedRepresentation.Items:
for item in rep_map.MappedRepresentation.Items:
if item.StyledByItem:
for styled_by in item.StyledByItem:
new_styled_by = ifcopenshell.util.element.copy(tool.Ifc.get(), styled_by)
new_styled_by.Item = copied_entities[styled_by.Item.id()]
copied_entities[styled_by.id()] = new_styled_by
new_representation_maps.append(new_map)
dest.RepresentationMaps = new_representation_maps
new_maps.append(new_map)
dest.RepresentationMaps = new_maps
return copied_entities
@classmethod