Browse Source

Every print ouput device should define its connection type(usb, network, cluster and etc)
CURA-6011

Aleksei S 6 years ago
parent
commit
973970a895

+ 3 - 3
cura/PrinterOutput/NetworkedPrinterOutputDevice.py

@@ -6,7 +6,7 @@ from UM.Logger import Logger
 from UM.Scene.SceneNode import SceneNode #For typing.
 from cura.CuraApplication import CuraApplication
 
-from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
+from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState, ConnectionType
 
 from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply, QAuthenticator
 from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl, QCoreApplication
@@ -28,8 +28,8 @@ class AuthState(IntEnum):
 class NetworkedPrinterOutputDevice(PrinterOutputDevice):
     authenticationStateChanged = pyqtSignal()
 
-    def __init__(self, device_id, address: str, properties: Dict[bytes, bytes], parent: QObject = None) -> None:
-        super().__init__(device_id = device_id, parent = parent)
+    def __init__(self, device_id, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType = ConnectionType.networkConnection, parent: QObject = None) -> None:
+        super().__init__(device_id = device_id, connection_type = connection_type, parent = parent)
         self._manager = None    # type: Optional[QNetworkAccessManager]
         self._last_manager_create_time = None       # type: Optional[float]
         self._recreate_network_manager_time = 30

+ 18 - 1
cura/PrinterOutputDevice.py

@@ -34,6 +34,12 @@ class ConnectionState(IntEnum):
     busy = 3
     error = 4
 
+class ConnectionType(IntEnum):
+    none = 0
+    usbConnection = 1
+    networkConnection = 2
+    clusterConnection = 3
+    cloudConnection = 4
 
 ##  Printer output device adds extra interface options on top of output device.
 #
@@ -62,7 +68,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
     # Signal to indicate that the configuration of one of the printers has changed.
     uniqueConfigurationsChanged = pyqtSignal()
 
-    def __init__(self, device_id: str, parent: QObject = None) -> None:
+    def __init__(self, device_id: str, connection_type: ConnectionType, parent: QObject = None) -> None:
         super().__init__(device_id = device_id, parent = parent) # type: ignore  # MyPy complains with the multiple inheritance
 
         self._printers = []  # type: List[PrinterOutputModel]
@@ -84,6 +90,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
         self._update_timer.timeout.connect(self._update)
 
         self._connection_state = ConnectionState.closed #type: ConnectionState
+        self._connection_type = connection_type
 
         self._firmware_updater = None #type: Optional[FirmwareUpdater]
         self._firmware_name = None #type: Optional[str]
@@ -117,6 +124,16 @@ class PrinterOutputDevice(QObject, OutputDevice):
             self._connection_state = connection_state
             self.connectionStateChanged.emit(self._id)
 
+    def checkConnectionType(self, connection_type: ConnectionType) -> bool:
+        return connection_type == self._connection_type
+
+    def getConnectionType(self) -> ConnectionType:
+        return self._connection_type
+
+    def setConnectionType(self, new_connection_type: ConnectionType) -> None:
+        if self._connection_type != new_connection_type:
+            self._connection_type = new_connection_type
+
     @pyqtProperty(str, notify = connectionStateChanged)
     def connectionState(self) -> ConnectionState:
         return self._connection_state

+ 1 - 1
plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml

@@ -28,7 +28,7 @@ Cura.MachineAction
                 // Check if there is another instance with the same key
                 if (!manager.existsKey(printerKey))
                 {
-                    manager.setKey(printerKey)
+                    manager.setKey(base.selectedDevice)
                     manager.setGroupName(printerName)   // TODO To change when the groups have a name
                     completed()
                 }

+ 2 - 1
plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py

@@ -22,6 +22,7 @@ from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationM
 from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice, AuthState
 from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
 from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
+from cura.PrinterOutputDevice import ConnectionType
 
 from .ClusterUM3PrinterOutputController import ClusterUM3PrinterOutputController
 from .SendMaterialJob import SendMaterialJob
@@ -54,7 +55,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
     clusterPrintersChanged = pyqtSignal()
 
     def __init__(self, device_id, address, properties, parent = None) -> None:
-        super().__init__(device_id = device_id, address = address, properties=properties, parent = parent)
+        super().__init__(device_id = device_id, address = address, properties=properties, connection_type = ConnectionType.clusterConnection, parent = parent)
         self._api_prefix = "/cluster-api/v1/"
 
         self._number_of_extruders = 2

+ 15 - 8
plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py

@@ -3,7 +3,7 @@
 
 import os.path
 import time
-from typing import cast, Optional
+from typing import Optional
 
 from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot, QObject
 
@@ -13,6 +13,7 @@ from UM.i18n import i18nCatalog
 
 from cura.CuraApplication import CuraApplication
 from cura.MachineAction import MachineAction
