CURA-4870 Wait until the configuration has all the mandatory data before

add it to the list of unique configurations.
Remove some connections to signals and reuse already defined listeners.
This commit is contained in:
Diego Prado Gesto 2018-03-13 13:14:29 +01:00
parent d807ce57a5
commit dfb903fb81
6 changed files with 36 additions and 21 deletions

View file

@ -40,6 +40,16 @@ class ConfigurationModel(QObject):
def buildplateConfiguration(self): def buildplateConfiguration(self):
return self._buildplate_configuration 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): def __str__(self):
message_chunks = [] message_chunks = []
message_chunks.append("Printer type: " + self._printer_type) message_chunks.append("Printer type: " + self._printer_type)

View file

@ -35,8 +35,13 @@ class ExtruderConfigurationModel(QObject):
def hotendID(self): def hotendID(self):
return self._hotend_id 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): 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 "No information"
return "Position: " + str(self._position) + " - Material: " + self._material.type + " - HotendID: " + self._hotend_id return "Position: " + str(self._position) + " - Material: " + self._material.type + " - HotendID: " + self._hotend_id

View file

@ -28,9 +28,7 @@ class ExtruderOutputModel(QObject):
self._hotend_id = "" self._hotend_id = ""
self._active_material = None # type: Optional[MaterialOutputModel] self._active_material = None # type: Optional[MaterialOutputModel]
self._extruder_configuration = ExtruderConfigurationModel() self._extruder_configuration = ExtruderConfigurationModel()
# Update the configuration every time the hotend or the active material change self._extruder_configuration.position = self._position
self.hotendIDChanged.connect(self._updateExtruderConfiguration)
self.activeMaterialChanged.connect(self._updateExtruderConfiguration)
@pyqtProperty(QObject, notify = activeMaterialChanged) @pyqtProperty(QObject, notify = activeMaterialChanged)
def activeMaterial(self) -> "MaterialOutputModel": def activeMaterial(self) -> "MaterialOutputModel":
@ -39,7 +37,9 @@ class ExtruderOutputModel(QObject):
def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]): def updateActiveMaterial(self, material: Optional["MaterialOutputModel"]):
if self._active_material != material: if self._active_material != material:
self._active_material = material self._active_material = material
self._extruder_configuration.material = self._active_material
self.activeMaterialChanged.emit() 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):
@ -73,14 +73,12 @@ class ExtruderOutputModel(QObject):
def updateHotendID(self, id: str): def updateHotendID(self, id: str):
if self._hotend_id != id: if self._hotend_id != id:
self._hotend_id = id self._hotend_id = id
self._extruder_configuration.hotendID = self._hotend_id
self.hotendIDChanged.emit() self.hotendIDChanged.emit()
self.extruderConfigurationChanged.emit()
@pyqtProperty(QObject, notify = extruderConfigurationChanged) @pyqtProperty(QObject, notify = extruderConfigurationChanged)
def extruderConfiguration(self): def extruderConfiguration(self):
return self._extruder_configuration if self._extruder_configuration.isValid():
return self._extruder_configuration
def _updateExtruderConfiguration(self): return None
self._extruder_configuration.position = self._position
self._extruder_configuration.material = self._active_material
self._extruder_configuration.hotendID = self._hotend_id
self.extruderConfigurationChanged.emit()

View file

@ -45,9 +45,7 @@ class PrinterOutputModel(QObject):
self._buildplate_name = None self._buildplate_name = None
# Update the printer configuration every time any of the extruders changes its configuration # Update the printer configuration every time any of the extruders changes its configuration
for extruder in self._extruders: for extruder in self._extruders:
extruder.extruderConfigurationChanged.connect(self._updatePrinterConfiguration) extruder.extruderConfigurationChanged.connect(self._updateExtruderConfiguration)
self.printerTypeChanged.connect(self._updatePrinterConfiguration)
self.buildplateChanged.connect(self._updatePrinterConfiguration)
self._camera = None self._camera = None
@ -80,16 +78,20 @@ class PrinterOutputModel(QObject):
def updateType(self, printer_type): def updateType(self, printer_type):
if self._printer_type != printer_type: if self._printer_type != printer_type:
self._printer_type = printer_type self._printer_type = printer_type
self._printer_configuration.printerType = self._printer_type
self.printerTypeChanged.emit() self.printerTypeChanged.emit()
self.configurationChanged.emit()
@pyqtProperty(str, notify = buildplateChanged) @pyqtProperty(str, notify = buildplateChanged)
def buildplate(self): def buildplate(self):
return self._buildplate_name return self._buildplate_name
def updateBuildplate(self, buildplate_name): def updateBuildplateName(self, buildplate_name):
if self._buildplate_name != buildplate_name: if self._buildplate_name != buildplate_name:
self._buildplate_name = buildplate_name self._buildplate_name = buildplate_name
self._printer_configuration.buildplateConfiguration = self._buildplate_name
self.buildplateChanged.emit() self.buildplateChanged.emit()
self.configurationChanged.emit()
@pyqtProperty(str, notify=keyChanged) @pyqtProperty(str, notify=keyChanged)
def key(self): def key(self):
@ -260,10 +262,10 @@ class PrinterOutputModel(QObject):
# Returns the configuration (material, variant and buildplate) of the current printer # Returns the configuration (material, variant and buildplate) of the current printer
@pyqtProperty(QObject, notify = configurationChanged) @pyqtProperty(QObject, notify = configurationChanged)
def printerConfiguration(self): def printerConfiguration(self):
return self._printer_configuration if self._printer_configuration.isValid():
return self._printer_configuration
return None
def _updatePrinterConfiguration(self): def _updateExtruderConfiguration(self):
self._printer_configuration.printerType = self._printer_type
self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders] self._printer_configuration.extruderConfigurations = [extruder.extruderConfiguration for extruder in self._extruders]
self._printer_configuration.buildplateConfiguration = self._buildplate_name
self.configurationChanged.emit() self.configurationChanged.emit()

View file

@ -187,7 +187,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
return self._unique_configurations return self._unique_configurations
def _updateUniqueConfigurations(self): 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._unique_configurations.sort(key = lambda k: k.printerType)
self.uniqueConfigurationsChanged.emit() self.uniqueConfigurationsChanged.emit()

View file

@ -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 # 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): 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"]: if not data["enabled"]:
printer.updateState("disabled") printer.updateState("disabled")
else: else: