mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -19,62 +19,57 @@
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file: ifcopenshell.file, representation: ifcopenshell.entity_instance):
|
||||
"""Remove a representation.
|
||||
def remove_representation(file: ifcopenshell.file, representation: ifcopenshell.entity_instance) -> None:
|
||||
"""Remove a representation.
|
||||
|
||||
Also purges representation items and their related elements
|
||||
like IfcStyledItem, tessellated facesets colours and UV map.
|
||||
Also purges representation items and their related elements
|
||||
like IfcStyledItem, tessellated facesets colours and UV map.
|
||||
|
||||
:param representation: IfcRepresentation to remove.
|
||||
Note that it's expected that IfcRepresentation won't be in use
|
||||
before calling this method (in such elements as IfcProductRepresentation, IfcShapeAspect)
|
||||
otherwise representation won't be removed.
|
||||
:type representation: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"representation": representation}
|
||||
:param representation: IfcRepresentation to remove.
|
||||
Note that it's expected that IfcRepresentation won't be in use
|
||||
before calling this method (in such elements as IfcProductRepresentation, IfcShapeAspect)
|
||||
otherwise representation won't be removed.
|
||||
:type representation: ifcopenshell.entity_instance
|
||||
:return: None
|
||||
:rtype: None
|
||||
"""
|
||||
settings = {"representation": representation}
|
||||
|
||||
def execute(self) -> None:
|
||||
styled_items = set()
|
||||
presentation_layer_assignments = set()
|
||||
textures = set()
|
||||
colours = set()
|
||||
for subelement in self.file.traverse(self.settings["representation"]):
|
||||
if subelement.is_a("IfcRepresentationItem"):
|
||||
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
||||
# IFC2X3 is using LayerAssignments
|
||||
for s in (
|
||||
subelement.LayerAssignment
|
||||
if hasattr(subelement, "LayerAssignment")
|
||||
else subelement.LayerAssignments
|
||||
):
|
||||
presentation_layer_assignments.add(s)
|
||||
# IfcTessellatedFaceSet inverses
|
||||
[textures.add(t) for t in getattr(subelement, "HasTextures", []) or []]
|
||||
[colours.add(t) for t in getattr(subelement, "HasColours", []) or []]
|
||||
elif subelement.is_a("IfcRepresentation"):
|
||||
for layer in subelement.LayerAssignments:
|
||||
presentation_layer_assignments.add(layer)
|
||||
styled_items = set()
|
||||
presentation_layer_assignments = set()
|
||||
textures = set()
|
||||
colours = set()
|
||||
for subelement in file.traverse(settings["representation"]):
|
||||
if subelement.is_a("IfcRepresentationItem"):
|
||||
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
||||
# IFC2X3 is using LayerAssignments
|
||||
for s in (
|
||||
subelement.LayerAssignment if hasattr(subelement, "LayerAssignment") else subelement.LayerAssignments
|
||||
):
|
||||
presentation_layer_assignments.add(s)
|
||||
# IfcTessellatedFaceSet inverses
|
||||
[textures.add(t) for t in getattr(subelement, "HasTextures", []) or []]
|
||||
[colours.add(t) for t in getattr(subelement, "HasColours", []) or []]
|
||||
elif subelement.is_a("IfcRepresentation"):
|
||||
for layer in subelement.LayerAssignments:
|
||||
presentation_layer_assignments.add(layer)
|
||||
|
||||
ifcopenshell.util.element.remove_deep2(
|
||||
self.file,
|
||||
self.settings["representation"],
|
||||
also_consider=list(styled_items | presentation_layer_assignments | colours),
|
||||
do_not_delete=self.file.by_type("IfcGeometricRepresentationContext"),
|
||||
)
|
||||
ifcopenshell.util.element.remove_deep2(
|
||||
file,
|
||||
settings["representation"],
|
||||
also_consider=list(styled_items | presentation_layer_assignments | colours),
|
||||
do_not_delete=file.by_type("IfcGeometricRepresentationContext"),
|
||||
)
|
||||
|
||||
for texture in textures:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, texture)
|
||||
for colour in colours:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, colour)
|
||||
for texture in textures:
|
||||
ifcopenshell.util.element.remove_deep2(file, texture)
|
||||
for colour in colours:
|
||||
ifcopenshell.util.element.remove_deep2(file, colour)
|
||||
|
||||
to_delete = getattr(self.file, "to_delete", ())
|
||||
for element in styled_items:
|
||||
if not element.Item or element.Item in to_delete:
|
||||
self.file.remove(element)
|
||||
for element in presentation_layer_assignments:
|
||||
if all(item in to_delete for item in element.AssignedItems):
|
||||
self.file.remove(element)
|
||||
to_delete = getattr(file, "to_delete", ())
|
||||
for element in styled_items:
|
||||
if not element.Item or element.Item in to_delete:
|
||||
file.remove(element)
|
||||
for element in presentation_layer_assignments:
|
||||
if all(item in to_delete for item in element.AssignedItems):
|
||||
file.remove(element)
|
||||
|
||||
Reference in New Issue
Block a user