From d650cbe26ce0fcc4c5146466d2827b930c153b0f Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 24 Mar 2015 17:02:58 +0100 Subject: [PATCH] Use GroupedOperation for merging PlatformPhyisicsOperation --- PlatformPhysicsOperation.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/PlatformPhysicsOperation.py b/PlatformPhysicsOperation.py index 40ce20d453..70363b3b08 100644 --- a/PlatformPhysicsOperation.py +++ b/PlatformPhysicsOperation.py @@ -1,27 +1,30 @@ from UM.Operations.Operation import Operation from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation from UM.Operations.TranslateOperation import TranslateOperation +from UM.Operations.GroupedOperation import GroupedOperation ## A specialised operation designed specifically to modify the previous operation. class PlatformPhysicsOperation(Operation): def __init__(self, node, translation): super().__init__() self._node = node - self._translation = translation + self._transform = node.getLocalTransformation() + self._position = node.getPosition() + translation + self._always_merge = True def undo(self): - pass + self._node.setLocalTransformation(self._transform) def redo(self): - pass + self._node.setPosition(self._position) def mergeWith(self, other): - if type(other) is AddSceneNodeOperation: - other._node.translate(self._translation) - return other - elif type(other) is TranslateOperation: - other._translation += self._translation - return other - else: - return False + group = GroupedOperation() + group.addOperation(self) + group.addOperation(other) + + return group + + def __repr__(self): + return 'PlatformPhysicsOperation(t = {0})'.format(self._position)