mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
IFC Mesh Separate - reload representation just once if multiple items got separated
This commit is contained in:
@@ -110,19 +110,29 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
selected_objects = context.selected_editable_objects
|
selected_objects = context.selected_editable_objects
|
||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
|
|
||||||
|
should_reload_representation = False
|
||||||
for obj in selected_objects:
|
for obj in selected_objects:
|
||||||
if tool.Geometry.is_representation_item(obj):
|
if tool.Geometry.is_representation_item(obj):
|
||||||
self.separate_item(context, obj)
|
res = self.separate_item(context, obj)
|
||||||
|
should_reload_representation |= res
|
||||||
elif element := tool.Ifc.get_entity(obj):
|
elif element := tool.Ifc.get_entity(obj):
|
||||||
self.separate_element(context, element, obj)
|
self.separate_element(context, element, obj)
|
||||||
else:
|
else:
|
||||||
non_ifc_objects.append(obj)
|
non_ifc_objects.append(obj)
|
||||||
|
|
||||||
|
if should_reload_representation:
|
||||||
|
rep_obj = tool.Geometry.get_geometry_props().representation_obj
|
||||||
|
assert rep_obj
|
||||||
|
tool.Geometry.reload_representation(rep_obj)
|
||||||
|
|
||||||
if non_ifc_objects:
|
if non_ifc_objects:
|
||||||
with context.temp_override(selected_editable_objects=non_ifc_objects):
|
with context.temp_override(selected_editable_objects=non_ifc_objects):
|
||||||
bpy.ops.mesh.separate(type=self.type)
|
bpy.ops.mesh.separate(type=self.type)
|
||||||
|
|
||||||
def separate_item(self, context: bpy.types.Context, obj: bpy.types.Object) -> None:
|
def separate_item(self, context: bpy.types.Context, obj: bpy.types.Object) -> bool:
|
||||||
|
"""
|
||||||
|
:return: True if item was changed and ``representation_obj`` should be reloaded.
|
||||||
|
"""
|
||||||
tool.Blender.set_active_object(obj)
|
tool.Blender.set_active_object(obj)
|
||||||
item = tool.Geometry.get_active_representation(obj)
|
item = tool.Geometry.get_active_representation(obj)
|
||||||
representation_obj = tool.Geometry.get_geometry_props().representation_obj
|
representation_obj = tool.Geometry.get_geometry_props().representation_obj
|
||||||
@@ -130,13 +140,17 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
if tool.Geometry.is_meshlike_item(item):
|
if tool.Geometry.is_meshlike_item(item):
|
||||||
bpy.ops.mesh.separate(type=self.type)
|
bpy.ops.mesh.separate(type=self.type)
|
||||||
|
# Nothing got separated.
|
||||||
|
if len(context.selected_objects) == 1:
|
||||||
|
return False
|
||||||
for obj_ in context.selected_objects:
|
for obj_ in context.selected_objects:
|
||||||
if obj_ == obj:
|
if obj_ == obj:
|
||||||
continue
|
continue
|
||||||
self.add_meshlike_item(obj_)
|
self.add_meshlike_item(obj_)
|
||||||
tool.Geometry.reload_representation(representation_obj)
|
return True
|
||||||
else:
|
else:
|
||||||
self.report({"INFO"}, f"Separating an {item.is_a()} is not supported")
|
self.report({"INFO"}, f"Separating an {item.is_a()} is not supported")
|
||||||
|
return False
|
||||||
|
|
||||||
def add_meshlike_item(self, obj: bpy.types.Object) -> None:
|
def add_meshlike_item(self, obj: bpy.types.Object) -> None:
|
||||||
props = tool.Geometry.get_geometry_props()
|
props = tool.Geometry.get_geometry_props()
|
||||||
|
|||||||
Reference in New Issue
Block a user