PlatformPhysicsOperation.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Math.Vector import Vector
  4. from UM.Operations.Operation import Operation
  5. from UM.Operations.GroupedOperation import GroupedOperation
  6. from UM.Scene.SceneNode import SceneNode
  7. class PlatformPhysicsOperation(Operation):
  8. """A specialised operation designed specifically to modify the previous operation."""
  9. def __init__(self, node: SceneNode, translation: Vector) -> None:
  10. super().__init__()
  11. self._node = node
  12. self._old_transformation = node.getLocalTransformation()
  13. self._translation = translation
  14. self._always_merge = True
  15. def undo(self) -> None:
  16. self._node.setTransformation(self._old_transformation)
  17. def redo(self) -> None:
  18. self._node.translate(self._translation, SceneNode.TransformSpace.World)
  19. def mergeWith(self, other: Operation) -> GroupedOperation:
  20. group = GroupedOperation()
  21. group.addOperation(other)
  22. group.addOperation(self)
  23. return group
  24. def __repr__(self) -> str:
  25. return "PlatformPhysicsOp.(trans.={0})".format(self._translation)