From 97fd35c21d2d8e90c0f078f4e9529b03383760e8 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 20 Apr 2017 17:22:39 +0200 Subject: [PATCH] Add a centerSelection method to CuraActions Can be used to center all selected objects. Contributes to CURA-3609 --- cura/CuraActions.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cura/CuraActions.py b/cura/CuraActions.py index df26a9a9a6..7e9cbebd94 100644 --- a/cura/CuraActions.py +++ b/cura/CuraActions.py @@ -1,9 +1,16 @@ +# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + from PyQt5.QtCore import QObject, QUrl from PyQt5.QtGui import QDesktopServices from UM.FlameProfiler import pyqtSlot from UM.Event import CallFunctionEvent 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.SetTransformOperation import SetTransformOperation class CuraActions(QObject): @@ -23,5 +30,18 @@ class CuraActions(QObject): event = CallFunctionEvent(self._openUrl, [QUrl("http://github.com/Ultimaker/Cura/issues")], {}) Application.getInstance().functionEvent(event) + ## Center all objects in the selection + @pyqtSlot() + def centerSelection(self) -> None: + operation = GroupedOperation() + for node in Selection.getAllSelectedObjects(): + current_node = node + while current_node.getParent() and current_node.getParent().callDecoration("isGroup"): + current_node = current_node.getParent() + + center_operation = SetTransformOperation(current_node, Vector()) + operation.addOperation(center_operation) + operation.push() + def _openUrl(self, url): - QDesktopServices.openUrl(url) \ No newline at end of file + QDesktopServices.openUrl(url)