mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
remove_representation - small optimizations
check schema version instead of accessing attribute directly (hasattr under the hood is just doing getattr and checking whether it returns AttributeError), so one less IFC access Similar thing with element.Item to access IFC just once.
This commit is contained in:
@@ -37,6 +37,7 @@ def remove_representation(
|
|||||||
:param should_keep_named_profiles: If true, named profile defs will not be
|
:param should_keep_named_profiles: If true, named profile defs will not be
|
||||||
removed as they are assumed to be significant.
|
removed as they are assumed to be significant.
|
||||||
"""
|
"""
|
||||||
|
is_ifc2x3 = file.schema == "IFC2X3"
|
||||||
styled_items = set()
|
styled_items = set()
|
||||||
presentation_layer_assignments = set()
|
presentation_layer_assignments = set()
|
||||||
textures = set()
|
textures = set()
|
||||||
@@ -46,9 +47,7 @@ def remove_representation(
|
|||||||
if subelement.is_a("IfcRepresentationItem"):
|
if subelement.is_a("IfcRepresentationItem"):
|
||||||
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
[styled_items.add(s) for s in subelement.StyledByItem or []]
|
||||||
# IFC2X3 is using LayerAssignments
|
# IFC2X3 is using LayerAssignments
|
||||||
for s in (
|
for s in subelement.LayerAssignment if not is_ifc2x3 else subelement.LayerAssignments:
|
||||||
subelement.LayerAssignment if hasattr(subelement, "LayerAssignment") else subelement.LayerAssignments
|
|
||||||
):
|
|
||||||
presentation_layer_assignments.add(s)
|
presentation_layer_assignments.add(s)
|
||||||
# IfcTessellatedFaceSet inverses
|
# IfcTessellatedFaceSet inverses
|
||||||
[textures.add(t) for t in getattr(subelement, "HasTextures", []) or []]
|
[textures.add(t) for t in getattr(subelement, "HasTextures", []) or []]
|
||||||
@@ -77,7 +76,8 @@ def remove_representation(
|
|||||||
|
|
||||||
to_delete = file.to_delete or set()
|
to_delete = file.to_delete or set()
|
||||||
for element in styled_items:
|
for element in styled_items:
|
||||||
if not element.Item or element.Item in to_delete:
|
item = element.Item
|
||||||
|
if not item or item in to_delete:
|
||||||
file.remove(element)
|
file.remove(element)
|
||||||
for element in presentation_layer_assignments:
|
for element in presentation_layer_assignments:
|
||||||
if all(item in to_delete for item in element.AssignedItems):
|
if all(item in to_delete for item in element.AssignedItems):
|
||||||
|
|||||||
Reference in New Issue
Block a user