diff options
author | Arjen Hiemstra <ahiemstra@heimr.nl> | 2017-04-20 18:22:39 +0300 |
---|---|---|
committer | Arjen Hiemstra <ahiemstra@heimr.nl> | 2017-04-20 18:41:53 +0300 |
commit | 97fd35c21d2d8e90c0f078f4e9529b03383760e8 (patch) | |
tree | 4def9e69daff7f37609d7533662c5f32e73156fc /cura/CuraActions.py | |
parent | 8e95c894fbb73de7207f90ba6147965d43b9922f (diff) |
Add a centerSelection method to CuraActions
Can be used to center all selected objects.
Contributes to CURA-3609
Diffstat (limited to 'cura/CuraActions.py')
-rw-r--r-- | cura/CuraActions.py | 22 |
1 files changed, 21 insertions, 1 deletions
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) |