CURA-4870 Add the ability in Cura to switch between different types of

printers. Create a new container stack if it doesn't exist with the same
network connection key.
This commit is contained in:
Diego Prado Gesto 2018-03-09 10:47:08 +01:00
parent b212781a19
commit 4be4d08d97
2 changed files with 39 additions and 16 deletions

View file

@ -352,12 +352,25 @@ class MachineManager(QObject):
self.__emitChangedSignals() self.__emitChangedSignals()
## Given a definition id, return the machine with this id.
# Optional: add a list of keys and values to filter the list of machines with the given definition id
# \param definition_id \type{str} definition id that needs to look for
# \param metadata_filter \type{dict} list of metadata keys and values used for filtering
@staticmethod @staticmethod
def getMachine(definition_id: str) -> Optional["GlobalStack"]: def getMachine(definition_id: str, metadata_filter: Dict[str, str] = None) -> Optional["GlobalStack"]:
machines = ContainerRegistry.getInstance().findContainerStacks(type = "machine") machines = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
for machine in machines: for machine in machines:
if machine.definition.getId() == definition_id: if machine.definition.getId() == definition_id:
return machine if metadata_filter:
pass_all_filters = True
for key in metadata_filter:
if machine.getMetaDataEntry(key) != metadata_filter[key]:
pass_all_filters = False
break
if pass_all_filters:
return machine
else:
return machine
return None return None
@pyqtSlot(str, str) @pyqtSlot(str, str)
@ -1044,21 +1057,31 @@ class MachineManager(QObject):
self._setMaterial(position, new_material) self._setMaterial(position, new_material)
continue continue
def switchPrinterType(self, machine_type): ## Given a printer definition name, select the right machine instance. In case it doesn't exist, create a new
container_registry = ContainerRegistry.getInstance() # instance with the same network key.
machine_definition = container_registry.findDefinitionContainers(name = machine_type)[0] @pyqtSlot(str)
self._global_container_stack.definition = machine_definition def switchPrinterType(self, machine_name):
self.globalContainerChanged.emit() # Don't switch if the user tries to change to the same type of printer
# machine_stack = CuraStackBuilder.createMachine("ultimaker_s5" + "_instance", "ultimaker_s5") if self.activeMachineDefinitionName == machine_name:
# # if not machine_stack: return
# # raise Exception("No machine found for ID {}".format(machine_id)) # Get the definition id corresponding to this machine name
# Logger.log("d", "Setting active machine to %s", machine_stack.getId()) machine_definition_id = ContainerRegistry.getInstance().findDefinitionContainers(name = machine_name)[0].getId()
# self.setActiveMachine(machine_stack.getId()) # Try to find a machine with the same network key
new_machine = self.getMachine(machine_definition_id, metadata_filter = {"um_network_key": self.activeMachineNetworkKey})
# If there is no machine, then create a new one
if not new_machine:
new_machine = CuraStackBuilder.createMachine(machine_definition_id + "_instance", machine_definition_id)
new_machine.addMetaDataEntry("um_network_key", self.activeMachineNetworkKey)
else:
Logger.log("i", "Found a %s with the key %s. Let's use it!", machine_name, self.activeMachineNetworkKey)
self.setActiveMachine(new_machine.getId())
@pyqtSlot(QObject) @pyqtSlot(QObject)
def applyRemoteConfiguration(self, configuration: ConfigurationModel): def applyRemoteConfiguration(self, configuration: ConfigurationModel):
self.blurSettings.emit() self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue): with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self.switchPrinterType(configuration.printerType)
for extruder_configuration in configuration.extruderConfigurations: for extruder_configuration in configuration.extruderConfigurations:
position = str(extruder_configuration.position) position = str(extruder_configuration.position)
variant_container_node = self._variant_manager.getVariantNode(self._global_container_stack.definition.getId(), extruder_configuration.hotendID) variant_container_node = self._variant_manager.getVariantNode(self._global_container_stack.definition.getId(), extruder_configuration.hotendID)

View file

@ -23,10 +23,10 @@ Menu
checkable: true checkable: true
checked: Cura.MachineManager.activeMachineDefinitionName == modelData.machine_type checked: Cura.MachineManager.activeMachineDefinitionName == modelData.machine_type
exclusiveGroup: group exclusiveGroup: group
// onTriggered: onTriggered:
// { {
// TODO Cura.MachineManager.switchPrinterType(modelData.machine_type)
// } }
} }
onObjectAdded: menu.insertItem(index, object) onObjectAdded: menu.insertItem(index, object)
onObjectRemoved: menu.removeItem(object) onObjectRemoved: menu.removeItem(object)