mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
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:
@@ -47,17 +47,25 @@ class Usecase:
|
|||||||
product.Representation.Representations = representations
|
product.Representation.Representations = representations
|
||||||
|
|
||||||
def unassign_type_representation(self):
|
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 []:
|
for representation_map in self.settings["product"].RepresentationMaps or []:
|
||||||
if representation_map.MappedRepresentation == self.settings["representation"]:
|
if representation_map.MappedRepresentation == self.settings["representation"]:
|
||||||
self.unassign_products_using_mapped_representation(representation_map)
|
matching_representation_map = representation_map
|
||||||
self.remove_representation_map_only(representation_map)
|
|
||||||
break
|
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):
|
def remove_representation_map_only(self, representation_map):
|
||||||
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
|
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
|
||||||
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
|
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
|
||||||
self.file.remove(representation_map)
|
|
||||||
|
|
||||||
def unassign_products_using_mapped_representation(self, representation_map):
|
def unassign_products_using_mapped_representation(self, representation_map):
|
||||||
mapped_representations = []
|
mapped_representations = []
|
||||||
|
|||||||
Reference in New Issue
Block a user