diff options
author | joeydelarago <joeydelarago@gmail.com> | 2022-08-19 14:53:43 +0300 |
---|---|---|
committer | joeydelarago <joeydelarago@gmail.com> | 2022-08-19 14:53:43 +0300 |
commit | b82f1f4a8c66fbe0a587d1f0cc6a15b0ee55d421 (patch) | |
tree | 18545555834688720a1df079609462cf91be5105 /cura/Settings | |
parent | bf6422825b6ea6151740a53d873e1855cb8474d6 (diff) |
Add new Abstract machine stack type. This represents a type of printers (ultimaker_s3 etc).
These are created whenever a cloud printer of a new printer type is added.
CURA-9277
Co-authored-by: casperlamboo <c.lamboo@ultimaker.com>
Diffstat (limited to 'cura/Settings')
-rw-r--r-- | cura/Settings/AbstractMachine.py | 16 | ||||
-rw-r--r-- | cura/Settings/CuraContainerRegistry.py | 1 | ||||
-rw-r--r-- | cura/Settings/CuraStackBuilder.py | 73 |
3 files changed, 84 insertions, 6 deletions
diff --git a/cura/Settings/AbstractMachine.py b/cura/Settings/AbstractMachine.py new file mode 100644 index 0000000000..0dd4dfb1c0 --- /dev/null +++ b/cura/Settings/AbstractMachine.py @@ -0,0 +1,16 @@ +from typing import List + +from cura.Settings.GlobalStack import GlobalStack + + +class AbstractMachine(GlobalStack): + """ Behaves as a type of machine, represents multiple machines of the same type """ + + def __init__(self): + super(self) + self.setMetaDataEntry("type", "abstract_machine") + + def getMachinesOfType(self) -> List[GlobalStack]: + pass + + diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index 6ff856efcb..f65697277e 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -108,6 +108,7 @@ class CuraContainerRegistry(ContainerRegistry): :param container_type: :type{string} Type of the container (machine, quality, ...) :param container_name: :type{string} Name to check """ + # FIXME: this should check for abstract machine container_class = ContainerStack if container_type == "machine" else InstanceContainer return self.findContainersMetadata(container_type = container_class, id = container_name, type = container_type, ignore_case = True) or \ diff --git a/cura/Settings/CuraStackBuilder.py b/cura/Settings/CuraStackBuilder.py index ff9a795c43..bc02fd6cd1 100644 --- a/cura/Settings/CuraStackBuilder.py +++ b/cura/Settings/CuraStackBuilder.py @@ -9,6 +9,7 @@ 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 @@ -199,17 +200,25 @@ class CuraStackBuilder: :return: A new Global stack instance with the specified parameters. """ + stack = GlobalStack(new_stack_id) + stack.setDefinition(definition) + cls.createUserContainer(new_stack_id, definition, stack, variant_container, material_container, quality_container) + return stack + @classmethod + def createUserContainer(cls, new_stack_id: str, definition: DefinitionContainerInterface, + stack: GlobalStack, + variant_container: "InstanceContainer", + material_container: "InstanceContainer", + quality_container: "InstanceContainer"): from cura.CuraApplication import CuraApplication application = CuraApplication.getInstance() - registry = application.getContainerRegistry() - stack = GlobalStack(new_stack_id) - stack.setDefinition(definition) + registry = application.getContainerRegistry() # Create user container user_container = cls.createUserChangesContainer(new_stack_id + "_user", definition.getId(), new_stack_id, - is_global_stack = True) + is_global_stack=True) stack.definitionChanges = cls.createDefinitionChangesContainer(stack, new_stack_id + "_settings") stack.variant = variant_container @@ -221,8 +230,6 @@ class CuraStackBuilder: registry.addContainer(user_container) - return stack - @classmethod def createUserChangesContainer(cls, container_name: str, definition_id: str, stack_id: str, is_global_stack: bool) -> "InstanceContainer": @@ -259,3 +266,57 @@ class CuraStackBuilder: container_stack.definitionChanges = definition_changes_container return definition_changes_container + + @classmethod + def createAbstractMachine(cls, name, definition_id): + # cls.createMachine(definition_id, definition_id) + """Create a new instance of a machine. + + :param name: The name of the new machine. + :param definition_id: The ID of the machine definition to use. + :param machine_extruder_count: The number of extruders in the machine. + + :return: The new global stack or None if an error occurred. + """ + + from cura.CuraApplication import CuraApplication + application = CuraApplication.getInstance() + registry = application.getContainerRegistry() + container_tree = ContainerTree.getInstance() + + if registry.findContainerStacks(type="abstract_machine", id=definition_id): + # This abstract machine already exists + return + + match registry.findDefinitionContainers(id=definition_id): + case []: + # It should not be possible for the definition to be missing since an abstract machine will only + # be created as a result of a machine with definition_id being created. + Logger.error("w", "Definition {definition} was not found!", definition=definition_id) + return None + case [machine_definition, *_definitions]: + machine_node = container_tree.machines[machine_definition.getId()] + + generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName()) + # Make sure the new name does not collide with any definition or (quality) profile + # createUniqueName() only looks at other stacks, but not at definitions or quality profiles + # Note that we don't go for uniqueName() immediately because that function matches with ignore_case set to true + if registry.findContainersMetadata(id=generated_name): + generated_name = registry.uniqueName(generated_name) + + stack = AbstractMachine(generated_name) + stack.setDefinition(machine_definition) + cls.createUserContainer( + generated_name, + machine_definition, + application.empty_variant_container, + application.empty_material_container, + machine_node.preferredGlobalQuality().container, + ) + + # FIXME: This should have a pretty name + stack.setName(generated_name) + + registry.addContainer(stack) + + return stack |