BuildPlateModel.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot
  2. from UM.Qt.ListModel import ListModel
  3. from UM.Scene.Selection import Selection
  4. from UM.Logger import Logger
  5. from UM.Application import Application
  6. class BuildPlateModel(ListModel):
  7. maxBuildPlateChanged = pyqtSignal()
  8. activeBuildPlateChanged = pyqtSignal()
  9. selectionChanged = pyqtSignal()
  10. def __init__(self):
  11. super().__init__()
  12. Application.getInstance().getController().getScene().sceneChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
  13. Selection.selectionChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
  14. self._max_build_plate = 1 # default
  15. self._active_build_plate = -1
  16. self._selection_build_plates = []
  17. def setMaxBuildPlate(self, max_build_plate):
  18. self._max_build_plate = max_build_plate
  19. self.maxBuildPlateChanged.emit()
  20. ## Return the highest build plate number
  21. @pyqtProperty(int, notify = maxBuildPlateChanged)
  22. def maxBuildPlate(self):
  23. return self._max_build_plate
  24. def setActiveBuildPlate(self, nr):
  25. self._active_build_plate = nr
  26. self.activeBuildPlateChanged.emit()
  27. @pyqtProperty(int, notify = activeBuildPlateChanged)
  28. def activeBuildPlate(self):
  29. return self._active_build_plate
  30. @staticmethod
  31. def createBuildPlateModel():
  32. return BuildPlateModel()
  33. def _updateSelectedObjectBuildPlateNumbers(self, *args):
  34. result = set()
  35. for node in Selection.getAllSelectedObjects():
  36. result.add(node.callDecoration("getBuildPlateNumber"))
  37. self._selection_build_plates = list(result)
  38. self.selectionChanged.emit()
  39. @pyqtProperty("QVariantList", notify = selectionChanged)
  40. def selectionBuildPlates(self):
  41. return self._selection_build_plates