diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index b0bbc05ca9..689ae888a6 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -37,6 +37,7 @@ from . import CameraAnimation from . import PrintInformation from . import CuraActions from . import MultiMaterialDecorator +from . import ZOffsetDecorator from PyQt5.QtCore import pyqtSlot, QUrl, Qt, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS from PyQt5.QtGui import QColor, QIcon @@ -342,14 +343,12 @@ class CuraApplication(QtApplication): continue #Grouped nodes don't need resetting as their parent (the group) is resetted) nodes.append(node) + if nodes: op = GroupedOperation() for node in nodes: - # Ensure that the object is above the build platform - move_distance = node.getBoundingBox().center.y - if move_distance <= 0: - move_distance = -node.getBoundingBox().bottom - op.addOperation(SetTransformOperation(node, Vector(0,move_distance,0))) + node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) + op.addOperation(SetTransformOperation(node, Vector(0,0,0))) op.push() @@ -371,10 +370,8 @@ class CuraApplication(QtApplication): for node in nodes: # Ensure that the object is above the build platform - move_distance = node.getBoundingBox().center.y - if move_distance <= 0: - move_distance = -node.getBoundingBox().bottom - op.addOperation(SetTransformOperation(node, Vector(0,move_distance,0), Quaternion(), Vector(1, 1, 1))) + node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) + op.addOperation(SetTransformOperation(node, Vector(0,0,0), Quaternion(), Vector(1, 1, 1))) op.push() diff --git a/cura/PlatformPhysics.py b/cura/PlatformPhysics.py index 2e4d77b77f..3933802135 100644 --- a/cura/PlatformPhysics.py +++ b/cura/PlatformPhysics.py @@ -17,6 +17,7 @@ from cura.ConvexHullDecorator import ConvexHullDecorator from . import PlatformPhysicsOperation from . import ConvexHullJob +from . import ZOffsetDecorator import time import threading @@ -69,8 +70,12 @@ class PlatformPhysics: # Move it downwards if bottom is above platform move_vector = Vector() if not (node.getParent() and node.getParent().callDecoration("isGroup")): #If an object is grouped, don't move it down + z_offset = node.callDecoration("getZOffset") if node.getDecorator(ZOffsetDecorator.ZOffsetDecorator) else 0 if bbox.bottom > 0: - move_vector.setY(-bbox.bottom) + move_vector.setY(-bbox.bottom + z_offset) + elif bbox.bottom < z_offset: + move_vector.setY((-bbox.bottom) - z_offset) + #if not Float.fuzzyCompare(bbox.bottom, 0.0): # pass#move_vector.setY(-bbox.bottom) @@ -149,5 +154,16 @@ class PlatformPhysics: self._enabled = False def _onToolOperationStopped(self, tool): + if tool.getPluginId() == "TranslateTool": + for node in Selection.getAllSelectedObjects(): + if node.getBoundingBox().bottom < 0: + if not node.getDecorator(ZOffsetDecorator.ZOffsetDecorator): + node.addDecorator(ZOffsetDecorator.ZOffsetDecorator()) + + node.callDecoration("setZOffset", node.getBoundingBox().bottom) + else: + if node.getDecorator(ZOffsetDecorator.ZOffsetDecorator): + node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) + self._enabled = True self._onChangeTimerFinished() diff --git a/cura/ZOffsetDecorator.py b/cura/ZOffsetDecorator.py new file mode 100644 index 0000000000..54bf64b9a5 --- /dev/null +++ b/cura/ZOffsetDecorator.py @@ -0,0 +1,13 @@ +from UM.Scene.SceneNodeDecorator import SceneNodeDecorator + +## A decorator that stores the amount an object has been moved below the platform. +class ZOffsetDecorator(SceneNodeDecorator): + def __init__(self): + self._z_offset = 0 + + def setZOffset(self, offset): + print("setZOffset", offset) + self._z_offset = offset + + def getZOffset(self): + return self._z_offset