Simplified shape aspect duplication in copy_representation()

This commit is contained in:
Robin Quint
2025-08-12 18:47:31 +02:00
committed by Ryan Schultz
parent 8b155fc989
commit be62fd494e
+26 -47
View File
@@ -103,62 +103,41 @@ class Root(bonsai.core.tool.Root):
copied_entities=copied_entities, copied_entities=copied_entities,
) )
cls.copy_shape_aspects(source.Representation, dest.Representation) for aspect in source.Representation.HasShapeAspects:
ifcopenshell.util.element.copy_deep(
elif dest.is_a("IfcTypeProduct"):
if not source.RepresentationMaps:
return copied_entities
new_maps = []
for m in source.RepresentationMaps:
new_map = ifcopenshell.util.element.copy_deep(
tool.Ifc.get(), tool.Ifc.get(),
m, aspect,
exclude=["IfcGeometricRepresentationContext"], exclude=["IfcGeometricRepresentationContext"],
exclude_callback=exclude_callback, exclude_callback=exclude_callback,
copied_entities=copied_entities, copied_entities=copied_entities,
) )
cls.copy_shape_aspects(m, new_map)
new_maps.append(new_map) elif dest.is_a("IfcTypeProduct"):
dest.RepresentationMaps = new_maps if not source.RepresentationMaps:
return copied_entities return copied_entities
@classmethod new_representation_maps = []
def copy_shape_aspects(cls, source_repr: ifcopenshell.entity_instance, dest_repr: ifcopenshell.entity_instance): for map in source.RepresentationMaps:
if source_repr.is_a("IfcProductDefinitionShape"): new_map = ifcopenshell.util.element.copy_deep(
old_to_new_items = {} tool.Ifc.get(),
for repr_index, representation in enumerate(source_repr.Representations): map,
for item_index, item in enumerate(representation.Items): exclude=["IfcGeometricRepresentationContext"],
old_to_new_items[item.id()] = dest_repr.Representations[repr_index].Items[item_index] exclude_callback=exclude_callback,
copied_entities=copied_entities,
)
for aspect in source_repr.HasShapeAspects: for aspect in map.HasShapeAspects:
new_reprs = [] ifcopenshell.util.element.copy_deep(
for repr in aspect.ShapeRepresentations: tool.Ifc.get(),
new_items = [] aspect,
for old_item in repr.Items: exclude=["IfcGeometricRepresentationContext"],
new_items.append(old_to_new_items[old_item.id()]) exclude_callback=exclude_callback,
new_repr = ifcopenshell.util.element.copy(tool.Ifc.get(), repr) copied_entities=copied_entities,
new_repr.Items = new_items )
new_reprs.append(new_repr)
new_aspect = ifcopenshell.util.element.copy(tool.Ifc.get(), aspect)
new_aspect.ShapeRepresentations = new_reprs
new_aspect.PartOfProductDefinitionShape = dest_repr
elif source_repr.is_a("IfcRepresentationMap"):
old_to_new_items = {}
for item_index, item in enumerate(source_repr.MappedRepresentation.Items):
old_to_new_items[item.id()] = dest_repr.MappedRepresentation.Items[item_index]
for aspect in source_repr.HasShapeAspects: new_representation_maps.append(new_map)
new_reprs = [] dest.RepresentationMaps = new_representation_maps
for repr in aspect.ShapeRepresentations: return copied_entities
new_items = []
for old_item in repr.Items:
new_items.append(old_to_new_items[old_item.id()])
new_repr = ifcopenshell.util.element.copy(tool.Ifc.get(), repr)
new_repr.Items = new_items
new_reprs.append(new_repr)
new_aspect = ifcopenshell.util.element.copy(tool.Ifc.get(), aspect)
new_aspect.ShapeRepresentations = new_reprs
new_aspect.PartOfProductDefinitionShape = dest_repr
@classmethod @classmethod
def does_type_have_representations(cls, element: ifcopenshell.entity_instance) -> bool: def does_type_have_representations(cls, element: ifcopenshell.entity_instance) -> bool: