Move getMachinesWithDefinition to MachinesManager

CURA-9514, CURA-9277
This commit is contained in:
c.lamboo 2022-08-26 11:16:10 +02:00
parent 8b84db7059
commit f000b75661
3 changed files with 31 additions and 27 deletions

View file

@ -9,7 +9,7 @@ from UM.i18n import i18nCatalog
from UM.Util import parseBool
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
from cura.Settings.GlobalStack import GlobalStack, getMachinesWithDefinition
from cura.Settings.GlobalStack import GlobalStack
class MachineListModel(ListModel):
@ -65,7 +65,9 @@ class MachineListModel(ListModel):
for abstract_machine in abstract_machine_stacks:
definition_id = abstract_machine.definition.getId()
online_machine_stacks = getMachinesWithDefinition(definition_id, online_only = True)
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
self.addItem(abstract_machine, len(online_machine_stacks))

View file

@ -349,31 +349,6 @@ class GlobalStack(CuraContainerStack):
nameChanged = pyqtSignal()
name = pyqtProperty(str, fget=getName, fset=setName, notify=nameChanged)
def getMachinesWithDefinition(definition_id: str, online_only = False) -> List[ContainerStack]:
""" Fetches all container stacks that match definition_id.
:param definition_id: The id of the machine definition.
:return: A list of Containers that match definition_id
"""
from cura.CuraApplication import CuraApplication # In function to avoid circular import
application = CuraApplication.getInstance()
registry = application.getContainerRegistry()
machines = registry.findContainerStacks(type="machine")
# Filter machines that match definition
machines = filter(lambda machine: machine.definition.id == definition_id, machines)
# Filter only LAN and Cloud printers
machines = filter(lambda machine: ConnectionType.CloudConnection in machine.configuredConnectionTypes or
ConnectionType.NetworkConnection in machine.configuredConnectionTypes, machines)
if online_only:
# LAN printers can have is_online = False but should still be included, their online status is only checked when
# they are the active printer.
machines = filter(lambda machine: parseBool(machine.getMetaDataEntry("is_online", False) or
ConnectionType.NetworkConnection in machine.configuredConnectionTypes), machines)
return list(machines)
## private:
global_stack_mime = MimeType(
name = "application/x-cura-globalstack",

View file

@ -19,6 +19,7 @@ from UM.Logger import Logger
from UM.Message import Message
from UM.Settings.SettingFunction import SettingFunction
from UM.Settings.ContainerStack import ContainerStack
from UM.Signal import postponeSignals, CompressTechnique
import cura.CuraApplication # Imported like this to prevent circular references.
@ -186,6 +187,32 @@ class MachineManager(QObject):
self.outputDevicesChanged.emit()
def getMachinesWithDefinition(self, definition_id: str, online_only=False) -> List[ContainerStack]:
""" Fetches all container stacks that match definition_id.
:param definition_id: The id of the machine definition.
:return: A list of Containers that match definition_id
"""
from cura.CuraApplication import CuraApplication # In function to avoid circular import
application = CuraApplication.getInstance()
registry = application.getContainerRegistry()
machines = registry.findContainerStacks(type="machine")
# Filter machines that match definition
machines = filter(lambda machine: machine.definition.id == definition_id, machines)
# Filter only LAN and Cloud printers
machines = filter(lambda machine: ConnectionType.CloudConnection in machine.configuredConnectionTypes or
ConnectionType.NetworkConnection in machine.configuredConnectionTypes,
machines)
if online_only:
# LAN printers can have is_online = False but should still be included,
# their online status is only checked when they are the active printer.
machines = filter(lambda machine: parseBool(machine.getMetaDataEntry("is_online", False) or
ConnectionType.NetworkConnection in machine.configuredConnectionTypes),
machines)
return list(machines)
@pyqtProperty(QObject, notify = currentConfigurationChanged)
def currentConfiguration(self) -> PrinterConfigurationModel:
return self._current_printer_configuration