+from cura.PrinterOutputDevice import PrinterOutputDevice
 
 from .UM3OutputDevicePlugin import UM3OutputDevicePlugin
 
@@ -116,22 +117,28 @@ class DiscoverUM3Action(MachineAction):
             # Ensure that the connection states are refreshed.
             self._network_plugin.reCheckConnections()
 
-    @pyqtSlot(str)
-    def setKey(self, key: str) -> None:
-        Logger.log("d", "Attempting to set the network key of the active machine to %s", key)
+    @pyqtSlot(QObject)
+    def setKey(self, printer_device: Optional[PrinterOutputDevice]) -> None:
+        Logger.log("d", "Attempting to set the network key of the active machine to %s", printer_device.key)
         global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
         if global_container_stack:
             meta_data = global_container_stack.getMetaData()
             if "um_network_key" in meta_data:
                 previous_network_key= meta_data["um_network_key"]
-                global_container_stack.setMetaDataEntry("um_network_key", key)
+                global_container_stack.setMetaDataEntry("um_network_key", printer_device.key)
                 # Delete old authentication data.
-                Logger.log("d", "Removing old authentication id %s for device %s", global_container_stack.getMetaDataEntry("network_authentication_id", None), key)
+                Logger.log("d", "Removing old authentication id %s for device %s", global_container_stack.getMetaDataEntry("network_authentication_id", None), printer_device.key)
                 global_container_stack.removeMetaDataEntry("network_authentication_id")
                 global_container_stack.removeMetaDataEntry("network_authentication_key")
-                CuraApplication.getInstance().getMachineManager().replaceContainersMetadata(key = "um_network_key", value = previous_network_key, new_value = key)
+                CuraApplication.getInstance().getMachineManager().replaceContainersMetadata(key = "um_network_key", value = previous_network_key, new_value = printer_device.key)
+
+                if "um_connection_type" in meta_data:
+                    previous_connection_type = meta_data["um_connection_type"]
+                    global_container_stack.setMetaDataEntry("um_connection_type", printer_device.getConnectionType().value)
+                    CuraApplication.getInstance().getMachineManager().replaceContainersMetadata(key = "um_connection_type", value = previous_connection_type, new_value = printer_device.getConnectionType().value)
             else:
-                global_container_stack.setMetaDataEntry("um_network_key", key)
+                global_container_stack.setMetaDataEntry("um_network_key", printer_device.key)
+                global_container_stack.setMetaDataEntry("um_connection_type", printer_device.getConnectionType().value)
 
         if self._network_plugin:
             # Ensure that the connection states are refreshed.

+ 2 - 1
plugins/UM3NetworkPrinting/src/LegacyUM3OutputDevice.py

@@ -7,6 +7,7 @@ from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutp
 from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
 from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
 from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
+from cura.PrinterOutputDevice import ConnectionType
 
 from cura.Settings.ContainerManager import ContainerManager
 from cura.Settings.ExtruderManager import ExtruderManager
@@ -43,7 +44,7 @@ i18n_catalog = i18nCatalog("cura")
 #   5. As a final step, we verify the authentication, as this forces the QT manager to setup the authenticator.
 class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
     def __init__(self, device_id, address: str, properties, parent = None) -> None:
-        super().__init__(device_id = device_id, address = address, properties = properties, parent = parent)
+        super().__init__(device_id = device_id, address = address, properties = properties, connection_type =  ConnectionType.networkConnection, parent = parent)
         self._api_prefix = "/api/v1/"
         self._number_of_extruders = 2
 

+ 2 - 2
plugins/USBPrinting/USBPrinterOutputDevice.py

@@ -7,7 +7,7 @@ from UM.i18n import i18nCatalog
 from UM.Qt.Duration import DurationFormat
 
 from cura.CuraApplication import CuraApplication
-from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
+from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState, ConnectionType
 from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
 from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
 from cura.PrinterOutput.GenericOutputController import GenericOutputController
@@ -29,7 +29,7 @@ catalog = i18nCatalog("cura")
 
 class USBPrinterOutputDevice(PrinterOutputDevice):
     def __init__(self, serial_port: str, baud_rate: Optional[int] = None) -> None:
-        super().__init__(serial_port)
+        super().__init__(serial_port, connection_type=ConnectionType.usbConnection)
         self.setName(catalog.i18nc("@item:inmenu", "USB printing"))
         self.setShortDescription(catalog.i18nc("@action:button Preceded by 'Ready to'.", "Print via USB"))
         self.setDescription(catalog.i18nc("@info:tooltip", "Print via USB"))

+ 1 - 1
resources/qml/PrinterSelector/MachineSelectorList.qml

@@ -32,7 +32,7 @@ Column
             id: networkedPrintersModel
             filter:
             {
-                "type": "machine", "um_network_key": "*", "hidden": "False"
+                "type": "machine", "um_network_key": "*", "hidden": "False", "um_connection_type": "[2,3,4]"
             }
         }