Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc.lamboo <casperlamboo@gmail.com>2022-08-26 11:45:45 +0300
committerc.lamboo <casperlamboo@gmail.com>2022-08-26 11:45:45 +0300
commit8b84db705943217072003bec7d97439506a91eb0 (patch)
tree305c4c53f6489063964d7dad4792dec8ba07b7f7 /cura/Settings
parentd843921c7a0b483ba37cf868e811e831e8ef5a22 (diff)
Remove AbstractMachine
Having a separate class for the AbstractMachine complicated things; it's behaviour was extremely similar to the GlobalStack so adding one more stack container type in addition to the many similar setting container types we already have adds complexity to the system. Having these different classes for machines and abstract machines also add complexity to the update script as the abstract machines were stored in a separate folder from the machine types. Because of these reasons we decided to replace the AbstractMachine by a GlobalStack where the is_abstract_machine property metadata property is set to True. CURA-9514, CURA-9277 Co-authored-by: joeydelarago <joeydelarago@gmail.com>
Diffstat (limited to 'cura/Settings')
-rw-r--r--cura/Settings/AbstractMachine.py52
-rw-r--r--cura/Settings/CuraStackBuilder.py10
-rwxr-xr-xcura/Settings/GlobalStack.py30
3 files changed, 31 insertions, 61 deletions
diff --git a/cura/Settings/AbstractMachine.py b/cura/Settings/AbstractMachine.py
deleted file mode 100644
index 86909b6e29..0000000000
--- a/cura/Settings/AbstractMachine.py
+++ /dev/null
@@ -1,52 +0,0 @@
-from typing import List
-
-from UM.Settings.ContainerStack import ContainerStack
-from UM.Util import parseBool
-from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
-from cura.Settings.GlobalStack import GlobalStack
-from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
-from UM.Settings.ContainerRegistry import ContainerRegistry
-
-
-class AbstractMachine(GlobalStack):
- """ Represents a group of machines of the same type. This allows the user to select settings before selecting a printer. """
-
- def __init__(self, container_id: str) -> None:
- super().__init__(container_id)
- self.setMetaDataEntry("type", "abstract_machine")
-
- @classmethod
- def getMachines(cls, abstract_machine: ContainerStack, online_only = False) -> List[ContainerStack]:
- """ Fetches all container stacks that match definition_id with an abstract machine.
-
- :param abstractMachine: The abstract machine stack.
- :return: A list of Containers or an empty list if abstract_machine is not an "abstract_machine"
- """
- if not abstract_machine.getMetaDataEntry("type") == "abstract_machine":
- return []
-
- 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 == abstract_machine.definition.getId(), 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 have is_online = False but should still be included
- machines = filter(lambda machine: parseBool(machine.getMetaDataEntry("is_online", False) or ConnectionType.NetworkConnection in machine.configuredConnectionTypes), machines)
-
- return list(machines)
-
-
-## private:
-_abstract_machine_mime = MimeType(
- name = "application/x-cura-abstract-machine",
- comment = "Cura Abstract Machine",
- suffixes = ["global.cfg"]
-)
-
-MimeTypeDatabase.addMimeType(_abstract_machine_mime)
-ContainerRegistry.addContainerTypeByName(AbstractMachine, "abstract_machine", _abstract_machine_mime.name)
diff --git a/cura/Settings/CuraStackBuilder.py b/cura/Settings/CuraStackBuilder.py
index d711a61243..5a745f8f0a 100644
--- a/cura/Settings/CuraStackBuilder.py
+++ b/cura/Settings/CuraStackBuilder.py
@@ -9,7 +9,6 @@ from UM.Settings.Interfaces import DefinitionContainerInterface
from UM.Settings.InstanceContainer import InstanceContainer
from cura.Machines.ContainerTree import ContainerTree
-from .AbstractMachine import AbstractMachine
from .GlobalStack import GlobalStack
from .ExtruderStack import ExtruderStack
@@ -268,21 +267,21 @@ class CuraStackBuilder:
return definition_changes_container
@classmethod
- def createAbstractMachine(cls, definition_id: str) -> Optional[AbstractMachine]:
+ def createAbstractMachine(cls, definition_id: str) -> Optional[GlobalStack]:
"""Create a new instance of an abstract machine.
:param definition_id: The ID of the machine definition to use.
:return: The new Abstract Machine or None if an error occurred.
"""
- abstract_machine_id = definition_id + "_abstract_machine"
+ abstract_machine_id = f"{definition_id}_abstract_machine"
from cura.CuraApplication import CuraApplication
application = CuraApplication.getInstance()
registry = application.getContainerRegistry()
container_tree = ContainerTree.getInstance()
- if registry.findContainerStacks(type = "abstract_machine", id = abstract_machine_id):
+ if registry.findContainerStacks(is_abstract_machine = "True", id = abstract_machine_id):
# This abstract machine already exists
return None
@@ -296,7 +295,8 @@ class CuraStackBuilder:
machine_node = container_tree.machines[machine_definition.getId()]
name = machine_definition.getName()
- stack = AbstractMachine(abstract_machine_id)
+ stack = GlobalStack(abstract_machine_id)
+ stack.setMetaDataEntry("is_abstract_machine", True)
stack.setMetaDataEntry("is_online", True)
stack.setDefinition(machine_definition)
cls.createUserContainer(
diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py
index f0a6946f88..6a14f10fe4 100755
--- a/cura/Settings/GlobalStack.py
+++ b/cura/Settings/GlobalStack.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Ultimaker B.V.
+# Copyright (c) 2022 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from collections import defaultdict
@@ -8,10 +8,9 @@ import uuid
from PyQt6.QtCore import pyqtProperty, pyqtSlot, pyqtSignal
-from UM.Decorators import deprecated, override
+from UM.Decorators import override
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
from UM.Settings.ContainerStack import ContainerStack
-from UM.Settings.SettingInstance import InstanceState
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.Interfaces import PropertyEvaluationContext
from UM.Logger import Logger
@@ -344,13 +343,36 @@ class GlobalStack(CuraContainerStack):
def getName(self) -> str:
return self._metadata.get("group_name", self._metadata.get("name", ""))
- def setName(self, name: "str") -> None:
+ def setName(self, name: str) -> None:
super().setName(name)
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(