mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
Use GroupedOperation for merging PlatformPhyisicsOperation
This commit is contained in:
parent
0c606c4d6f
commit
d650cbe26c
1 changed files with 14 additions and 11 deletions
|
@ -1,27 +1,30 @@
|
||||||
from UM.Operations.Operation import Operation
|
from UM.Operations.Operation import Operation
|
||||||
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
|
||||||
from UM.Operations.TranslateOperation import TranslateOperation
|
from UM.Operations.TranslateOperation import TranslateOperation
|
||||||
|
from UM.Operations.GroupedOperation import GroupedOperation
|
||||||
|
|
||||||
## A specialised operation designed specifically to modify the previous operation.
|
## A specialised operation designed specifically to modify the previous operation.
|
||||||
class PlatformPhysicsOperation(Operation):
|
class PlatformPhysicsOperation(Operation):
|
||||||
def __init__(self, node, translation):
|
def __init__(self, node, translation):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._node = node
|
self._node = node
|
||||||
self._translation = translation
|
self._transform = node.getLocalTransformation()
|
||||||
|
self._position = node.getPosition() + translation
|
||||||
|
self._always_merge = True
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
pass
|
self._node.setLocalTransformation(self._transform)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
pass
|
self._node.setPosition(self._position)
|
||||||
|
|
||||||
def mergeWith(self, other):
|
def mergeWith(self, other):
|
||||||
if type(other) is AddSceneNodeOperation:
|
group = GroupedOperation()
|
||||||
other._node.translate(self._translation)
|
|
||||||
return other
|
|
||||||
elif type(other) is TranslateOperation:
|
|
||||||
other._translation += self._translation
|
|
||||||
return other
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
group.addOperation(self)
|
||||||
|
group.addOperation(other)
|
||||||
|
|
||||||
|
return group
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return 'PlatformPhysicsOperation(t = {0})'.format(self._position)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue