MultiBuildPlateModel.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import QTimer, pyqtSignal, pyqtProperty
  4. from UM.Application import Application
  5. from UM.Scene.Selection import Selection
  6. from UM.Qt.ListModel import ListModel
  7. #
  8. # This is the model for multi build plate feature.
  9. # This has nothing to do with the build plate types you can choose on the sidebar for a machine.
  10. #
  11. class MultiBuildPlateModel(ListModel):
  12. maxBuildPlateChanged = pyqtSignal()
  13. activeBuildPlateChanged = pyqtSignal()
  14. selectionChanged = pyqtSignal()
  15. def __init__(self, parent = None):
  16. super().__init__(parent)
  17. self._update_timer = QTimer()
  18. self._update_timer.setInterval(100)
  19. self._update_timer.setSingleShot(True)
  20. self._update_timer.timeout.connect(self._updateSelectedObjectBuildPlateNumbers)
  21. self._application = Application.getInstance()
  22. self._application.getController().getScene().sceneChanged.connect(self._updateSelectedObjectBuildPlateNumbersDelayed)
  23. Selection.selectionChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
  24. self._max_build_plate = 1 # default
  25. self._active_build_plate = -1
  26. def setMaxBuildPlate(self, max_build_plate):
  27. self._max_build_plate = max_build_plate
  28. self.maxBuildPlateChanged.emit()
  29. ## Return the highest build plate number
  30. @pyqtProperty(int, notify = maxBuildPlateChanged)
  31. def maxBuildPlate(self):
  32. return self._max_build_plate
  33. def setActiveBuildPlate(self, nr):
  34. self._active_build_plate = nr
  35. self.activeBuildPlateChanged.emit()
  36. @pyqtProperty(int, notify = activeBuildPlateChanged)
  37. def activeBuildPlate(self):
  38. return self._active_build_plate
  39. def _updateSelectedObjectBuildPlateNumbersDelayed(self, *args):
  40. self._update_timer.start()
  41. def _updateSelectedObjectBuildPlateNumbers(self, *args):
  42. result = set()
  43. for node in Selection.getAllSelectedObjects():
  44. result.add(node.callDecoration("getBuildPlateNumber"))
  45. self._selection_build_plates = list(result)
  46. self.selectionChanged.emit()
  47. @pyqtProperty("QVariantList", notify = selectionChanged)
  48. def selectionBuildPlates(self):
  49. return self._selection_build_plates