PlatformPhysicsOperation.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from UM.Operations.Operation import Operation
  4. from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
  5. from UM.Operations.TranslateOperation import TranslateOperation
  6. from UM.Operations.GroupedOperation import GroupedOperation
  7. ## A specialised operation designed specifically to modify the previous operation.
  8. class PlatformPhysicsOperation(Operation):
  9. def __init__(self, node, translation):
  10. super().__init__()
  11. self._node = node
  12. self._old_position = node.getPosition()
  13. self._new_position = node.getPosition() + translation
  14. self._always_merge = True
  15. def undo(self):
  16. self._node.setPosition(self._old_position)
  17. def redo(self):
  18. self._node.setPosition(self._new_position)
  19. def mergeWith(self, other):
  20. group = GroupedOperation()
  21. group.addOperation(self)
  22. group.addOperation(other)
  23. return group
  24. def __repr__(self):
  25. return "PlatformPhysicsOperation(t = {0})".format(self._position)