ExtruderOutputModel.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, TYPE_CHECKING
  6. if TYPE_CHECKING:
  7. from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
  8. from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
  9. class ExtruderOutputModel(QObject):
  10. targetHotendTemperatureChanged = pyqtSignal()
  11. hotendTemperatureChanged = pyqtSignal()
  12. extruderConfigurationChanged = pyqtSignal()
  13. isPreheatingChanged = pyqtSignal()
  14. def __init__(self, printer: "PrinterOutputModel", position: int, parent=None) -> None:
  15. super().__init__(parent)
  16. self._printer = printer # type: PrinterOutputModel
  17. self._position = position
  18. self._target_hotend_temperature = 0.0 # type: float
  19. self._hotend_temperature = 0.0 # type: float
  20. self._is_preheating = False
  21. # The extruder output model wraps the configuration model. This way we can use the same config model for jobs
  22. # and extruders alike.
  23. self._extruder_configuration = ExtruderConfigurationModel()
  24. self._extruder_configuration.position = self._position
  25. self._extruder_configuration.extruderConfigurationChanged.connect(self.extruderConfigurationChanged)
  26. def getPrinter(self) -> "PrinterOutputModel":
  27. return self._printer
  28. def getPosition(self) -> int:
  29. return self._position
  30. # Does the printer support pre-heating the bed at all
  31. @pyqtProperty(bool, constant=True)
  32. def canPreHeatHotends(self) -> bool:
  33. if self._printer:
  34. return self._printer.canPreHeatHotends
  35. return False
  36. @pyqtProperty(QObject, notify = extruderConfigurationChanged)
  37. def activeMaterial(self) -> Optional["MaterialOutputModel"]:
  38. return self._extruder_configuration.activeMaterial
  39. def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]) -> None:
  40. self._extruder_configuration.setMaterial(material)
  41. ## Update the hotend temperature. This only changes it locally.
  42. def updateHotendTemperature(self, temperature: float) -> None:
  43. if self._hotend_temperature != temperature:
  44. self._hotend_temperature = temperature
  45. self.hotendTemperatureChanged.emit()
  46. def updateTargetHotendTemperature(self, temperature: float) -> None:
  47. if self._target_hotend_temperature != temperature:
  48. self._target_hotend_temperature = temperature
  49. self.targetHotendTemperatureChanged.emit()
  50. ## Set the target hotend temperature. This ensures that it's actually sent to the remote.
  51. @pyqtSlot(float)
  52. def setTargetHotendTemperature(self, temperature: float) -> None:
  53. self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
  54. self.updateTargetHotendTemperature(temperature)
  55. @pyqtProperty(float, notify = targetHotendTemperatureChanged)
  56. def targetHotendTemperature(self) -> float:
  57. return self._target_hotend_temperature
  58. @pyqtProperty(float, notify = hotendTemperatureChanged)
  59. def hotendTemperature(self) -> float:
  60. return self._hotend_temperature
  61. @pyqtProperty(str, notify = extruderConfigurationChanged)
  62. def hotendID(self) -> str:
  63. return self._extruder_configuration.hotendID
  64. def updateHotendID(self, hotend_id: str) -> None:
  65. self._extruder_configuration.setHotendID(hotend_id)
  66. @pyqtProperty(QObject, notify = extruderConfigurationChanged)
  67. def extruderConfiguration(self) -> Optional[ExtruderConfigurationModel]:
  68. if self._extruder_configuration.isValid():
  69. return self._extruder_configuration
  70. return None
  71. def updateIsPreheating(self, pre_heating: bool) -> None:
  72. if self._is_preheating != pre_heating:
  73. self._is_preheating = pre_heating
  74. self.isPreheatingChanged.emit()
  75. @pyqtProperty(bool, notify=isPreheatingChanged)
  76. def isPreheating(self) -> bool:
  77. return self._is_preheating
  78. ## Pre-heats the extruder before printer.
  79. #
  80. # \param temperature The temperature to heat the extruder to, in degrees
  81. # Celsius.
  82. # \param duration How long the bed should stay warm, in seconds.
  83. @pyqtSlot(float, float)
  84. def preheatHotend(self, temperature: float, duration: float) -> None:
  85. self._printer._controller.preheatHotend(self, temperature, duration)
  86. @pyqtSlot()
  87. def cancelPreheatHotend(self) -> None:
  88. self._printer._controller.cancelPreheatHotend(self)