From 83315f13b32e325839836959a7558ebcc14eaa80 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 28 Oct 2016 15:07:35 +0200 Subject: [PATCH] SetParent now correctly uses transformations This is different from the old way of setting scale / rotation & position in sequence. The assumption in that case only held if all spaces had the same axis orientations (which is not the case for 3MF) Contributes to CURA-382 --- cura/SetParentOperation.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cura/SetParentOperation.py b/cura/SetParentOperation.py index c40ce54909..064ab5304c 100644 --- a/cura/SetParentOperation.py +++ b/cura/SetParentOperation.py @@ -32,14 +32,20 @@ class SetParentOperation(Operation.Operation): # \param new_parent The new parent. Note: this argument can be None, which would hide the node from the scene. def _set_parent(self, new_parent): if new_parent: - self._node.setPosition(self._node.getWorldPosition() - new_parent.getWorldPosition()) current_parent = self._node.getParent() if current_parent: - self._node.scale(current_parent.getScale() / new_parent.getScale()) - self._node.rotate(current_parent.getOrientation()) - else: - self._node.scale(Vector(1, 1, 1) / new_parent.getScale()) - self._node.rotate(new_parent.getOrientation().getInverse()) + # Based on the depth difference, we need to do something different. + depth_difference = current_parent.getDepth() - new_parent.getDepth() + child_transformation = self._node.getLocalTransformation() + if depth_difference > 0: + parent_transformation = current_parent.getLocalTransformation() + # A node in the chain was removed, so we need to squash the parent info into all the nodes, so positions remain the same. + self._node.setTransformation(parent_transformation.multiply(child_transformation)) + else: + # A node is inserted into the chain, so use the inverse of the parent to set the transformation of it's children. + parent_transformation = new_parent.getLocalTransformation() + result = parent_transformation.getInverse().multiply(child_transformation, copy = True) + self._node.setTransformation(result) self._node.setParent(new_parent)