ExtruderOutputModel.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. isPreheatingChanged = pyqtSignal()
  17. def __init__(self, printer: "PrinterOutputModel", position, parent=None):
  18. super().__init__(parent)
  19. self._printer = printer
  20. self._position = position
  21. self._target_hotend_temperature = 0
  22. self._hotend_temperature = 0
  23. self._hotend_id = ""
  24. self._active_material = None # type: Optional[MaterialOutputModel]
  25. self._extruder_configuration = ExtruderConfigurationModel()
  26. self._extruder_configuration.position = self._position
  27. self._is_preheating = False
  28. def getPrinter(self):
  29. return self._printer
  30. def getPosition(self):
  31. return self._position
  32. # Does the printer support pre-heating the bed at all
  33. @pyqtProperty(bool, constant=True)
  34. def canPreHeatHotends(self):
  35. if self._printer:
  36. return self._printer.canPreHeatHotends
  37. return False
  38. @pyqtProperty(QObject, notify = activeMaterialChanged)
  39. def activeMaterial(self) -> "MaterialOutputModel":
  40. return self._active_material
  41. def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
  42. if self._active_material != material:
  43. self._active_material = material
  44. self._extruder_configuration.material = self._active_material
  45. self.activeMaterialChanged.emit()
  46. self.extruderConfigurationChanged.emit()
  47. ## Update the hotend temperature. This only changes it locally.
  48. def updateHotendTemperature(self, temperature: float):
  49. if self._hotend_temperature != temperature:
  50. self._hotend_temperature = temperature
  51. self.hotendTemperatureChanged.emit()
  52. def updateTargetHotendTemperature(self, temperature: float):
  53. if self._target_hotend_temperature != temperature:
  54. self._target_hotend_temperature = temperature
  55. self.targetHotendTemperatureChanged.emit()
  56. ## Set the target hotend temperature. This ensures that it's actually sent to the remote.
  57. @pyqtSlot(float)
  58. def setTargetHotendTemperature(self, temperature: float):
  59. self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
  60. self.updateTargetHotendTemperature(temperature)
  61. @pyqtProperty(float, notify = targetHotendTemperatureChanged)
  62. def targetHotendTemperature(self) -> float:
  63. return self._target_hotend_temperature
  64. @pyqtProperty(float, notify = hotendTemperatureChanged)
  65. def hotendTemperature(self) -> float:
  66. return self._hotend_temperature
  67. @pyqtProperty(str, notify = hotendIDChanged)
  68. def hotendID(self) -> str:
  69. return self._hotend_id
  70. def updateHotendID(self, id: str):
  71. if self._hotend_id != id:
  72. self._hotend_id = id
  73. self._extruder_configuration.hotendID = self._hotend_id
  74. self.hotendIDChanged.emit()
  75. self.extruderConfigurationChanged.emit()
  76. @pyqtProperty(QObject, notify = extruderConfigurationChanged)
  77. def extruderConfiguration(self):
  78. if self._extruder_configuration.isValid():
  79. return self._extruder_configuration
  80. return None
  81. def updateIsPreheating(self, pre_heating):
  82. if self._is_preheating != pre_heating:
  83. self._is_preheating = pre_heating
  84. self.isPreheatingChanged.emit()
  85. @pyqtProperty(bool, notify=isPreheatingChanged)
  86. def isPreheating(self):
  87. return self._is_preheating
  88. ## Pre-heats the extruder before printer.
  89. #
  90. # \param temperature The temperature to heat the extruder to, in degrees
  91. # Celsius.
  92. # \param duration How long the bed should stay warm, in seconds.
  93. @pyqtSlot(float, float)
  94. def preheatHotend(self, temperature, duration):
  95. self._printer._controller.preheatHotend(self, temperature, duration)
  96. @pyqtSlot()
  97. def cancelPreheatHotend(self):
  98. self._printer._controller.cancelPreheatHotend(self)