From b56802a52305ed1edc1588dfb51d3d16e99314f5 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 20 Apr 2017 17:26:49 +0200 Subject: [PATCH] Add a deleteSelection method to CuraActions It does the same as CuraApplication::deleteSelection but this is a better place for it. Contributes to CURA-3609 --- cura/CuraActions.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cura/CuraActions.py b/cura/CuraActions.py index 4fd51a8513..c617980bc5 100644 --- a/cura/CuraActions.py +++ b/cura/CuraActions.py @@ -10,8 +10,10 @@ from UM.Application import Application from UM.Math.Vector import Vector from UM.Scene.Selection import Selection from UM.Operations.GroupedOperation import GroupedOperation +from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation from UM.Operations.SetTransformOperation import SetTransformOperation +from .SetParentOperation import SetParentOperation from .MultiplyObjectsJob import MultiplyObjectsJob class CuraActions(QObject): @@ -52,5 +54,25 @@ class CuraActions(QObject): job = MultiplyObjectsJob(Selection.getAllSelectedObjects(), count, 8) job.start() return + + ## Delete all selected objects. + @pyqtSlot() + def deleteSelection(self) -> None: + if not Application.getInstance().getController().getToolsEnabled(): + return + + removed_group_nodes = [] + op = GroupedOperation() + nodes = Selection.getAllSelectedObjects() + for node in nodes: + op.addOperation(RemoveSceneNodeOperation(node)) + group_node = node.getParent() + if group_node and group_node.callDecoration("isGroup") and group_node not in removed_group_nodes: + remaining_nodes_in_group = list(set(group_node.getChildren()) - set(nodes)) + if len(remaining_nodes_in_group) == 1: + removed_group_nodes.append(group_node) + op.addOperation(SetParentOperation(remaining_nodes_in_group[0], group_node.getParent())) + op.addOperation(RemoveSceneNodeOperation(group_node)) + op.push() def _openUrl(self, url): QDesktopServices.openUrl(url)