mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-29 15:25:02 +08:00
Move associate um network printer function into UM3OutputDevicePlugin
This commit is contained in:
parent
109631d023
commit
d34b3b8585
@ -1665,43 +1665,3 @@ class MachineManager(QObject):
|
|||||||
if results:
|
if results:
|
||||||
machine_type_name = results[0]["name"]
|
machine_type_name = results[0]["name"]
|
||||||
return machine_type_name
|
return machine_type_name
|
||||||
|
|
||||||
@pyqtSlot(QObject)
|
|
||||||
def associateActiveMachineWithPrinterDevice(self, printer_device: Optional["PrinterOutputDevice"]) -> None:
|
|
||||||
if not printer_device:
|
|
||||||
return
|
|
||||||
|
|
||||||
Logger.log("d", "Attempting to set the network key of the active machine to %s", printer_device.key)
|
|
||||||
|
|
||||||
global_stack = self._global_container_stack
|
|
||||||
if not global_stack:
|
|
||||||
return
|
|
||||||
|
|
||||||
meta_data = global_stack.getMetaData()
|
|
||||||
|
|
||||||
# Global stack previously had a connection, so here it needs to change the connection information in all
|
|
||||||
# global stacks in that same group.
|
|
||||||
if "um_network_key" in meta_data:
|
|
||||||
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._container_registry.findContainerStacks(type = "machine", **metadata_filter)
|
|
||||||
|
|
||||||
for container in containers:
|
|
||||||
container.setMetaDataEntry("um_network_key", printer_device.key)
|
|
||||||
|
|
||||||
# Delete old authentication data.
|
|
||||||
Logger.log("d", "Removing old authentication id %s for device %s",
|
|
||||||
global_stack.getMetaDataEntry("network_authentication_id", None),
|
|
||||||
printer_device.key)
|
|
||||||
|
|
||||||
container.removeMetaDataEntry("network_authentication_id")
|
|
||||||
container.removeMetaDataEntry("network_authentication_key")
|
|
||||||
|
|
||||||
# Ensure that these containers do know that they are configured for network connection
|
|
||||||
container.addConfiguredConnectionType(printer_device.connectionType.value)
|
|
||||||
|
|
||||||
# Global stack previously didn't have a connection, so directly configure it.
|
|
||||||
else:
|
|
||||||
global_stack.setMetaDataEntry("um_network_key", printer_device.key)
|
|
||||||
global_stack.addConfiguredConnectionType(printer_device.connectionType.value)
|
|
||||||
|
@ -124,43 +124,8 @@ class DiscoverUM3Action(MachineAction):
|
|||||||
# stored into the metadata of the currently active machine.
|
# stored into the metadata of the currently active machine.
|
||||||
@pyqtSlot(QObject)
|
@pyqtSlot(QObject)
|
||||||
def associateActiveMachineWithPrinterDevice(self, printer_device: Optional["PrinterOutputDevice"]) -> None:
|
def associateActiveMachineWithPrinterDevice(self, printer_device: Optional["PrinterOutputDevice"]) -> None:
|
||||||
if not printer_device:
|
|
||||||
return
|
|
||||||
|
|
||||||
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 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 = CuraContainerRegistry.getInstance().findContainerStacks(type="machine", **metadata_filter)
|
|
||||||
|
|
||||||
for container in containers:
|
|
||||||
container.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), printer_device.key)
|
|
||||||
|
|
||||||
container.removeMetaDataEntry("network_authentication_id")
|
|
||||||
container.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)
|
|
||||||
|
|
||||||
if self._network_plugin:
|
if self._network_plugin:
|
||||||
# Ensure that the connection states are refreshed.
|
self._network_plugin.associateActiveMachineWithPrinterDevice(printer_device)
|
||||||
self._network_plugin.refreshConnections()
|
|
||||||
|
|
||||||
@pyqtSlot(result = str)
|
@pyqtSlot(result = str)
|
||||||
def getStoredKey(self) -> str:
|
def getStoredKey(self) -> str:
|
||||||
|
@ -30,8 +30,9 @@ from .Cloud.CloudOutputDeviceManager import CloudOutputDeviceManager
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from PyQt5.QtNetwork import QNetworkReply
|
from PyQt5.QtNetwork import QNetworkReply
|
||||||
from cura.Settings.GlobalStack import GlobalStack
|
|
||||||
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||||
|
from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
|
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
@ -244,10 +245,47 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
|
|
||||||
self._application.getMachineManager().addMachine(machine_type_id, group_name)
|
self._application.getMachineManager().addMachine(machine_type_id, group_name)
|
||||||
# connect the new machine to that network printer
|
# connect the new machine to that network printer
|
||||||
self._application.getMachineManager().associateActiveMachineWithPrinterDevice(discovered_device)
|
self.associateActiveMachineWithPrinterDevice(discovered_device)
|
||||||
# ensure that the connection states are refreshed.
|
# ensure that the connection states are refreshed.
|
||||||
self.refreshConnections()
|
self.refreshConnections()
|
||||||
|
|
||||||
|
def associateActiveMachineWithPrinterDevice(self, printer_device: Optional["PrinterOutputDevice"]) -> None:
|
||||||
|
if not printer_device:
|
||||||
|
return
|
||||||
|
|
||||||
|
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 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.findContainerStacks(type = "machine", **metadata_filter)
|
||||||
|
|
||||||
|
for container in containers:
|
||||||
|
container.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), printer_device.key)
|
||||||
|
|
||||||
|
container.removeMetaDataEntry("network_authentication_id")
|
||||||
|
container.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)
|
||||||
|
|
||||||
|
self.refreshConnections()
|
||||||
|
|
||||||
def _checkManualDevice(self, address):
|
def _checkManualDevice(self, address):
|
||||||
# Check if a UM3 family device exists at this address.
|
# Check if a UM3 family device exists at this address.
|
||||||
# If a printer responds, it will replace the preliminary printer created above
|
# If a printer responds, it will replace the preliminary printer created above
|
||||||
|
Loading…
x
Reference in New Issue
Block a user