mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
geometry.unassign_representation to remove shape aspects
previously it was leaving unused shape aspects unconnected to any other elements, now it will purge them
This commit is contained in:
@@ -50,13 +50,16 @@ class Usecase:
|
||||
return
|
||||
representations.remove(representation)
|
||||
if not representations:
|
||||
self.file.remove(product.Representation)
|
||||
product_def = product.Representation
|
||||
# TODO: should somehow find matching shape aspect and remove it
|
||||
# even before the last representation is removed.
|
||||
self.process_shape_aspects(product_def)
|
||||
self.file.remove(product_def)
|
||||
else:
|
||||
product.Representation.Representations = representations
|
||||
|
||||
def unassign_type_representation(self) -> None:
|
||||
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"]:
|
||||
@@ -68,8 +71,26 @@ class Usecase:
|
||||
self.settings["product"].RepresentationMaps = [
|
||||
rm for rm in self.settings["product"].RepresentationMaps if rm != matching_representation_map
|
||||
] or None
|
||||
self.process_shape_aspects(matching_representation_map)
|
||||
self.remove_representation_map_only(matching_representation_map)
|
||||
|
||||
def process_shape_aspects(self, product_representation: ifcopenshell.entity_instance) -> None:
|
||||
# Technically IfcShapeAspect doesn't become invalid when product representation is removed,
|
||||
# but shape aspect makes sense only in context of some other representation.
|
||||
if self.file.schema == "IFC2X3" and product_representation.is_a("IfcRepresentationMap"):
|
||||
shape_aspects = [
|
||||
a
|
||||
for a in self.file.by_type("IfcShapeAspect")
|
||||
if a.PartOfProductDefinitionShape == product_representation
|
||||
]
|
||||
else:
|
||||
shape_aspects = product_representation.HasShapeAspects
|
||||
for shape_aspect in shape_aspects:
|
||||
representations = shape_aspect.ShapeRepresentations
|
||||
self.file.remove(shape_aspect)
|
||||
for rep in representations:
|
||||
ifcopenshell.api.geometry.remove_representation(self.file, rep)
|
||||
|
||||
def remove_representation_map_only(self, representation_map: ifcopenshell.entity_instance) -> None:
|
||||
representation_map.MappedRepresentation = self.file.createIfcShapeRepresentation()
|
||||
ifcopenshell.util.element.remove_deep2(self.file, representation_map)
|
||||
|
||||
Reference in New Issue
Block a user