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.
This commit is contained in:
Dion Moult
2025-02-15 19:03:52 +11:00
parent d23cfcb2cf
commit 6ac6f13018
@@ -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(