mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-22 06:03:57 -06:00
Add a centerSelection method to CuraActions
Can be used to center all selected objects. Contributes to CURA-3609
This commit is contained in:
parent
8e95c894fb
commit
97fd35c21d
1 changed files with 21 additions and 1 deletions
|
@ -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.QtCore import QObject, QUrl
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from UM.FlameProfiler import pyqtSlot
|
from UM.FlameProfiler import pyqtSlot
|
||||||
|
|
||||||
from UM.Event import CallFunctionEvent
|
from UM.Event import CallFunctionEvent
|
||||||
from UM.Application import Application
|
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):
|
class CuraActions(QObject):
|
||||||
|
@ -23,5 +30,18 @@ class CuraActions(QObject):
|
||||||
event = CallFunctionEvent(self._openUrl, [QUrl("http://github.com/Ultimaker/Cura/issues")], {})
|
event = CallFunctionEvent(self._openUrl, [QUrl("http://github.com/Ultimaker/Cura/issues")], {})
|
||||||
Application.getInstance().functionEvent(event)
|
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):
|
def _openUrl(self, url):
|
||||||
QDesktopServices.openUrl(url)
|
QDesktopServices.openUrl(url)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue