mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
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>
This commit is contained in:
parent
bf6422825b
commit
b82f1f4a8c
4 changed files with 88 additions and 8 deletions
16
cura/Settings/AbstractMachine.py
Normal file
16
cura/Settings/AbstractMachine.py
Normal file
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ class CuraContainerRegistry(ContainerRegistry):
|
||||||
:param container_type: :type{string} Type of the container (machine, quality, ...)
|
:param container_type: :type{string} Type of the container (machine, quality, ...)
|
||||||
:param container_name: :type{string} Name to check
|
:param container_name: :type{string} Name to check
|
||||||
"""
|
"""
|
||||||
|
# FIXME: this should check for abstract machine
|
||||||
container_class = ContainerStack if container_type == "machine" else InstanceContainer
|
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 \
|
return self.findContainersMetadata(container_type = container_class, id = container_name, type = container_type, ignore_case = True) or \
|
||||||
|
|
|
@ -9,6 +9,7 @@ from UM.Settings.Interfaces import DefinitionContainerInterface
|
||||||
from UM.Settings.InstanceContainer import InstanceContainer
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
from cura.Machines.ContainerTree import ContainerTree
|
from cura.Machines.ContainerTree import ContainerTree
|
||||||
|
from .AbstractMachine import AbstractMachine
|
||||||
from .GlobalStack import GlobalStack
|
from .GlobalStack import GlobalStack
|
||||||
from .ExtruderStack import ExtruderStack
|
from .ExtruderStack import ExtruderStack
|
||||||
|
|
||||||
|
@ -199,17 +200,25 @@ class CuraStackBuilder:
|
||||||
|
|
||||||
:return: A new Global stack instance with the specified parameters.
|
:return: A new Global stack instance with the specified parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
|
||||||
application = CuraApplication.getInstance()
|
|
||||||
registry = application.getContainerRegistry()
|
|
||||||
|
|
||||||
stack = GlobalStack(new_stack_id)
|
stack = GlobalStack(new_stack_id)
|
||||||
stack.setDefinition(definition)
|
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()
|
||||||
|
|
||||||
# Create user container
|
# Create user container
|
||||||
user_container = cls.createUserChangesContainer(new_stack_id + "_user", definition.getId(), new_stack_id,
|
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.definitionChanges = cls.createDefinitionChangesContainer(stack, new_stack_id + "_settings")
|
||||||
stack.variant = variant_container
|
stack.variant = variant_container
|
||||||
|
@ -221,8 +230,6 @@ class CuraStackBuilder:
|
||||||
|
|
||||||
registry.addContainer(user_container)
|
registry.addContainer(user_container)
|
||||||
|
|
||||||
return stack
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def createUserChangesContainer(cls, container_name: str, definition_id: str, stack_id: str,
|
def createUserChangesContainer(cls, container_name: str, definition_id: str, stack_id: str,
|
||||||
is_global_stack: bool) -> "InstanceContainer":
|
is_global_stack: bool) -> "InstanceContainer":
|
||||||
|
@ -259,3 +266,57 @@ class CuraStackBuilder:
|
||||||
container_stack.definitionChanges = definition_changes_container
|
container_stack.definitionChanges = definition_changes_container
|
||||||
|
|
||||||
return 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
|
||||||
|
|
|
@ -405,6 +405,8 @@ class CloudOutputDeviceManager:
|
||||||
|
|
||||||
self._setOutputDeviceMetadata(device, new_machine)
|
self._setOutputDeviceMetadata(device, new_machine)
|
||||||
|
|
||||||
|
CuraStackBuilder.createAbstractMachine(new_machine)
|
||||||
|
|
||||||
if activate:
|
if activate:
|
||||||
CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId())
|
CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue