diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 9619329e59..b69d91c0d4 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1220,6 +1220,14 @@ class MachineManager(QObject): for container in hidden_containers: container.setMetaDataEntry("connect_group_name", group_name) + ## This method checks if there is an instance connected to the given network_key + def existNetworkInstances(self, network_key: str) -> bool: + metadata_filter = {"um_network_key": network_key} + containers = ContainerRegistry.getInstance().findContainerStacks(type = "machine", **metadata_filter) + if containers: + return True + return False + @pyqtSlot("QVariant") def setGlobalVariant(self, container_node): self.blurSettings.emit() diff --git a/plugins/UM3NetworkPrinting/DiscoverUM3Action.py b/plugins/UM3NetworkPrinting/DiscoverUM3Action.py index 76e8721fdd..0b8d6e9f53 100644 --- a/plugins/UM3NetworkPrinting/DiscoverUM3Action.py +++ b/plugins/UM3NetworkPrinting/DiscoverUM3Action.py @@ -147,6 +147,10 @@ class DiscoverUM3Action(MachineAction): return "" + @pyqtSlot(str, result = bool) + def existsKey(self, key) -> bool: + return Application.getInstance().getMachineManager().existNetworkInstances(network_key = key) + @pyqtSlot() def loadConfigurationFromPrinter(self): machine_manager = Application.getInstance().getMachineManager() diff --git a/plugins/UM3NetworkPrinting/DiscoverUM3Action.qml b/plugins/UM3NetworkPrinting/DiscoverUM3Action.qml index 079e5dcdd3..e7df22b546 100644 --- a/plugins/UM3NetworkPrinting/DiscoverUM3Action.qml +++ b/plugins/UM3NetworkPrinting/DiscoverUM3Action.qml @@ -5,6 +5,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 +import QtQuick.Dialogs 1.2 Cura.MachineAction { @@ -33,15 +34,34 @@ Cura.MachineAction { var printerKey = base.selectedDevice.key var printerName = base.selectedDevice.name // TODO To change when the groups have a name - if(manager.getStoredKey() != printerKey) + if (manager.getStoredKey() != printerKey) { - manager.setKey(printerKey) - manager.setGroupName(printerName) // TODO To change when the groups have a name - completed() + // Check if there is another instance with the same key + if (!manager.existsKey(printerKey)) + { + manager.setKey(printerKey) + manager.setGroupName(printerName) // TODO To change when the groups have a name + completed() + } + else + { + existingConnectionDialog.open() + } } } } + MessageDialog + { + id: existingConnectionDialog + title: catalog.i18nc("@window:title", "Existing Connection") + icon: StandardIcon.Information + text: catalog.i18nc("@message:text", "There is an instance already connected to this group") + detailedText: catalog.i18nc("@message:description", "You can't connect two instances to the same group. Please use the other instance or connect to another group.") + standardButtons: StandardButton.Ok + modality: Qt.ApplicationModal + } + Column { anchors.fill: parent;