CURA-4870 Create an extruder configuration model to store the extruder configuration.

Connect the signals coming from the printer to correctly update the UI
This commit is contained in:
Diego Prado Gesto 2018-03-05 17:15:09 +01:00
parent a992487589
commit 51686943e6
6 changed files with 82 additions and 17 deletions

View file

@ -2,6 +2,11 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
from typing import List
MYPY = False
if MYPY:
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
class ConfigurationModel(QObject): class ConfigurationModel(QObject):
@ -11,13 +16,13 @@ class ConfigurationModel(QObject):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self._printer_type = None self._printer_type = None
self._extruder_configurations = [] self._extruder_configurations = [] # type: List[ExtruderConfigurationModel]
self._buildplate_configuration = None self._buildplate_configuration = None
def setPrinterType(self, printer_type): def setPrinterType(self, printer_type):
self._printer_type = printer_type self._printer_type = printer_type
@pyqtProperty(str, fset = setPrinterType, constant = True) @pyqtProperty(str, fset = setPrinterType, notify = configurationChanged)
def printerType(self): def printerType(self):
return self._printer_type return self._printer_type
@ -41,5 +46,5 @@ class ConfigurationModel(QObject):
def __hash__(self): def __hash__(self):
extruder_hash = hash(0) extruder_hash = hash(0)
for configuration in self.extruderConfigurations: for configuration in self.extruderConfigurations:
extruder_hash ^= hash(frozenset(configuration.items())) extruder_hash ^= configuration.__hash__()
return hash(self.printerType) ^ extruder_hash ^ hash(self.buildplateConfiguration) return hash(self.printerType) ^ extruder_hash ^ hash(self.buildplateConfiguration)

View file

@ -0,0 +1,42 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject, pyqtSignal
class ExtruderConfigurationModel(QObject):
extruderConfigurationChanged = pyqtSignal()
def __init__(self):
super().__init__()
self._position = -1
self._material = None
self._hotend_id = None
def setPosition(self, position):
self._position = position
@pyqtProperty(int, fset = setPosition, notify = extruderConfigurationChanged)
def position(self):
return self._position
def setMaterial(self, material):
self._material = material
@pyqtProperty(str, fset = setMaterial, notify = extruderConfigurationChanged)
def material(self):
return self._material
def setHotendID(self, hotend_id):
self._hotend_id = hotend_id
@pyqtProperty(str, fset = setHotendID, notify = extruderConfigurationChanged)
def hotendID(self):
return self._hotend_id
def __eq__(self, other):
return hash(self) == hash(other)
def __hash__(self):
return hash(self.position) ^ hash(self.material) ^ hash(self.hotendID)

View file

@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, pyqtSlot from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, pyqtSlot
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
from typing import Optional from typing import Optional
@ -26,7 +27,7 @@ class ExtruderOutputModel(QObject):
self._hotend_temperature = 0 self._hotend_temperature = 0
self._hotend_id = "" self._hotend_id = ""
self._active_material = None # type: Optional[MaterialOutputModel] self._active_material = None # type: Optional[MaterialOutputModel]
self._extruder_configuration = {} self._extruder_configuration = ExtruderConfigurationModel()
# Update the configuration every time the hotend or the active material change # Update the configuration every time the hotend or the active material change
self.hotendIDChanged.connect(self._updateExtruderConfiguration) self.hotendIDChanged.connect(self._updateExtruderConfiguration)
self.activeMaterialChanged.connect(self._updateExtruderConfiguration) self.activeMaterialChanged.connect(self._updateExtruderConfiguration)
@ -74,15 +75,13 @@ class ExtruderOutputModel(QObject):
self._hotend_id = id self._hotend_id = id
self.hotendIDChanged.emit() self.hotendIDChanged.emit()
@pyqtProperty("QVariantMap", notify = extruderConfigurationChanged) @pyqtProperty(QObject, notify = extruderConfigurationChanged)
def extruderConfiguration(self): def extruderConfiguration(self):
return self._extruder_configuration return self._extruder_configuration
def _updateExtruderConfiguration(self): def _updateExtruderConfiguration(self):
self._extruder_configuration = { self._extruder_configuration.position = self._position
"position": self._position, self._extruder_configuration.material = self._active_material.type if self.activeMaterial is not None else None
"material": self._active_material.type if self.activeMaterial is not None else None, self._extruder_configuration.hotendID = self._hotend_id
"hotendID": self._hotend_id
}
print("Recalculating extruder configuration:", self._extruder_configuration) print("Recalculating extruder configuration:", self._extruder_configuration)
self.extruderConfigurationChanged.emit() self.extruderConfigurationChanged.emit()

