diff --git a/cura/PrinterOutput/ConfigurationModel.py b/cura/PrinterOutput/ConfigurationModel.py index 23ed687fb8..c03d968b9e 100644 --- a/cura/PrinterOutput/ConfigurationModel.py +++ b/cura/PrinterOutput/ConfigurationModel.py @@ -40,6 +40,16 @@ class ConfigurationModel(QObject): def buildplateConfiguration(self): return self._buildplate_configuration + ## This method is intended to indicate whether the configuration is valid or not. + # The method checks if the mandatory fields are or not set + def isValid(self): + if not self._extruder_configurations: + return False + for configuration in self._extruder_configurations: + if configuration is None: + return False + return self._printer_type is not None + def __str__(self): message_chunks = [] message_chunks.append("Printer type: " + self._printer_type) diff --git a/cura/PrinterOutput/ExtruderConfigurationModel.py b/cura/PrinterOutput/ExtruderConfigurationModel.py index 34eddb3038..e49ffe13d7 100644 --- a/cura/PrinterOutput/ExtruderConfigurationModel.py +++ b/cura/PrinterOutput/ExtruderConfigurationModel.py @@ -35,8 +35,13 @@ class ExtruderConfigurationModel(QObject): def hotendID(self): 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 + def isValid(self): + return self._material is not None and self._hotend_id is not None and self.material.guid is not None + def __str__(self): - if self._material is None or self._hotend_id is None or self.material.type is None: + if not self.isValid(): return "No information" return "Position: " + str(self._position) + " - Material: " + self._material.type + " - HotendID: " + self._hotend_id diff --git a/cura/PrinterOutput/ExtruderOutputModel.py b/cura/PrinterOutput/ExtruderOutputModel.py index df47bca71a..e4c7f1608e 100644 --- a/cura/PrinterOutput/ExtruderOutputModel.py +++ b/cura/PrinterOutput/ExtruderOutputModel.py @@ -28,9 +28,7 @@ class ExtruderOutputModel(QObject): self._hotend_id = "" self._active_material = None # type: Optional[MaterialOutputModel] self._extruder_configuration = ExtruderConfigurationModel() - # Update the configuration every time the hotend or the active material change - self.hotendIDChanged.connect(self._updateExtruderConfiguration) - self.activeMaterialChanged.connect(self._updateExtruderConfiguration) + self._extruder_configuration.position = self._position @pyqtProperty(QObject, notify = activeMaterialChanged) def activeMaterial(self) -> "MaterialOutputModel": @@ -39,7 +37,9 @@ class ExtruderOutputModel(QObject): 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() ## Update the hotend temperature. This only changes it locally. def updateHotendTemperature(self, temperature: float): @@ -73,14 +73,12 @@ class ExtruderOutputModel(QObject): 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() @pyqtProperty(QObject, notify = extruderConfigurationChanged) def extruderConfiguration(self): - return self._extruder_configuration - - def _updateExtruderConfiguration(self): - self._extruder_configuration.position = self._position - self._extruder_configuration.material = self._active_material - self._extruder_configuration.hotendID = self._hotend_id - self.extruderConfigurationChanged.emit() + if self._extruder_configuration.isValid(): + return self._extruder_configuration + return None diff --git a/cura/PrinterOutput/PrinterOutputModel.py b/cura/PrinterOutput/PrinterOutputModel.py index 04f2c1eb62..712f9b5b1e 100644 --- a/cura/PrinterOutput/PrinterOutputModel.py +++ b/cura/PrinterOutput/PrinterOutputModel.py @@ -45,9 +45,7 @@ class PrinterOutputModel(QObject): 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._updatePrinterConfiguration) - self.printerTypeChanged.connect(self._updatePrinterConfiguration) - self.buildplateChanged.connect(self._updatePrinterConfiguration) + extruder.extruderConfigurationChanged.connect(self._updateExtruderConfiguration) self._camera = None @@ -80,16 +78,20 @@ class PrinterOutputModel(QObject): def updateType(self, printer_type): if self._printer_type != printer_type: self._printer_type = printer_type + self._printer_configuration.printerType = self._printer_type self.printerTypeChanged.emit() + self.configurationChanged.emit() @pyqtProperty(str, notify = buildplateChanged) def buildplate(self): return self._buildplate_name - def updateBuildplate(self, buildplate_name): + def updateBuildplateName(self, buildplate_name): if self._buildplate_name != buildplate_name: self._buildplate_name = buildplate_name + self._printer_configuration.buildplateConfiguration = self._buildplate_name self.buildplateChanged.emit() + self.configurationChanged.emit() @pyqtProperty(str, notify=keyChanged) def key(self): @@ -260,10 +262,10 @@ class PrinterOutputModel(QObject): # Returns the configuration (material, variant and buildplate) of the current printer @pyqtProperty(QObject, notify = configurationChanged) def printerConfiguration(self): - return self._printer_configuration + if self._printer_configuration.isValid(): + return self._printer_configuration + return None - def _updatePrinterConfiguration(self): - self._printer_configuration.printerType = self._printer_type + def _updateExtruderConfiguration(self): self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders] - self._printer_configuration.buildplateConfiguration = self._buildplate_name self.configurationChanged.emit() diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 453cb4d78a..4d6ddb8dfa 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -187,7 +187,7 @@ class PrinterOutputDevice(QObject, OutputDevice): return self._unique_configurations def _updateUniqueConfigurations(self): - self._unique_configurations = list(set([printer.printerConfiguration for printer in self._printers])) + self._unique_configurations = list(set([printer.printerConfiguration for printer in self._printers if printer.printerConfiguration is not None])) self._unique_configurations.sort(key = lambda k: k.printerType) self.uniqueConfigurationsChanged.emit() diff --git a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py index 942bc82280..77b64ee080 100644 --- a/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py @@ -384,7 +384,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): # Do not store the buildplate information that comes from connect if the current printer has not buildplate information if "build_plate" in data and machine_definition.getMetaDataEntry("has_variant_buildplates", False): - printer.updateBuildplate(data["build_plate"]["type"]) + printer.updateBuildplateName(data["build_plate"]["type"]) if not data["enabled"]: printer.updateState("disabled") else: