activate_drawing to prioritize already active representation

If there are multiple representations in the same subcontext, when it was searching for the representation for some specific subcontext, it would previously always switch to the first representation from the list, now it's going to prioritize the one that's already active.
This commit is contained in:
Andrej730
2023-10-18 12:25:00 +05:00
parent ab807e3b9b
commit dd7a6a80eb
2 changed files with 24 additions and 11 deletions
+16 -11
View File
@@ -1647,20 +1647,25 @@ class Drawing(blenderbim.core.tool.Drawing):
for element in filtered_elements: for element in filtered_elements:
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)
subcontext = tool.Geometry.get_active_representation(obj).ContextOfItems
current_representation_subcontext = tool.Geometry.get_subcontext_parameters(subcontext)
for subcontext in subcontexts: for subcontext in subcontexts:
# prioritize already active representation if it matches the subcontext
# (element could have multiple representations in the same subcontext)
if subcontext == current_representation_subcontext:
break
priority_representation = ifcopenshell.util.representation.get_representation(element, *subcontext) priority_representation = ifcopenshell.util.representation.get_representation(element, *subcontext)
if priority_representation: if priority_representation:
current_representation = tool.Geometry.get_active_representation(obj) blenderbim.core.geometry.switch_representation(
if current_representation != priority_representation: tool.Ifc,
blenderbim.core.geometry.switch_representation( tool.Geometry,
tool.Ifc, obj=obj,
tool.Geometry, representation=priority_representation,
obj=obj, should_reload=False,
representation=priority_representation, is_global=True,
should_reload=False, should_sync_changes_first=True,
is_global=True, )
should_sync_changes_first=True,
)
break break
@classmethod @classmethod
@@ -308,6 +308,14 @@ class Geometry(blenderbim.core.tool.Geometry):
return active_representation.ContextOfItems return active_representation.ContextOfItems
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW") return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
@classmethod
def get_subcontext_parameters(cls, subcontext):
return (
subcontext.ContextType,
subcontext.ContextIdentifier,
subcontext.TargetView,
)
@classmethod @classmethod
def get_representation_by_context(cls, element, context): def get_representation_by_context(cls, element, context):
if element.is_a("IfcProduct") and element.Representation: if element.is_a("IfcProduct") and element.Representation: