mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-09-13 06:13:13 +08:00
Add a PlatformPhysics class to handle some details about keeping objects on the printer platform
This commit is contained in:
parent
e68e761598
commit
abe19dfd9b
39
PlatformPhysics.py
Normal file
39
PlatformPhysics.py
Normal file
@ -0,0 +1,39 @@
|
||||
from UM.Scene.SceneNode import SceneNode
|
||||
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
|
||||
from UM.Operations.TranslateOperation import TranslateOperation
|
||||
from UM.Math.Float import Float
|
||||
from UM.Math.Vector import Vector
|
||||
from UM.Application import Application
|
||||
|
||||
import threading
|
||||
|
||||
class PlatformPhysics:
|
||||
def __init__(self, controller):
|
||||
super().__init__()
|
||||
self._controller = controller
|
||||
self._controller.activeToolChanged.connect(self._onActiveToolChanged)
|
||||
self._active_tool = None
|
||||
self._operation = False
|
||||
self._onActiveToolChanged()
|
||||
|
||||
def _onActiveToolChanged(self):
|
||||
if self._active_tool:
|
||||
self._active_tool.endOperation.disconnect(self._onEndOperation)
|
||||
|
||||
self._active_tool = self._controller.getActiveTool()
|
||||
|
||||
if self._active_tool:
|
||||
self._active_tool.endOperation.connect(self._onEndOperation)
|
||||
|
||||
def _onEndOperation(self):
|
||||
root = self._controller.getScene().getRoot()
|
||||
for node in BreadthFirstIterator(root):
|
||||
if type(node) is not SceneNode:
|
||||
continue
|
||||
|
||||
bbox = node.getBoundingBox()
|
||||
if not Float.fuzzyCompare(bbox.bottom, 0.0):
|
||||
self._signal_source = node
|
||||
op = TranslateOperation(node, Vector(0, -bbox.bottom, 0))
|
||||
Application.getInstance().getOperationStack().push(op)
|
||||
self._signal_source = None
|
Loading…
x
Reference in New Issue
Block a user