diff options
author | Jaime van Kessel <nallath@gmail.com> | 2022-08-31 11:27:52 +0300 |
---|---|---|
committer | Jaime van Kessel <nallath@gmail.com> | 2022-08-31 11:27:52 +0300 |
commit | 5ff07b00d029a0b6652dc6dcdd2992d162adaae8 (patch) | |
tree | f298800c3a0d45cd2c661ab413f7fb473c3a27c8 /plugins | |
parent | dd5981d85e4b9ac3580c6164e731fc76fcc5ce6b (diff) |
Fix case where both a "normal" and an "abstract" ouput device could be active
CURA-8463
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 1105a8b356..4082431cd9 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -64,7 +64,6 @@ class CloudOutputDeviceManager: self._running = False self._syncing = False - CuraApplication.getInstance().getContainerRegistry().containerRemoved.connect(self._printerRemoved) def start(self): @@ -375,7 +374,6 @@ class CloudOutputDeviceManager: def _connectToActiveMachine(self) -> None: """Callback for when the active machine was changed by the user""" - active_machine = CuraApplication.getInstance().getGlobalContainerStack() if not active_machine: return @@ -383,29 +381,29 @@ class CloudOutputDeviceManager: # Check if we should directly connect with a "normal" CloudOutputDevice or that we should connect to an # 'abstract' one output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() - if active_machine.getMetaDataEntry("is_abstract_machine") != "True": - stored_cluster_id = active_machine.getMetaDataEntry(self.META_CLUSTER_ID) - local_network_key = active_machine.getMetaDataEntry(self.META_NETWORK_KEY) - - # Copy of the device list, to prevent modifying the list while iterating, if a device gets added asynchronously. - remote_cluster_copy: List[CloudOutputDevice] = list(self._remote_clusters.values()) - for device in remote_cluster_copy: - if device.key == stored_cluster_id: - # Connect to it if the stored ID matches. - self._connectToOutputDevice(device, active_machine) - elif local_network_key and device.matchesNetworkKey(local_network_key): - # Connect to it if we can match the local network key that was already present. - self._connectToOutputDevice(device, active_machine) - elif device.key in output_device_manager.getOutputDeviceIds(): - # Remove device if it is not meant for the active machine. - output_device_manager.removeOutputDevice(device.key) - else: # Abstract it is! - remote_abstract_cluster_copy: List[CloudOutputDevice] = list(self._abstract_clusters.values()) - for device in remote_abstract_cluster_copy: - if device.printerType == active_machine.definition.getId(): - self._connectToAbstractOutputDevice(device, active_machine) - elif device.key in output_device_manager.getOutputDeviceIds(): - output_device_manager.removeOutputDevice(device.key) + stored_cluster_id = active_machine.getMetaDataEntry(self.META_CLUSTER_ID) + local_network_key = active_machine.getMetaDataEntry(self.META_NETWORK_KEY) + + # Copy of the device list, to prevent modifying the list while iterating, if a device gets added asynchronously. + remote_cluster_copy: List[CloudOutputDevice] = list(self._remote_clusters.values()) + for device in remote_cluster_copy: + if device.key == stored_cluster_id: + # Connect to it if the stored ID matches. + self._connectToOutputDevice(device, active_machine) + elif local_network_key and device.matchesNetworkKey(local_network_key): + # Connect to it if we can match the local network key that was already present. + self._connectToOutputDevice(device, active_machine) + elif device.key in output_device_manager.getOutputDeviceIds(): + # Remove device if it is not meant for the active machine. + output_device_manager.removeOutputDevice(device.key) + + # Update state of all abstract output devices + remote_abstract_cluster_copy: List[CloudOutputDevice] = list(self._abstract_clusters.values()) + for device in remote_abstract_cluster_copy: + if device.printerType == active_machine.definition.getId() and parseBool(active_machine.getMetaDataEntry("is_abstract_machine", False)): + self._connectToAbstractOutputDevice(device, active_machine) + elif device.key in output_device_manager.getOutputDeviceIds(): + output_device_manager.removeOutputDevice(device.key) def _setOutputDeviceMetadata(self, device: CloudOutputDevice, machine: GlobalStack): machine.setName(device.name) |