mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
WIP: Implement add machine from network device
This commit is contained in:
parent
f7f5123fea
commit
de9f6f47bd
5 changed files with 80 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
from typing import Callable, List, Optional, TYPE_CHECKING
|
from typing import Callable, List, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
|
||||||
|
@ -13,6 +15,7 @@ class DiscoveredPrinter(QObject):
|
||||||
def __init__(self, ip_address: str, key: str, name: str, create_callback: Callable[[str], None], machine_type: str,
|
def __init__(self, ip_address: str, key: str, name: str, create_callback: Callable[[str], None], machine_type: str,
|
||||||
device, parent = None) -> None:
|
device, parent = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self._ip_address = ip_address
|
self._ip_address = ip_address
|
||||||
self._key = key
|
self._key = key
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -40,10 +43,11 @@ class DiscoveredPrinter(QObject):
|
||||||
def machine_type(self) -> str:
|
def machine_type(self) -> str:
|
||||||
return self._machine_type
|
return self._machine_type
|
||||||
|
|
||||||
def setMachineType(self, machine_type: str) -> None:
|
# Machine type string with underscores "_" replaced with spaces " "
|
||||||
if self._machine_type != machine_type:
|
@pyqtProperty(str, notify = machineTypeChanged)
|
||||||
self._machine_type = machine_type
|
def machine_type_with_spaces(self) -> str:
|
||||||
self.machineTypeChanged.emit()
|
from cura.CuraApplication import CuraApplication
|
||||||
|
return CuraApplication.getInstance().getMachineManager().getMachineTypeNameFromId(self._machine_type)
|
||||||
|
|
||||||
@pyqtProperty(QObject, constant = True)
|
@pyqtProperty(QObject, constant = True)
|
||||||
def device(self):
|
def device(self):
|
||||||
|
|
|
@ -1657,3 +1657,47 @@ class MachineManager(QObject):
|
||||||
abbr_machine += stripped_word
|
abbr_machine += stripped_word
|
||||||
|
|
||||||
return abbr_machine
|
return abbr_machine
|
||||||
|
|
||||||
|
def getMachineTypeNameFromId(self, machine_type_id: str) -> str:
|
||||||
|
machine_type_name = ""
|
||||||
|
results = self._container_registry.findDefinitionContainersMetadata(id = machine_type_id)
|
||||||
|
if results:
|
||||||
|
machine_type_name = results[0]["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()
|
||||||
|
|
||||||
|
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._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)
|
||||||
|
|
||||||
|
else: # Global stack didn't have a connection yet, configure it.
|
||||||
|
global_stack.setMetaDataEntry("um_network_key", printer_device.key)
|
||||||
|
global_stack.addConfiguredConnectionType(printer_device.connectionType.value)
|
||||||
|
|
|
@ -218,7 +218,22 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
||||||
# TODO: This needs to be implemented. It's supposed to create a machine given a unique key as already discovered
|
# TODO: This needs to be implemented. It's supposed to create a machine given a unique key as already discovered
|
||||||
# by this plugin.
|
# by this plugin.
|
||||||
pass
|
discovered_device = self._discovered_devices.get(key)
|
||||||
|
if discovered_device is None:
|
||||||
|
Logger.log("e", "Could not find discovered device with key [%s]", key)
|
||||||
|
return
|
||||||
|
|
||||||
|
group_name = discovered_device.getProperty("name")
|
||||||
|
machine_type_id = discovered_device.getProperty("printer_type")
|
||||||
|
|
||||||
|
Logger.log("i", "Creating machine from network device with key = [%s], group name = [%s], printer type = [%s]",
|
||||||
|
key, group_name, machine_type_id)
|
||||||
|
|
||||||
|
self._application.getMachineManager().addMachine(machine_type_id, group_name)
|
||||||
|
# connect the new machine to that network printer
|
||||||
|
self._application.getMachineManager().associateActiveMachineWithPrinterDevice(discovered_device)
|
||||||
|
# ensure that the connection states are refreshed.
|
||||||
|
self.reCheckConnections()
|
||||||
|
|
||||||
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.
|
||||||
|
|
|
@ -24,6 +24,8 @@ Button
|
||||||
property var outputDevice: null
|
property var outputDevice: null
|
||||||
property var printerTypesList: []
|
property var printerTypesList: []
|
||||||
|
|
||||||
|
property var updatePrinterTypesFunction: updatePrinterTypesList
|
||||||
|
|
||||||
function updatePrinterTypesList()
|
function updatePrinterTypesList()
|
||||||
{
|
{
|
||||||
printerTypesList = (outputDevice != null) ? outputDevice.uniquePrinterTypes : []
|
printerTypesList = (outputDevice != null) ? outputDevice.uniquePrinterTypes : []
|
||||||
|
@ -87,14 +89,14 @@ Button
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: outputDevice
|
target: outputDevice
|
||||||
onUniqueConfigurationsChanged: updatePrinterTypesList()
|
onUniqueConfigurationsChanged: updatePrinterTypesFunction()
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: Cura.MachineManager
|
target: Cura.MachineManager
|
||||||
onOutputDevicesChanged: updatePrinterTypesList()
|
onOutputDevicesChanged: updatePrinterTypesFunction()
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: updatePrinterTypesList()
|
Component.onCompleted: updatePrinterTypesFunction()
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,13 @@ Item
|
||||||
anchors.rightMargin: 10
|
anchors.rightMargin: 10
|
||||||
outputDevice: modelData.device
|
outputDevice: modelData.device
|
||||||
|
|
||||||
|
updatePrinterTypesFunction: updateMachineTypes
|
||||||
|
|
||||||
|
function updateMachineTypes()
|
||||||
|
{
|
||||||
|
printerTypesList = [ modelData.machine_type_with_spaces ]
|
||||||
|
}
|
||||||
|
|
||||||
checkable: false
|
checkable: false
|
||||||
selected: ListView.view.currentIndex == model.index
|
selected: ListView.view.currentIndex == model.index
|
||||||
onClicked:
|
onClicked:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue