diff options
author | Remco Burema <r.burema@ultimaker.com> | 2022-09-02 18:49:39 +0300 |
---|---|---|
committer | Remco Burema <r.burema@ultimaker.com> | 2022-09-02 18:49:39 +0300 |
commit | a56a21cf9350ef03410467af92b4c059bf61d324 (patch) | |
tree | ea72b3d578a2a8857e102200fd3d14a5cd5e4194 /cura/Machines | |
parent | ccdbc3e06fa3b21e46168116e45e35f7ac063e50 (diff) |
W.I.P.: Press print on abstract cloud printer. User should see dialog.
Start of implementation. When printing on an abstract printer, a user should see a dialog with the matching concrete cloud printers to pick from to actually print. Names are not final. Very much a work in progress. Very not finished also.
start of implementation for CURA-9278
Diffstat (limited to 'cura/Machines')
-rw-r--r-- | cura/Machines/Models/CompatibleMachineModel.py | 73 | ||||
-rw-r--r-- | cura/Machines/Models/MachineListModel.py | 20 |
2 files changed, 85 insertions, 8 deletions
diff --git a/cura/Machines/Models/CompatibleMachineModel.py b/cura/Machines/Models/CompatibleMachineModel.py new file mode 100644 index 0000000000..a0a6fd8bb2 --- /dev/null +++ b/cura/Machines/Models/CompatibleMachineModel.py @@ -0,0 +1,73 @@ +# Copyright (c) 2022 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +# TODO?: documentation + +from typing import Optional + +from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal + +from UM.Qt.ListModel import ListModel +from UM.Settings.ContainerStack import ContainerStack +from UM.i18n import i18nCatalog +from UM.Util import parseBool + +from cura.PrinterOutput.PrinterOutputDevice import ConnectionType +from cura.Settings.CuraContainerRegistry import CuraContainerRegistry + + +class CompatibleMachineModel(ListModel): + NameRole = Qt.ItemDataRole.UserRole + 1 + IdRole = Qt.ItemDataRole.UserRole + 2 + ExtrudersRole = Qt.ItemDataRole.UserRole + 3 + + def __init__(self, parent: Optional[QObject] = None) -> None: + super().__init__(parent) + + self._filter_on_definition_id: Optional[str] = None + + self._catalog = i18nCatalog("cura") + + self.addRoleName(self.NameRole, "name") + self.addRoleName(self.IdRole, "id") + self.addRoleName(self.ExtrudersRole, "extruders") + + filterChanged = pyqtSignal(str) + + @pyqtSlot(str) + def setFilter(self, abstract_machine_id: str) -> None: + # TODO??: defensive coding; check if machine is abstract & abort/log if not + self._filter_on_definition_id = abstract_machine_id + + # Don't need a delayed update, since it's fire once on user click (either on 'print to cloud' or 'refresh'). + # So, no signals that could come in (too) quickly. + self.filterChanged.emit(self._filter_on_definition_id) + self._update() + + @pyqtProperty(str, fset=setFilter, notify=filterChanged) + def filter(self) -> str: + return self._filter_on_definition_id + + def _update(self) -> None: + self.clear() + if not self._filter_on_definition_id or self._filter_on_definition_id == "": + # TODO?: log + return + + from cura.CuraApplication import CuraApplication + machine_manager = CuraApplication.getInstance().getMachineManager() + compatible_machines = machine_manager.getMachinesWithDefinition(self._filter_on_definition_id, online_only = True) + # TODO: Handle 0 compatible machines -> option to close window? Message in card? (remember the design has a refresh button!) + + for container_stack in compatible_machines: + if parseBool(container_stack.getMetaDataEntry("hidden", False)) or parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)): + continue + self.addItem(container_stack) + + def addItem(self, container_stack: ContainerStack, machine_count: int = 0) -> None: + extruders = CuraContainerRegistry.getInstance().findContainerStacks(type="extruder_train", machine=container_stack.getId()) + self.appendItem({ + "name": container_stack.getName(), + "id": container_stack.getId(), + "extruders": [extruder.getMetaData().copy() for extruder in extruders] + }) diff --git a/cura/Machines/Models/MachineListModel.py b/cura/Machines/Models/MachineListModel.py index 55db072180..bc071e226f 100644 --- a/cura/Machines/Models/MachineListModel.py +++ b/cura/Machines/Models/MachineListModel.py @@ -5,10 +5,13 @@ # online cloud connected printers are represented within this ListModel. Additional information such as the number of # connected printers for each printer type is gathered. -from PyQt6.QtCore import Qt, QTimer, pyqtSlot, pyqtProperty, pyqtSignal +from typing import Optional + +from PyQt6.QtCore import Qt, QTimer, QObject, pyqtSlot, pyqtProperty, pyqtSignal from UM.Qt.ListModel import ListModel from UM.Settings.ContainerStack import ContainerStack +from UM.Settings.Interfaces import ContainerInterface from UM.i18n import i18nCatalog from UM.Util import parseBool from cura.PrinterOutput.PrinterOutputDevice import ConnectionType @@ -27,7 +30,7 @@ class MachineListModel(ListModel): IsAbstractMachineRole = Qt.ItemDataRole.UserRole + 7 ComponentTypeRole = Qt.ItemDataRole.UserRole + 8 - def __init__(self, parent=None) -> None: + def __init__(self, parent: Optional[QObject] = None) -> None: super().__init__(parent) self._show_cloud_printers = False @@ -66,7 +69,7 @@ class MachineListModel(ListModel): self._updateDelayed() self.showCloudPrintersChanged.emit(show_cloud_printers) - def _onContainerChanged(self, container) -> None: + def _onContainerChanged(self, container: ContainerInterface) -> None: """Handler for container added/removed events from registry""" # We only need to update when the added / removed container GlobalStack @@ -79,14 +82,15 @@ class MachineListModel(ListModel): def _update(self) -> None: self.clear() + from cura.CuraApplication import CuraApplication + machines_manager = CuraApplication.getInstance().getMachineManager() + other_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="machine") abstract_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(is_abstract_machine = "True") abstract_machine_stacks.sort(key = lambda machine: machine.getName(), reverse = True) for abstract_machine in abstract_machine_stacks: definition_id = abstract_machine.definition.getId() - from cura.CuraApplication import CuraApplication - machines_manager = CuraApplication.getInstance().getMachineManager() online_machine_stacks = machines_manager.getMachinesWithDefinition(definition_id, online_only = True) # Create a list item for abstract machine @@ -132,11 +136,11 @@ class MachineListModel(ListModel): has_connection |= connection_type in container_stack.configuredConnectionTypes self.appendItem({ - "componentType": "MACHINE", - "name": container_stack.getName(), + "componentType": "MACHINE", + "name": container_stack.getName(), "id": container_stack.getId(), "metadata": container_stack.getMetaData().copy(), "isOnline": parseBool(container_stack.getMetaDataEntry("is_online", False)) and has_connection, "isAbstractMachine": parseBool(container_stack.getMetaDataEntry("is_abstract_machine", False)), "machineCount": machine_count, - }) + }) |