diff options
author | Jaime van Kessel <nallath@gmail.com> | 2022-08-26 15:08:03 +0300 |
---|---|---|
committer | Jaime van Kessel <nallath@gmail.com> | 2022-08-26 15:08:03 +0300 |
commit | 506f2b982075c3a525fbba0ab088cf35771c688c (patch) | |
tree | f8d29a86ed82fc8564ae0adf540faa320c2a1c95 /cura/Settings | |
parent | 46532828a402fd2ce4b925b6dac85da57a9c8af4 (diff) |
Remove code duplication in createAbstractMachine
This also caused a crash when an abstract machine with multiple extruders was selected
CURA-8463
Diffstat (limited to 'cura/Settings')
-rw-r--r-- | cura/Settings/CuraStackBuilder.py | 51 | ||||
-rwxr-xr-x | cura/Settings/GlobalStack.py | 1 |
2 files changed, 18 insertions, 34 deletions
diff --git a/cura/Settings/CuraStackBuilder.py b/cura/Settings/CuraStackBuilder.py index 5a745f8f0a..813b3f7d2e 100644 --- a/cura/Settings/CuraStackBuilder.py +++ b/cura/Settings/CuraStackBuilder.py @@ -1,7 +1,7 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from typing import Optional +from typing import Optional, cast from UM.ConfigurationErrorMessage import ConfigurationErrorMessage from UM.Logger import Logger @@ -275,41 +275,26 @@ class CuraStackBuilder: :return: The new Abstract Machine or None if an error occurred. """ 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(is_abstract_machine = "True", id = abstract_machine_id): - # This abstract machine already exists + abstract_machines = registry.findContainerStacks(id = abstract_machine_id) + if abstract_machines: + return cast(GlobalStack, abstract_machines[0]) + definitions = registry.findDefinitionContainers(id=definition_id) + + name = "" + + if definitions: + name = definitions[0].getName() + stack = cls.createMachine(abstract_machine_id, definition_id) + if not stack: return None - match registry.findDefinitionContainers(type = "machine", 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(f"Definition {definition_id} was not found!") - return None - case [machine_definition, *_definitions]: - machine_node = container_tree.machines[machine_definition.getId()] - name = machine_definition.getName() - - stack = GlobalStack(abstract_machine_id) - stack.setMetaDataEntry("is_abstract_machine", True) - stack.setMetaDataEntry("is_online", True) - stack.setDefinition(machine_definition) - cls.createUserContainer( - name, - machine_definition, - stack, - application.empty_variant_container, - application.empty_material_container, - machine_node.preferredGlobalQuality().container, - ) - - stack.setName(name) - - registry.addContainer(stack) - - return stack + stack.setName(name) + + stack.setMetaDataEntry("is_abstract_machine", True) + stack.setMetaDataEntry("is_online", True) + + return stack
\ No newline at end of file diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 3c13f236ab..43232da725 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -292,7 +292,6 @@ class GlobalStack(CuraContainerStack): for extruder_train in extruder_trains: extruder_position = extruder_train.getMetaDataEntry("position") extruder_check_position.add(extruder_position) - for check_position in range(machine_extruder_count): if str(check_position) not in extruder_check_position: return False |