diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 3ec73972dd..a8e6f2f2c0 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -4,6 +4,8 @@ from collections import defaultdict import threading from typing import Any, Dict, Optional, Set, TYPE_CHECKING, List +import uuid + from PyQt5.QtCore import pyqtProperty, pyqtSlot, pyqtSignal from UM.Decorators import override @@ -33,6 +35,7 @@ class GlobalStack(CuraContainerStack): super().__init__(container_id) self.setMetaDataEntry("type", "machine") # For backward compatibility + self.setMetaDataEntry("group_id", str(uuid.uuid4())) # Assign a new GlobalStack to a unique group by default self._extruders = {} # type: Dict[str, "ExtruderStack"] diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 24d63d5164..5db0a702a1 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -797,7 +797,6 @@ class MachineManager(QObject): self.setActiveMachine(other_machine_stacks[0]["id"]) metadata = CuraContainerRegistry.getInstance().findContainerStacksMetadata(id = machine_id)[0] - network_key = metadata.get("um_network_key", None) ExtruderManager.getInstance().removeMachineExtruders(machine_id) containers = CuraContainerRegistry.getInstance().findInstanceContainersMetadata(type = "user", machine = machine_id) for container in containers: @@ -805,8 +804,9 @@ class MachineManager(QObject): CuraContainerRegistry.getInstance().removeContainer(machine_id) # If the printer that is being removed is a network printer, the hidden printers have to be also removed - if network_key: - metadata_filter = {"um_network_key": network_key} + group_id = metadata.get("group_id", None) + if group_id: + metadata_filter = {"group_id": group_id} hidden_containers = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter) if hidden_containers: # This reuses the method and remove all printers recursively @@ -1366,6 +1366,7 @@ class MachineManager(QObject): new_machine = CuraStackBuilder.createMachine(machine_definition_id + "_sync", machine_definition_id) if not new_machine: return + new_machine.setMetaDataEntry("group_id", self._global_container_stack.getMetaDataEntry("group_id")) new_machine.setMetaDataEntry("um_network_key", self.activeMachineNetworkKey()) new_machine.setMetaDataEntry("group_name", self.activeMachineNetworkGroupName) new_machine.setMetaDataEntry("hidden", False) diff --git a/plugins/VersionUpgrade/VersionUpgrade40to41/VersionUpgrade40to41.py b/plugins/VersionUpgrade/VersionUpgrade40to41/VersionUpgrade40to41.py index 03272e63d5..845e9cbb8c 100644 --- a/plugins/VersionUpgrade/VersionUpgrade40to41/VersionUpgrade40to41.py +++ b/plugins/VersionUpgrade/VersionUpgrade40to41/VersionUpgrade40to41.py @@ -3,6 +3,7 @@ import configparser import io +import uuid from typing import Dict, List, Tuple from UM.VersionUpgrade import VersionUpgrade @@ -18,6 +19,7 @@ _renamed_quality_profiles = { "gmax15plus_pla_very_thick": "gmax15plus_global_very_thick" } # type: Dict[str, str] + ## Upgrades configurations from the state they were in at version 4.0 to the # state they should be in at version 4.1. class VersionUpgrade40to41(VersionUpgrade): @@ -95,6 +97,13 @@ class VersionUpgrade40to41(VersionUpgrade): if parser["containers"]["4"] in _renamed_quality_profiles: parser["containers"]["4"] = _renamed_quality_profiles[parser["containers"]["4"]] + # Assign a GlobalStack to a unique group_id. If the GlobalStack has a UM network connection, use the UM network + # key as the group_id. + if "um_network_key" in parser["metadata"]: + parser["metadata"]["group_id"] = parser["metadata"]["um_network_key"] + elif "group_id" not in parser["metadata"]: + parser["metadata"]["group_id"] = str(uuid.uuid4()) + result = io.StringIO() parser.write(result) return [filename], [result.getvalue()]