Fix unassign_representation to not incorrectly use remove_deep without first removing known inverses.

In theory, it would be possible for the representation map to be used elsewhere, then file.remove(representation_map) would cause problems.
This commit is contained in:
Dion Moult
2024-05-23 23:08:53 +10:00
parent 02cae9c7c2
commit c405ff1adf
@@ -47,17 +47,25 @@ class Usecase:
product.Representation.Representations = representations
def unassign_type_representation(self):
matching_representation_map = None
representation_maps = self.settings["product"].RepresentationMaps or []
for representation_map in self.settings["product"].RepresentationMaps or []:
if representation_map.MappedRepresentation == self.settings["representation"]:
self.unassign_products_using_mapped_representation(representation_map)
self.remove_representation_map_only(representation_map)
matching_representation_map = representation_map
break
self.settings["product"].RepresentationMaps = self.settings["product"].RepresentationMaps or None
if matching_representation_map:
self.unassign_products_using_mapped_representation(matching_representation_map)
self.settings["product"].RepresentationMaps = [
rm for rm in self.settings["product"].RepresentationMaps if rm != matching_representation_map
] or None
self.remove_representation_map_only(matching_representation_map)
def remove_representation_map_only(self, representation_map):
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
self.file.remove(representation_map)
def unassign_products_using_mapped_representation(self, representation_map):
mapped_representations = []