mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Cleanup and make sure that group_name is set
This commit is contained in:
parent
d16da3da3a
commit
bed13bf42b
3 changed files with 22 additions and 37 deletions
|
@ -1655,3 +1655,7 @@ class MachineManager(QObject):
|
|||
if results:
|
||||
machine_type_name = results[0]["name"]
|
||||
return machine_type_name
|
||||
|
||||
# Gets all machines that belong to the given group_id.
|
||||
def getMachinesInGroup(self, group_id: str) -> List["GlobalStack"]:
|
||||
return self._container_registry.findContainerStacks(type = "machine", group_id = group_id)
|
||||
|
|
|
@ -110,14 +110,12 @@ class DiscoverUM3Action(MachineAction):
|
|||
Logger.log("d", "Attempting to set the group name of the active machine to %s", group_name)
|
||||
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
meta_data = global_container_stack.getMetaData()
|
||||
if "group_name" in meta_data:
|
||||
previous_connect_group_name = meta_data["group_name"]
|
||||
global_container_stack.setMetaDataEntry("group_name", group_name)
|
||||
# Find all the places where there is the same group name and change it accordingly
|
||||
self._replaceContainersMetadata(key = "group_name", value = previous_connect_group_name, new_value = group_name)
|
||||
else:
|
||||
global_container_stack.setMetaDataEntry("group_name", group_name)
|
||||
# Update a GlobalStacks in the same group with the new group name.
|
||||
group_id = global_container_stack.getMetaDataEntry("group_id")
|
||||
machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||
for machine in machine_manager.getMachinesInGroup(group_id):
|
||||
machine.setMetaDataEntry("group_name", group_name)
|
||||
|
||||
# Set the default value for "hidden", which is used when you have a group with multiple types of printers
|
||||
global_container_stack.setMetaDataEntry("hidden", False)
|
||||
|
||||
|
@ -125,13 +123,6 @@ class DiscoverUM3Action(MachineAction):
|
|||
# Ensure that the connection states are refreshed.
|
||||
self._network_plugin.refreshConnections()
|
||||
|
||||
## Find all container stacks that has the pair 'key = value' in its metadata and replaces the value with 'new_value'
|
||||
def _replaceContainersMetadata(self, key: str, value: str, new_value: str) -> None:
|
||||
machines = CuraContainerRegistry.getInstance().findContainerStacks(type="machine")
|
||||
for machine in machines:
|
||||
if machine.getMetaDataEntry(key) == value:
|
||||
machine.setMetaDataEntry(key, new_value)
|
||||
|
||||
# Associates the currently active machine with the given printer device. The network connection information will be
|
||||
# stored into the metadata of the currently active machine.
|
||||
@pyqtSlot(QObject)
|
||||
|
|
|
@ -283,34 +283,24 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
|
||||
Logger.log("d", "Attempting to set the network key of the active machine to %s", printer_device.key)
|
||||
|
||||
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
||||
machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||
global_container_stack = machine_manager.activeMachine
|
||||
if not global_container_stack:
|
||||
return
|
||||
|
||||
meta_data = global_container_stack.getMetaData()
|
||||
|
||||
if "um_network_key" in meta_data: # Global stack already had a connection, but it's changed.
|
||||
old_network_key = meta_data["um_network_key"]
|
||||
# Since we might have a bunch of hidden stacks, we also need to change it there.
|
||||
metadata_filter = {"um_network_key": old_network_key}
|
||||
containers = self._application.getContainerRegistry().findContainerStacks(type = "machine", **metadata_filter)
|
||||
|
||||
for container in containers:
|
||||
container.setMetaDataEntry("um_network_key", printer_device.key)
|
||||
for machine in machine_manager.getMachinesInGroup(global_container_stack.getMetaDataEntry("group_id")):
|
||||
machine.setMetaDataEntry("um_network_key", printer_device.key)
|
||||
machine.setMetaDataEntry("group_name", printer_device.name)
|
||||
|
||||
# Delete old authentication data.
|
||||
Logger.log("d", "Removing old authentication id %s for device %s",
|
||||
global_container_stack.getMetaDataEntry("network_authentication_id", None), printer_device.key)
|
||||
|
||||
container.removeMetaDataEntry("network_authentication_id")
|
||||
container.removeMetaDataEntry("network_authentication_key")
|
||||
machine.removeMetaDataEntry("network_authentication_id")
|
||||
machine.removeMetaDataEntry("network_authentication_key")
|
||||
|
||||
# Ensure that these containers do know that they are configured for network connection
|
||||
container.addConfiguredConnectionType(printer_device.connectionType.value)
|
||||
|
||||
else: # Global stack didn't have a connection yet, configure it.
|
||||
global_container_stack.setMetaDataEntry("um_network_key", printer_device.key)
|
||||
global_container_stack.addConfiguredConnectionType(printer_device.connectionType.value)
|
||||
machine.addConfiguredConnectionType(printer_device.connectionType.value)
|
||||
|
||||
self.refreshConnections()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue