mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-18 04:07:57 -06:00
Add a createMachine method to CuraStackBuilder that creates a complete machine
This commit is contained in:
parent
df8bba6c96
commit
f154db13b1
1 changed files with 48 additions and 3 deletions
|
@ -7,11 +7,50 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
|
|
||||||
from .GlobalStack import GlobalStack
|
from .GlobalStack import GlobalStack
|
||||||
from .ExtruderStack import ExtruderStack
|
from .ExtruderStack import ExtruderStack
|
||||||
|
from .CuraContainerStack import CuraContainerStack
|
||||||
|
|
||||||
class CuraStackBuilder:
|
class CuraStackBuilder:
|
||||||
@staticmethod
|
@classmethod
|
||||||
def createExtruderStack(new_stack_id: str, definition_id: str, **kwargs) -> ExtruderStack:
|
def createMachine(cls, name: str, definition_id: str) -> GlobalStack:
|
||||||
registry = ContainerRegistry.getInstance()
|
cls.__registry = ContainerRegistry.getInstance()
|
||||||
|
definitions = cls.__registry.findDefinitionContainers(id = definition_id)
|
||||||
|
if not definitions:
|
||||||
|
Logger.log("w", "Definition {definition} was not found!", definition = definition_id)
|
||||||
|
return None
|
||||||
|
|
||||||
|
machine_definition = definitions[0]
|
||||||
|
name = cls.__registry.createUniqueName("machine", "", name, machine_definition.name)
|
||||||
|
|
||||||
|
new_global_stack = cls.createGlobalStack(
|
||||||
|
new_stack_id = name,
|
||||||
|
definition = machine_definition,
|
||||||
|
quality = "default",
|
||||||
|
material = "default",
|
||||||
|
variant = "default",
|
||||||
|
)
|
||||||
|
|
||||||
|
for extruder_definition in cls.__registry.findDefinitionContainers(machine = machine_definition.id):
|
||||||
|
position = extruder_definition.getMetaDataEntry("position", None)
|
||||||
|
if not position:
|
||||||
|
Logger.log("w", "Extruder definition %s specifies no position metadata entry.", extruder_definition.id)
|
||||||
|
|
||||||
|
new_extruder_id = cls.__registry.uniqueName(extruder_definition.id)
|
||||||
|
new_extruder = cls.createExtruderStack(
|
||||||
|
new_extruder_id = new_extruder_id,
|
||||||
|
definition = extruder_definition,
|
||||||
|
machine_definition = machine_definition,
|
||||||
|
quality = "default",
|
||||||
|
material = "default",
|
||||||
|
variant = "default",
|
||||||
|
next_stack = new_global_stack
|
||||||
|
)
|
||||||
|
|
||||||
|
return new_global_stack
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def createExtruderStack(cls, new_stack_id: str, definition: DefinitionContainer, machine_definition: DefinitionContainer, **kwargs) -> ExtruderStack:
|
||||||
|
cls.__registry = ContainerRegistry.getInstance()
|
||||||
|
|
||||||
stack = ExtruderStack(new_stack_id)
|
stack = ExtruderStack(new_stack_id)
|
||||||
|
|
||||||
|
@ -84,3 +123,9 @@ class CuraStackBuilder:
|
||||||
registry.addContainer(user_container)
|
registry.addContainer(user_container)
|
||||||
|
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
|
# Convenience variable
|
||||||
|
# It should get set before any private functions are called so the privates do not need to
|
||||||
|
# re-get the container registry.
|
||||||
|
__registry = None # type: ContainerRegistry
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue