mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Bonsai: route array-regen selection through tool.Blender utilities
Rewrite tool.Array.select_only_parent as a thin call to tool.Blender.select_and_activate_single_object; drop the ad-hoc per-child deselect loop and the unused parent_element parameter. Replace the tail parent_obj.select_set(True) in _regenerate_array_body with tool.Blender.set_object_selection, which wraps select_set in the hidden-object try/except the utility already owns. Relates to #8088. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -329,7 +329,7 @@ class _ArrayEditMixin(ParametricEditMixinBase):
|
||||
# Unhide the (possibly newly-regenerated) children so the user sees
|
||||
# the committed result. Mirrors the hide in ``_enable_one``.
|
||||
cls._set_children_visibility(element, hidden=False)
|
||||
tool.Array.select_only_parent(obj, element, context)
|
||||
tool.Array.select_only_parent(obj, context)
|
||||
|
||||
@classmethod
|
||||
def _cancel_one(cls, obj: bpy.types.Object) -> None:
|
||||
@@ -443,7 +443,7 @@ class RegenerateArray(bpy.types.Operator, tool.Ifc.Operator):
|
||||
tool.Model.regenerate_array(parent, arrays)
|
||||
tool.Array.constrain_children_to_parent(parent_element)
|
||||
|
||||
tool.Array.select_only_parent(parent, parent_element, context)
|
||||
tool.Array.select_only_parent(parent, context)
|
||||
|
||||
|
||||
class RemoveArray(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
@@ -179,25 +179,11 @@ class Array(bonsai.core.tool.Array):
|
||||
return [o for o in occurrences if cls.get_array_root_guid(o) == element_root]
|
||||
|
||||
@classmethod
|
||||
def select_only_parent(
|
||||
cls,
|
||||
parent_obj: bpy.types.Object,
|
||||
parent_element: entity_instance,
|
||||
context: bpy.types.Context,
|
||||
) -> None:
|
||||
"""Deselect every array child of ``parent_element``, then select and
|
||||
activate ``parent_obj``. Post-condition for the user-facing regenerate
|
||||
and finish-edit paths — grow and shrink otherwise diverge on which
|
||||
objects stay selected, surfacing an inconsistency to the user."""
|
||||
for child_obj in cls.get_all_objects(parent_element):
|
||||
if child_obj is parent_obj:
|
||||
continue
|
||||
try:
|
||||
child_obj.select_set(False)
|
||||
except (ReferenceError, RuntimeError):
|
||||
continue
|
||||
parent_obj.select_set(True)
|
||||
context.view_layer.objects.active = parent_obj
|
||||
def select_only_parent(cls, parent_obj: bpy.types.Object, context: bpy.types.Context) -> None:
|
||||
"""Post-condition for the user-facing regenerate and finish-edit paths:
|
||||
only ``parent_obj`` is selected + active. Grow and shrink otherwise
|
||||
diverge on which objects stay selected, surfacing an inconsistency."""
|
||||
tool.Blender.select_and_activate_single_object(context, parent_obj)
|
||||
|
||||
@classmethod
|
||||
def is_array_child(cls, element: entity_instance) -> bool:
|
||||
|
||||
@@ -1404,7 +1404,7 @@ class Model(bonsai.core.tool.Model):
|
||||
tool.Ifc.get(), pset=pset, properties={"Data": json_data, "Parent": parent_element.GlobalId}
|
||||
)
|
||||
|
||||
parent_obj.select_set(True)
|
||||
tool.Blender.set_object_selection(parent_obj, True)
|
||||
|
||||
@classmethod
|
||||
def mirror_parent_void_fillings_to_children(
|
||||
|
||||
@@ -537,7 +537,7 @@ class TestSelectOnlyParent(NewFile):
|
||||
child_obj = tool.Ifc.get_object(child_element)
|
||||
child_obj.select_set(True)
|
||||
|
||||
tool.Array.select_only_parent(obj, element, bpy.context)
|
||||
tool.Array.select_only_parent(obj, bpy.context)
|
||||
|
||||
assert obj in bpy.context.selected_objects
|
||||
assert bpy.context.view_layer.objects.active is obj
|
||||
|
||||
Reference in New Issue
Block a user