View file

@ -30,6 +30,7 @@ from UM.Signal import postponeSignals, CompressTechnique
from cura.QualityManager import QualityManager from cura.QualityManager import QualityManager
from cura.PrinterOutputDevice import PrinterOutputDevice from cura.PrinterOutputDevice import PrinterOutputDevice
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.ExtruderManager import ExtruderManager
from .CuraStackBuilder import CuraStackBuilder from .CuraStackBuilder import CuraStackBuilder
@ -177,19 +178,21 @@ class MachineManager(QObject):
return return
self._current_printer_configuration.printerType = self._global_container_stack.definition.getName() self._current_printer_configuration.printerType = self._global_container_stack.definition.getName()
extruder_configurations = [] self._current_printer_configuration.extruderConfigurations = []
for extruder in self._global_container_stack.extruders.values(): for extruder in self._global_container_stack.extruders.values():
extruder_configurations.append({ extruder_configuration = ExtruderConfigurationModel()
"position": int(extruder.getMetaDataEntry("position")), extruder_configuration.position = int(extruder.getMetaDataEntry("position"))
"material": extruder.material.getName() if extruder.material != self._empty_material_container else None, extruder_configuration.material = extruder.material.getName() if extruder.material != self._empty_material_container else None
"hotendID": extruder.variant.getName() if extruder.variant != self._empty_variant_container else None extruder_configuration.hotendID = extruder.variant.getName() if extruder.variant != self._empty_variant_container else None
}) self._current_printer_configuration.extruderConfigurations.append(extruder_configuration)
self._current_printer_configuration.extruderConfigurations = extruder_configurations
self._current_printer_configuration.buildplateConfiguration = self._global_container_stack.variant.getName() if self._global_container_stack.variant != self._empty_variant_container else None self._current_printer_configuration.buildplateConfiguration = self._global_container_stack.variant.getName() if self._global_container_stack.variant != self._empty_variant_container else None
self.currentConfigurationChanged.emit() self.currentConfigurationChanged.emit()
@pyqtSlot(QObject, result = bool) @pyqtSlot(QObject, result = bool)
def matchesConfiguration(self, configuration: ConfigurationModel) -> bool: def matchesConfiguration(self, configuration: ConfigurationModel) -> bool:
# print("@@@@@@@@@@@@@@@@@@", configuration.extruderConfigurations)
# print("##################", self._current_printer_configuration.extruderConfigurations, configuration == self._current_printer_configuration)
return self._current_printer_configuration == configuration return self._current_printer_configuration == configuration
@property @property

View file

@ -108,4 +108,11 @@ Rectangle
configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration) configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration)
} }
} }
Connections {
target: configuration
onConfigurationChanged: {
configurationItem.selected = Cura.MachineManager.matchesConfiguration(configuration)
}
}
} }

View file

@ -42,6 +42,15 @@ Column
font: UM.Theme.getFont("default_bold") font: UM.Theme.getFont("default_bold")
} }
Connections {
target: outputDevice
onUniqueConfigurationsChanged: {
// FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI
configurationList.model = null
configurationList.model = outputDevice.uniqueConfigurations
}
}
ListView ListView
{ {
id: configurationList id: configurationList