Fix regression where adding a new occurrence should not change your active context back to body if you've switched it.

This commit is contained in:
Dion Moult
2025-02-07 23:52:55 +11:00
parent 49c3a55456
commit 7bc1992963
2 changed files with 13 additions and 3 deletions
+10 -1
View File
@@ -326,6 +326,12 @@ class AddConstrTypeInstance(bpy.types.Operator, tool.Ifc.Operator):
instance_class = ifcopenshell.util.type.get_applicable_entities(ifc_class, tool.Ifc.get().schema)[0]
material = ifcopenshell.util.element.get_material(relating_type)
existing_context = None
for existing_occurrence in ifcopenshell.util.element.get_types(relating_type):
if existing_obj := tool.Ifc.get_object(existing_occurrence):
existing_context = tool.Geometry.get_active_representation_context(existing_obj)
break
if material and material.is_a("IfcMaterialProfileSet"):
if obj := profile.DumbProfileGenerator(relating_type).generate():
tool.Blender.select_and_activate_single_object(context, obj)
@@ -415,7 +421,10 @@ class AddConstrTypeInstance(bpy.types.Operator, tool.Ifc.Operator):
element = tool.Ifc.get_entity(obj)
bonsai.core.type.assign_type(tool.Ifc, tool.Type, element=element, type=relating_type)
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if existing_context:
representation = ifcopenshell.util.representation.get_representation(element, existing_context)
else:
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if not representation and element.Representation:
representation = element.Representation.Representations[0]
+3 -2
View File
@@ -733,8 +733,9 @@ def the_object_name_has_a_representation_type_of_context(name, type, context):
element = ifc.by_id(the_object_name_exists(name).BIMObjectProperties.ifc_definition_id)
context, subcontext, target_view = context.split("/")
rep = ifcopenshell.util.representation.get_representation(element, context, subcontext or None, target_view or None)
rep =ifcopenshell.util.representation.resolve_representation(rep)
assert rep
assert rep.RepresentationType == type
assert rep.RepresentationType == type, f"The object {name} does not have a {type} representation"
@given(parsers.parse('the object "{name}" data is a "{type}" representation of "{context}"'))
@@ -744,7 +745,7 @@ def the_object_name_data_is_a_type_representation_of_context(name, type, context
context, subcontext, target_view = context.split("/")
rep = ifc.by_id(the_object_name_exists(name).data.BIMMeshProperties.ifc_definition_id)
assert rep
assert rep.RepresentationType == type
assert rep.RepresentationType == type, f"The object {name} is not a {type} representation"
assert rep.ContextOfItems.ContextType == context
assert rep.ContextOfItems.ContextIdentifier == subcontext
assert rep.ContextOfItems.TargetView == target_view