Use pretty-printed string for the AbstractMachine name

Cura-9277

Co-authored-by: joeydelarago <joeydelarago@gmail.com>
This commit is contained in:
c.lamboo 2022-08-19 16:35:00 +02:00
parent 761bf3b8fa
commit d7f119415f
2 changed files with 15 additions and 23 deletions

View file

@ -268,27 +268,25 @@ class CuraStackBuilder:
return definition_changes_container return definition_changes_container
@classmethod @classmethod
def createAbstractMachine(cls, name, definition_id): def createAbstractMachine(cls, definition_id) -> Optional[AbstractMachine]:
# cls.createMachine(definition_id, definition_id) """Create a new instance of an abstract machine.
"""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 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. :return: The new Abstract Machine or None if an error occurred.
""" """
abstract_machine_id = definition_id + "_abstract_machine"
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
application = CuraApplication.getInstance() application = CuraApplication.getInstance()
registry = application.getContainerRegistry() registry = application.getContainerRegistry()
container_tree = ContainerTree.getInstance() container_tree = ContainerTree.getInstance()
if registry.findContainerStacks(type="abstract_machine", id=definition_id): if registry.findContainerStacks(type="abstract_machine", id=abstract_machine_id):
# This abstract machine already exists # This abstract machine already exists
return return None
match registry.findDefinitionContainers(id=definition_id): match registry.findDefinitionContainers(type="machine", id=definition_id):
case []: case []:
# It should not be possible for the definition to be missing since an abstract machine will only # 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. # be created as a result of a machine with definition_id being created.
@ -296,26 +294,20 @@ class CuraStackBuilder:
return None return None
case [machine_definition, *_definitions]: case [machine_definition, *_definitions]:
machine_node = container_tree.machines[machine_definition.getId()] machine_node = container_tree.machines[machine_definition.getId()]
name = machine_definition.getName()
generated_name = registry.createUniqueName("machine", "", name, machine_definition.getName()) stack = AbstractMachine(abstract_machine_id)
# 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) stack.setDefinition(machine_definition)
cls.createUserContainer( cls.createUserContainer(
generated_name, name,
machine_definition, machine_definition,
stack,
application.empty_variant_container, application.empty_variant_container,
application.empty_material_container, application.empty_material_container,
machine_node.preferredGlobalQuality().container, machine_node.preferredGlobalQuality().container,
) )
# FIXME: This should have a pretty name stack.setName(name)
stack.setName(generated_name)
registry.addContainer(stack) registry.addContainer(stack)

View file

@ -405,7 +405,7 @@ class CloudOutputDeviceManager:
self._setOutputDeviceMetadata(device, new_machine) self._setOutputDeviceMetadata(device, new_machine)
CuraStackBuilder.createAbstractMachine(device.name, device.printerType) CuraStackBuilder.createAbstractMachine(device.printerType)
if activate: if activate:
CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId()) CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId())