From 6ac6f13018191b39c8440bfc480298e9944359cc Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 15 Feb 2025 19:03:52 +1100 Subject: [PATCH] Fix #5824. Prioritise 3D over 2D. Only then consider subcontexts. It's unexpected in our 3D default viewing world to have 2D first over 3D. --- .../ifcopenshell/util/representation.py | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/representation.py b/src/ifcopenshell-python/ifcopenshell/util/representation.py index 1255621608..b032501a20 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/representation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/representation.py @@ -343,9 +343,9 @@ def get_prioritised_contexts(ifc_file: ifcopenshell.file) -> list[ifcopenshell.e you may want to prioritise visualising certain contexts over others, determined by the context type, identifier, target view, and target scale. - The default prioritises subcontexts, then contexts. It then prioritises 3D, - then 2D. It then prioritises bodies, then others. It also prioritises model - views, then plan views, then others. + The default prioritises 3D, then 2D. It then prioritises subcontexts, then + contexts. It then prioritises bodies, then others. It also prioritises + model views, then plan views, then others. :param ifc_file: The model containing contexts :return: A list of IfcGeometricRepresentationContext (or SubContext) from @@ -383,14 +383,6 @@ def get_prioritised_contexts(ifc_file: ifcopenshell.file) -> list[ifcopenshell.e def sort_context(context): priority = [] - if context.ContextType in type_priority: - priority.append(len(type_priority) - type_priority.index(context.ContextType)) - else: - priority.append(0) - return tuple(priority) - - def sort_subcontext(context): - priority = [] if context.ContextType in type_priority: priority.append(len(type_priority) - type_priority.index(context.ContextType)) @@ -402,21 +394,16 @@ def get_prioritised_contexts(ifc_file: ifcopenshell.file) -> list[ifcopenshell.e else: priority.append(0) - if context.TargetView in target_view_priority: + if getattr(context, "TargetView", None) in target_view_priority: priority.append(len(target_view_priority) - target_view_priority.index(context.TargetView)) else: priority.append(0) - priority.append(context.TargetScale or 0) # Big then small + priority.append(getattr(context, "TargetScale", None) or 0) # Big then small return tuple(priority) - # Ideally, all representations should be in a subcontext, but some BIM programs don't do this correctly - return sorted(ifc_file.by_type("IfcGeometricRepresentationSubContext"), key=sort_subcontext, reverse=True) + sorted( - ifc_file.by_type("IfcGeometricRepresentationContext", include_subtypes=False), - key=sort_context, - reverse=True, - ) + return sorted(ifc_file.by_type("IfcGeometricRepresentationContext"), key=sort_context, reverse=True) def get_part_of_product(