mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -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
|
@ -27,8 +27,14 @@ class ConfigurationModel(QObject):
|
|||
return self._printer_type
|
||||
|
||||
def setExtruderConfigurations(self, extruder_configurations):
|
||||
if self._extruder_configurations != extruder_configurations:
|
||||
self._extruder_configurations = extruder_configurations
|
||||
|
||||
for extruder_configuration in self._extruder_configurations:
|
||||
extruder_configuration.extruderConfigurationChanged.connect(self.configurationChanged)
|
||||
|
||||
self.configurationChanged.emit()
|
||||
|
||||
@pyqtProperty("QVariantList", fset = setExtruderConfigurations, notify = configurationChanged)
|
||||
def extruderConfigurations(self):
|
||||
return self._extruder_configurations
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
from typing import Optional
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
|
||||
|
||||
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
||||
|
||||
|
||||
class ExtruderConfigurationModel(QObject):
|
||||
|
||||
|
@ -10,38 +13,42 @@ class ExtruderConfigurationModel(QObject):
|
|||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._position = -1
|
||||
self._material = None
|
||||
self._hotend_id = None
|
||||
self._position = -1 # type: int
|
||||
self._material = None # type: Optional[MaterialOutputModel]
|
||||
self._hotend_id = None # type: Optional[str]
|
||||
|
||||
def setPosition(self, position):
|
||||
def setPosition(self, position: int) -> None:
|
||||
self._position = position
|
||||
|
||||
@pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
|
||||
def position(self):
|
||||
def position(self) -> int:
|
||||
return self._position
|
||||
|
||||
def setMaterial(self, material):
|
||||
def setMaterial(self, material: Optional[MaterialOutputModel]):
|
||||
if self._hotend_id != material:
|
||||
self._material = material
|
||||
self.extruderConfigurationChanged.emit()
|
||||
|
||||
@pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
|
||||
def material(self):
|
||||
def material(self) -> MaterialOutputModel:
|
||||
return self._material
|
||||
|
||||
def setHotendID(self, hotend_id):
|
||||
def setHotendID(self, hotend_id: Optional[str]) -> None:
|
||||
if self._hotend_id != hotend_id:
|
||||
self._hotend_id = hotend_id
|
||||
self.extruderConfigurationChanged.emit()
|
||||
|
||||
@pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
|
||||
def hotendID(self):
|
||||
def hotendID(self) -> Optional[str]:
|
||||
return self._hotend_id
|
||||
|
||||
## This method is intended to indicate whether the configuration is valid or not.
|
||||
# The method checks if the mandatory fields are or not set
|
||||
# At this moment is always valid since we allow to have empty material and variants.
|
||||
def isValid(self):
|
||||
def isValid(self) -> bool:
|
||||
return True
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
message_chunks = []
|
||||
message_chunks.append("Position: " + str(self._position))
|
||||
message_chunks.append("-")
|
||||
|
@ -50,7 +57,7 @@ class ExtruderConfigurationModel(QObject):
|
|||
message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
|
||||
return " ".join(message_chunks)
|
||||
|
||||
def __eq__(self, other):
|
||||
def __eq__(self, other) -> bool:
|
||||
return hash(self) == hash(other)
|
||||
|
||||
# Calculating a hash function using the position of the extruder, the material GUID and the hotend id to check if is
|
||||
|
|
|
@ -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._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)
|
|
@ -43,9 +43,13 @@ class PrinterOutputModel(QObject):
|
|||
self._is_preheating = False
|
||||
self._printer_type = ""
|
||||
self._buildplate_name = None
|
||||
# Update the printer configuration every time any of the extruders changes its configuration
|
||||
for extruder in self._extruders:
|
||||
extruder.extruderConfigurationChanged.connect(self._updateExtruderConfiguration)
|
||||
|
||||
|
||||
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in
|
||||
self._extruders]
|
||||
|
||||
#for extruder_configuration in self._printer_configuration.extruderConfigurations:
|
||||
# extruder_configuration.extruderConfigurationChanged.connect(self.configurationChanged)
|
||||
|
||||
self._camera = None
|
||||
|
||||
|
@ -284,6 +288,6 @@ class PrinterOutputModel(QObject):
|
|||
return self._printer_configuration
|
||||
return None
|
||||
|
||||
def _updateExtruderConfiguration(self):
|
||||
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders]
|
||||
self.configurationChanged.emit()
|
||||
#def _updateExtruderConfiguration(self):
|
||||
|
||||
#self.configurationChanged.emit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue