SetObjectExtruderOperation.py 1.1 KB

123456789101112131415161718192021222324252627
  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 extruder a certain object should be printed with.
  7. class SetObjectExtruderOperation(Operation):
  8. def __init__(self, node: SceneNode, extruder_id: str) -> None:
  9. self._node = node
  10. self._extruder_id = extruder_id
  11. self._previous_extruder_id = None
  12. self._decorator_added = False
  13. def undo(self):
  14. if self._previous_extruder_id:
  15. self._node.callDecoration("setActiveExtruder", self._previous_extruder_id)
  16. def redo(self):
  17. stack = self._node.callDecoration("getStack") #Don't try to get the active extruder since it may be None anyway.
  18. if not stack:
  19. self._node.addDecorator(SettingOverrideDecorator())
  20. self._previous_extruder_id = self._node.callDecoration("getActiveExtruder")
  21. self._node.callDecoration("setActiveExtruder", self._extruder_id)