SetBuildPlateNumberOperation.py 1.2 KB

1234567891011121314151617181920212223242526272829
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Scene.SceneNode import SceneNode
  4. from UM.Operations.Operation import Operation
  5. from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator
  6. ## Simple operation to set the buildplate number of a scenenode.
  7. class SetBuildPlateNumberOperation(Operation):
  8. def __init__(self, node: SceneNode, build_plate_nr: int) -> None:
  9. super().__init__()
  10. self._node = node
  11. self._build_plate_nr = build_plate_nr
  12. self._previous_build_plate_nr = None
  13. self._decorator_added = False
  14. def undo(self):
  15. if self._previous_build_plate_nr:
  16. self._node.callDecoration("setBuildPlateNumber", self._previous_build_plate_nr)
  17. def redo(self):
  18. stack = self._node.callDecoration("getStack") #Don't try to get the active extruder since it may be None anyway.
  19. if not stack:
  20. self._node.addDecorator(SettingOverrideDecorator())
  21. self._previous_build_plate_nr = self._node.callDecoration("getBuildPlateNumber")
  22. self._node.callDecoration("setBuildPlateNumber", self._build_plate_nr)