mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Refactored the config models so they they function are more stand alone units.
The seperation of concern got a bit mixed up, as the printer output model was connecting the signals that the config model needed to function together. With these changes it's now also possible to use the config model as a part of a printjob, since printjobs can also have a configuration
This commit is contained in:
parent
da23eff2a6
commit
86be07b095
4 changed files with 67 additions and 57 deletions
|
@ -12,64 +12,61 @@ if TYPE_CHECKING:
|
|||
|
||||
|
||||
class ExtruderOutputModel(QObject):
|
||||
hotendIDChanged = pyqtSignal()
|
||||
targetHotendTemperatureChanged = pyqtSignal()
|
||||
hotendTemperatureChanged = pyqtSignal()
|
||||
activeMaterialChanged = pyqtSignal()
|
||||
|
||||
extruderConfigurationChanged = pyqtSignal()
|
||||
isPreheatingChanged = pyqtSignal()
|
||||
|
||||
def __init__(self, printer: "PrinterOutputModel", position, parent=None) -> None:
|
||||
def __init__(self, printer: "PrinterOutputModel", position: int, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self._printer = printer
|
||||
self._printer = printer # type: PrinterOutputModel
|
||||
self._position = position
|
||||
self._target_hotend_temperature = 0 # type: float
|
||||
self._hotend_temperature = 0 # type: float
|
||||
self._hotend_id = ""
|
||||
self._active_material = None # type: Optional[MaterialOutputModel]
|
||||
self._extruder_configuration = ExtruderConfigurationModel()
|
||||
self._extruder_configuration.position = self._position
|
||||
self._target_hotend_temperature = 0 # type: float
|
||||
self._hotend_temperature = 0 # type: float
|
||||
|
||||
self._is_preheating = False
|
||||
|
||||
def getPrinter(self):
|
||||
# The extruder output model wraps the configuration model. This way we can use the same config model for jobs
|
||||
# and extruders alike.
|
||||
self._extruder_configuration = ExtruderConfigurationModel()
|
||||
self._extruder_configuration.position = self._position
|
||||
self._extruder_configuration.extruderConfigurationChanged.connect(self.extruderConfigurationChanged)
|
||||
|
||||
def getPrinter(self) -> "PrinterOutputModel":
|
||||
return self._printer
|
||||
|
||||
def getPosition(self):
|
||||
def getPosition(self) -> int:
|
||||
return self._position
|
||||
|
||||
# Does the printer support pre-heating the bed at all
|
||||
@pyqtProperty(bool, constant=True)
|
||||
def canPreHeatHotends(self):
|
||||
def canPreHeatHotends(self) -> bool:
|
||||
if self._printer:
|
||||
return self._printer.canPreHeatHotends
|
||||
return False
|
||||
|
||||
@pyqtProperty(QObject, notify = activeMaterialChanged)
|
||||
@pyqtProperty(QObject, notify = extruderConfigurationChanged)
|
||||
def activeMaterial(self) -> Optional["MaterialOutputModel"]:
|
||||
return self._active_material
|
||||
return self._extruder_configuration.material
|
||||
|
||||
def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
|
||||
if self._active_material != material:
|
||||
self._active_material = material
|
||||
self._extruder_configuration.material = self._active_material
|
||||
self.activeMaterialChanged.emit()
|
||||
self.extruderConfigurationChanged.emit()
|
||||
self._extruder_configuration.setMaterial(material)
|
||||
|
||||
## Update the hotend temperature. This only changes it locally.
|
||||
def updateHotendTemperature(self, temperature: float):
|
||||
def updateHotendTemperature(self, temperature: float) -> None:
|
||||
if self._hotend_temperature != temperature:
|
||||
self._hotend_temperature = temperature
|
||||
self.hotendTemperatureChanged.emit()
|
||||
|
||||
def updateTargetHotendTemperature(self, temperature: float):
|
||||
def updateTargetHotendTemperature(self, temperature: float) -> None:
|
||||
if self._target_hotend_temperature != temperature:
|
||||
self._target_hotend_temperature = temperature
|
||||
self.targetHotendTemperatureChanged.emit()
|
||||
|
||||
## Set the target hotend temperature. This ensures that it's actually sent to the remote.
|
||||
@pyqtSlot(float)
|
||||
def setTargetHotendTemperature(self, temperature: float):
|
||||
def setTargetHotendTemperature(self, temperature: float) -> None:
|
||||
self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
|
||||
self.updateTargetHotendTemperature(temperature)
|
||||
|
||||
|
@ -81,30 +78,26 @@ class ExtruderOutputModel(QObject):
|
|||
def hotendTemperature(self) -> float:
|
||||
return self._hotend_temperature
|
||||
|
||||
@pyqtProperty(str, notify = hotendIDChanged)
|
||||
@pyqtProperty(str, notify = extruderConfigurationChanged)
|
||||
def hotendID(self) -> str:
|
||||
return self._hotend_id
|
||||
return self._extruder_configuration.hotendID
|
||||
|
||||
def updateHotendID(self, id: str):
|
||||
if self._hotend_id != id:
|
||||
self._hotend_id = id
|
||||
self._extruder_configuration.hotendID = self._hotend_id
|
||||
self.hotendIDChanged.emit()
|
||||
self.extruderConfigurationChanged.emit()
|
||||
def updateHotendID(self, hotend_id: str) -> None:
|
||||
self._extruder_configuration.setHotendID(hotend_id)
|
||||
|
||||
@pyqtProperty(QObject, notify = extruderConfigurationChanged)
|
||||
def extruderConfiguration(self):
|
||||
def extruderConfiguration(self) -> Optional[ExtruderConfigurationModel]:
|
||||
if self._extruder_configuration.isValid():
|
||||
return self._extruder_configuration
|
||||
return None
|
||||
|
||||
def updateIsPreheating(self, pre_heating):
|
||||
def updateIsPreheating(self, pre_heating: bool) -> None:
|
||||
if self._is_preheating != pre_heating:
|
||||
self._is_preheating = pre_heating
|
||||
self.isPreheatingChanged.emit()
|
||||
|
||||
@pyqtProperty(bool, notify=isPreheatingChanged)
|
||||
def isPreheating(self):
|
||||
def isPreheating(self) -> bool:
|
||||
return self._is_preheating
|
||||
|
||||
## Pre-heats the extruder before printer.
|
||||
|
@ -113,9 +106,9 @@ class ExtruderOutputModel(QObject):
|
|||
# Celsius.
|
||||
# \param duration How long the bed should stay warm, in seconds.
|
||||
@pyqtSlot(float, float)
|
||||
def preheatHotend(self, temperature, duration):
|
||||
def preheatHotend(self, temperature: float, duration: float) -> None:
|
||||
self._printer._controller.preheatHotend(self, temperature, duration)
|
||||
|
||||
@pyqtSlot()
|
||||
def cancelPreheatHotend(self):
|
||||
def cancelPreheatHotend(self) -> None:
|
||||
self._printer._controller.cancelPreheatHotend(self)
|
Loading…
Add table
Add a link
Reference in a new issue