mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 15:07: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
|
return self._printer_type
|
||||||
|
|
||||||
def setExtruderConfigurations(self, extruder_configurations):
|
def setExtruderConfigurations(self, extruder_configurations):
|
||||||
|
if self._extruder_configurations != extruder_configurations:
|
||||||
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)
|
@pyqtProperty("QVariantList", fset = setExtruderConfigurations, notify = configurationChanged)
|
||||||
def extruderConfigurations(self):
|
def extruderConfigurations(self):
|
||||||
return self._extruder_configurations
|
return self._extruder_configurations
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
|
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
|
||||||
|
|
||||||
|
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
|
||||||
|
|
||||||
|
|
||||||
class ExtruderConfigurationModel(QObject):
|
class ExtruderConfigurationModel(QObject):
|
||||||
|
|
||||||
|
@ -10,38 +13,42 @@ class ExtruderConfigurationModel(QObject):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._position = -1
|
self._position = -1 # type: int
|
||||||
self._material = None
|
self._material = None # type: Optional[MaterialOutputModel]
|
||||||
self._hotend_id = None
|
self._hotend_id = None # type: Optional[str]
|
||||||
|
|
||||||
def setPosition(self, position):
|
def setPosition(self, position: int) -> None:
|
||||||
self._position = position
|
self._position = position
|
||||||
|
|
||||||
@pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
|
@pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
|
||||||
def position(self):
|
def position(self) -> int:
|
||||||
return self._position
|
return self._position
|
||||||
|
|
||||||
def setMaterial(self, material):
|
def setMaterial(self, material: Optional[MaterialOutputModel]):
|
||||||
|
if self._hotend_id != material:
|
||||||
self._material = material
|
self._material = material
|
||||||
|
self.extruderConfigurationChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
|
@pyqtProperty(QObject, fset = setMaterial, notify = extruderConfigurationChanged)
|
||||||
def material(self):
|
def material(self) -> MaterialOutputModel:
|
||||||
return self._material
|
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._hotend_id = hotend_id
|
||||||
|
self.extruderConfigurationChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
|
@pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
|
||||||
def hotendID(self):
|
def hotendID(self) -> Optional[str]:
|
||||||
return self._hotend_id
|
return self._hotend_id
|
||||||
|
|
||||||
## This method is intended to indicate whether the configuration is valid or not.
|
## This method is intended to indicate whether the configuration is valid or not.
|
||||||
# The method checks if the mandatory fields are or not set
|
# 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.
|
# At this moment is always valid since we allow to have empty material and variants.
|
||||||
def isValid(self):
|
def isValid(self) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
message_chunks = []
|
message_chunks = []
|
||||||
message_chunks.append("Position: " + str(self._position))
|
message_chunks.append("Position: " + str(self._position))
|
||||||
message_chunks.append("-")
|
message_chunks.append("-")
|
||||||
|
@ -50,7 +57,7 @@ class ExtruderConfigurationModel(QObject):
|
||||||
message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
|
message_chunks.append("HotendID: " + self.hotendID if self.hotendID else "empty")
|
||||||
return " ".join(message_chunks)
|
return " ".join(message_chunks)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other) -> bool:
|
||||||
return hash(self) == hash(other)
|
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
|
# 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):
|
class ExtruderOutputModel(QObject):
|
||||||
hotendIDChanged = pyqtSignal()
|
|
||||||
targetHotendTemperatureChanged = pyqtSignal()
|
targetHotendTemperatureChanged = pyqtSignal()
|
||||||
hotendTemperatureChanged = pyqtSignal()
|
hotendTemperatureChanged = pyqtSignal()
|
||||||
activeMaterialChanged = pyqtSignal()
|
|
||||||
extruderConfigurationChanged = pyqtSignal()
|
extruderConfigurationChanged = pyqtSignal()
|
||||||
isPreheatingChanged = 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)
|
super().__init__(parent)
|
||||||
self._printer = printer
|
self._printer = printer # type: PrinterOutputModel
|
||||||
self._position = position
|
self._position = position
|
||||||
self._target_hotend_temperature = 0 # type: float
|
self._target_hotend_temperature = 0 # type: float
|
||||||
self._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
|
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
|
return self._printer
|
||||||
|
|
||||||
def getPosition(self):
|
def getPosition(self) -> int:
|
||||||
return self._position
|
return self._position
|
||||||
|
|
||||||
# Does the printer support pre-heating the bed at all
|
# Does the printer support pre-heating the bed at all
|
||||||
@pyqtProperty(bool, constant=True)
|
@pyqtProperty(bool, constant=True)
|
||||||
def canPreHeatHotends(self):
|
def canPreHeatHotends(self) -> bool:
|
||||||
if self._printer:
|
if self._printer:
|
||||||
return self._printer.canPreHeatHotends
|
return self._printer.canPreHeatHotends
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify = activeMaterialChanged)
|
@pyqtProperty(QObject, notify = extruderConfigurationChanged)
|
||||||
def activeMaterial(self) -> Optional["MaterialOutputModel"]:
|
def activeMaterial(self) -> Optional["MaterialOutputModel"]:
|
||||||
return self._active_material
|
return self._extruder_configuration.material
|
||||||
|
|
||||||
def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
|
def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
|
||||||
if self._active_material != material:
|
self._extruder_configuration.setMaterial(material)
|
||||||
self._active_material = material
|
|
||||||
self._extruder_configuration.material = self._active_material
|
|
||||||
self.activeMaterialChanged.emit()
|
|
||||||
self.extruderConfigurationChanged.emit()
|
|
||||||
|
|
||||||
## Update the hotend temperature. This only changes it locally.
|
## 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:
|
if self._hotend_temperature != temperature:
|
||||||
self._hotend_temperature = temperature
|
self._hotend_temperature = temperature
|
||||||
self.hotendTemperatureChanged.emit()
|
self.hotendTemperatureChanged.emit()
|
||||||
|
|
||||||
def updateTargetHotendTemperature(self, temperature: float):
|
def updateTargetHotendTemperature(self, temperature: float) -> None:
|
||||||
if self._target_hotend_temperature != temperature:
|
if self._target_hotend_temperature != temperature:
|
||||||
self._target_hotend_temperature = temperature
|
self._target_hotend_temperature = temperature
|
||||||
self.targetHotendTemperatureChanged.emit()
|
self.targetHotendTemperatureChanged.emit()
|
||||||
|
|
||||||
## Set the target hotend temperature. This ensures that it's actually sent to the remote.
|
## Set the target hotend temperature. This ensures that it's actually sent to the remote.
|
||||||
@pyqtSlot(float)
|
@pyqtSlot(float)
|
||||||
def setTargetHotendTemperature(self, temperature: float):
|
def setTargetHotendTemperature(self, temperature: float) -> None:
|
||||||
self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
|
self._printer.getController().setTargetHotendTemperature(self._printer, self, temperature)
|
||||||
self.updateTargetHotendTemperature(temperature)
|
self.updateTargetHotendTemperature(temperature)
|
||||||
|
|
||||||
|
@ -81,30 +78,26 @@ class ExtruderOutputModel(QObject):
|
||||||
def hotendTemperature(self) -> float:
|
def hotendTemperature(self) -> float:
|
||||||
return self._hotend_temperature
|
return self._hotend_temperature
|
||||||
|
|
||||||
@pyqtProperty(str, notify = hotendIDChanged)
|
@pyqtProperty(str, notify = extruderConfigurationChanged)
|
||||||
def hotendID(self) -> str:
|
def hotendID(self) -> str:
|
||||||
return self._hotend_id
|
return self._extruder_configuration.hotendID
|
||||||
|
|
||||||
def updateHotendID(self, id: str):
|
def updateHotendID(self, hotend_id: str) -> None:
|
||||||
if self._hotend_id != id:
|
self._extruder_configuration.setHotendID(hotend_id)
|
||||||
self._hotend_id = id
|
|
||||||
self._extruder_configuration.hotendID = self._hotend_id
|
|
||||||
self.hotendIDChanged.emit()
|
|
||||||
self.extruderConfigurationChanged.emit()
|
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify = extruderConfigurationChanged)
|
@pyqtProperty(QObject, notify = extruderConfigurationChanged)
|
||||||
def extruderConfiguration(self):
|
def extruderConfiguration(self) -> Optional[ExtruderConfigurationModel]:
|
||||||
if self._extruder_configuration.isValid():
|
if self._extruder_configuration.isValid():
|
||||||
return self._extruder_configuration
|
return self._extruder_configuration
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def updateIsPreheating(self, pre_heating):
|
def updateIsPreheating(self, pre_heating: bool) -> None:
|
||||||
if self._is_preheating != pre_heating:
|
if self._is_preheating != pre_heating:
|
||||||
self._is_preheating = pre_heating
|
self._is_preheating = pre_heating
|
||||||
self.isPreheatingChanged.emit()
|
self.isPreheatingChanged.emit()
|
||||||
|
|
||||||
@pyqtProperty(bool, notify=isPreheatingChanged)
|
@pyqtProperty(bool, notify=isPreheatingChanged)
|
||||||
def isPreheating(self):
|
def isPreheating(self) -> bool:
|
||||||
return self._is_preheating
|
return self._is_preheating
|
||||||
|
|
||||||
## Pre-heats the extruder before printer.
|
## Pre-heats the extruder before printer.
|
||||||
|
@ -113,9 +106,9 @@ class ExtruderOutputModel(QObject):
|
||||||
# Celsius.
|
# Celsius.
|
||||||
# \param duration How long the bed should stay warm, in seconds.
|
# \param duration How long the bed should stay warm, in seconds.
|
||||||
@pyqtSlot(float, float)
|
@pyqtSlot(float, float)
|
||||||
def preheatHotend(self, temperature, duration):
|
def preheatHotend(self, temperature: float, duration: float) -> None:
|
||||||
self._printer._controller.preheatHotend(self, temperature, duration)
|
self._printer._controller.preheatHotend(self, temperature, duration)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def cancelPreheatHotend(self):
|
def cancelPreheatHotend(self) -> None:
|
||||||
self._printer._controller.cancelPreheatHotend(self)
|
self._printer._controller.cancelPreheatHotend(self)
|
|
@ -43,9 +43,13 @@ class PrinterOutputModel(QObject):
|
||||||
self._is_preheating = False
|
self._is_preheating = False
|
||||||
self._printer_type = ""
|
self._printer_type = ""
|
||||||
self._buildplate_name = None
|
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
|
self._camera = None
|
||||||
|
|
||||||
|
@ -284,6 +288,6 @@ class PrinterOutputModel(QObject):
|
||||||
return self._printer_configuration
|
return self._printer_configuration
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _updateExtruderConfiguration(self):
|
#def _updateExtruderConfiguration(self):
|
||||||
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders]
|
|
||||||
self.configurationChanged.emit()
|
#self.configurationChanged.emit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue