UMOUpgradeSelection.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Uranium is released under the terms of the AGPLv3 or higher.
  3. from UM.Settings.ContainerRegistry import ContainerRegistry
  4. from UM.Settings.InstanceContainer import InstanceContainer
  5. from cura.MachineAction import MachineAction
  6. from PyQt5.QtCore import pyqtSlot, pyqtSignal, pyqtProperty
  7. from UM.i18n import i18nCatalog
  8. from UM.Application import Application
  9. catalog = i18nCatalog("cura")
  10. import UM.Settings.InstanceContainer
  11. ## The Ultimaker Original can have a few revisions & upgrades. This action helps with selecting them, so they are added
  12. # as a variant.
  13. class UMOUpgradeSelection(MachineAction):
  14. def __init__(self):
  15. super().__init__("UMOUpgradeSelection", catalog.i18nc("@action", "Select upgrades"))
  16. self._qml_url = "UMOUpgradeSelectionMachineAction.qml"
  17. def _reset(self):
  18. self.heatedBedChanged.emit()
  19. heatedBedChanged = pyqtSignal()
  20. @pyqtProperty(bool, notify = heatedBedChanged)
  21. def hasHeatedBed(self):
  22. global_container_stack = Application.getInstance().getGlobalContainerStack()
  23. if global_container_stack:
  24. return global_container_stack.getProperty("machine_heated_bed", "value")
  25. @pyqtSlot(bool)
  26. def setHeatedBed(self, heated_bed = True):
  27. global_container_stack = Application.getInstance().getGlobalContainerStack()
  28. if global_container_stack:
  29. # Make sure there is a definition_changes container to store the machine settings
  30. definition_changes_container = global_container_stack.findContainer({"type": "definition_changes"})
  31. if not definition_changes_container:
  32. definition_changes_container = self._createDefinitionChangesContainer(global_container_stack)
  33. definition_changes_container.setProperty("machine_heated_bed", "value", heated_bed)
  34. self.heatedBedChanged.emit()
  35. def _createDefinitionChangesContainer(self, global_container_stack):
  36. # Create a definition_changes container to store the settings in and add it to the stack
  37. definition_changes_container = UM.Settings.InstanceContainer.InstanceContainer(global_container_stack.getName() + "_settings")
  38. definition = global_container_stack.getBottom()
  39. definition_changes_container.setDefinition(definition)
  40. definition_changes_container.addMetaDataEntry("type", "definition_changes")
  41. UM.Settings.ContainerRegistry.ContainerRegistry.getInstance().addContainer(definition_changes_container)
  42. # Insert definition_changes between the definition and the variant
  43. global_container_stack.insertContainer(-1, definition_changes_container)
  44. return definition_changes_container