ExtruderOutputModel.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, pyqtSlot
  4. from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
  5. from typing import Optional
  6. MYPY = False
  7. if MYPY:
  8. from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
  9. from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
  10. class ExtruderOutputModel(QObject):
  11. hotendIDChanged = pyqtSignal()
  12. targetHotendTemperatureChanged = pyqtSignal()
  13. hotendTemperatureChanged = pyqtSignal()
  14. activeMaterialChanged = pyqtSignal()
  15. extruderConfigurationChanged = pyqtSignal()
  16. def __init__(self, printer: "PrinterOutputModel", position, parent=None):
  17. super().__init__(parent)
  18. self._printer = printer
  19. self._position = position
  20. self._target_hotend_temperature = 0
  21. self._hotend_temperature = 0
  22. self._hotend_id = ""
  23. self._active_material = None # type: Optional[MaterialOutputModel]
  24. self._extruder_configuration = ExtruderConfigurationModel()
  25. # Update the configuration every time the hotend or the active material change
  26. self.hotendIDChanged.connect(self._updateExtruderConfiguration)
  27. self.activeMaterialChanged.connect(self._updateExtruderConfiguration)
  28. @pyqtProperty(QObject, notify = activeMaterialChanged)
  29. def activeMaterial(self) -> "MaterialOutputModel":
  30. return self._active_material
  31. def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
  32. if self._active_material != material:
  33. self._active_material = material
  34. self.activeMaterialChanged.emit()
  35. ## Update the hotend temperature. This only changes it locally.
  36. def updateHotendTemperature(self, temperature: float):
  37. if self._hotend_temperature != temperature:
  38. self._hotend_temperature = temperature
  39. self.hotendTemperatureChanged.emit()
  40. def updateTargetHotendTemperature(self, temperature: float):
  41. if self._target_hotend_temperature != temperature:
  42. self._target_hotend_temperature = temperature
  43. self.targetHotendTemperatureChanged.emit()
  44. ## Set the target hotend temperature. This ensures that it's actually sent to the remote.
  45. @pyqtSlot(float)
  46. def setTargetHotendTemperature(self, temperature: float):
  47. self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
  48. self.updateTargetHotendTemperature(temperature)
  49. @pyqtProperty(float, notify = targetHotendTemperatureChanged)
  50. def targetHotendTemperature(self) -> float:
  51. return self._target_hotend_temperature
  52. @pyqtProperty(float, notify=hotendTemperatureChanged)
  53. def hotendTemperature(self) -> float:
  54. return self._hotend_temperature
  55. @pyqtProperty(str, notify = hotendIDChanged)
  56. def hotendID(self) -> str:
  57. return self._hotend_id
  58. def updateHotendID(self, id: str):
  59. if self._hotend_id != id:
  60. self._hotend_id = id
  61. self.hotendIDChanged.emit()
  62. @pyqtProperty(QObject, notify = extruderConfigurationChanged)
  63. def extruderConfiguration(self):
  64. return self._extruder_configuration
  65. def _updateExtruderConfiguration(self):
  66. self._extruder_configuration.position = self._position
  67. self._extruder_configuration.material = self._active_material
  68. self._extruder_configuration.hotendID = self._hotend_id
  69. self.extruderConfigurationChanged.emit()