123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- from UM.Scene.SceneNode import SceneNode
- from UM.Operations import Operation
- from UM.Math.Vector import Vector
- class SetParentOperation(Operation.Operation):
-
-
-
-
- def __init__(self, node, parent_node):
- super().__init__()
- self._node = node
- self._parent = parent_node
- self._old_parent = node.getParent()
-
- def undo(self):
- self._set_parent(self._old_parent)
-
- def redo(self):
- self._set_parent(self._parent)
-
-
-
- def _set_parent(self, new_parent):
- if new_parent:
- current_parent = self._node.getParent()
- if current_parent:
-
-
-
- old_parent = new_parent.callDecoration("getOldParent")
- if old_parent:
- new_parent.callDecoration("getNode").setParent(old_parent)
-
- depth_difference = current_parent.getDepth() - new_parent.getDepth()
- child_transformation = self._node.getLocalTransformation()
- if depth_difference > 0:
- parent_transformation = current_parent.getLocalTransformation()
-
- self._node.setTransformation(parent_transformation.multiply(child_transformation))
- else:
-
- parent_transformation = new_parent.getLocalTransformation()
- result = parent_transformation.getInverse().multiply(child_transformation, copy = True)
- self._node.setTransformation(result)
- self._node.setParent(new_parent)
-
-
-
- def __repr__(self):
- return "SetParentOperation(node = {0}, parent_node={1})".format(self._node, self._parent)
|