mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
Remove code duplication in createAbstractMachine
This also caused a crash when an abstract machine with multiple extruders was selected CURA-8463
This commit is contained in:
parent
46532828a4
commit
506f2b9820
3 changed files with 18 additions and 33 deletions
|
@ -81,7 +81,8 @@ class MachineListModel(ListModel):
|
||||||
for stack in online_machine_stacks:
|
for stack in online_machine_stacks:
|
||||||
self.addItem(stack)
|
self.addItem(stack)
|
||||||
# Remove this machine from the other stack list
|
# Remove this machine from the other stack list
|
||||||
other_machine_stacks.remove(stack)
|
if stack in other_machine_stacks:
|
||||||
|
other_machine_stacks.remove(stack)
|
||||||
|
|
||||||
for stack in other_machine_stacks:
|
for stack in other_machine_stacks:
|
||||||
self.addItem(stack)
|
self.addItem(stack)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# 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.ConfigurationErrorMessage import ConfigurationErrorMessage
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
@ -275,41 +275,26 @@ class CuraStackBuilder:
|
||||||
:return: The new Abstract Machine or None if an error occurred.
|
:return: The new Abstract Machine or None if an error occurred.
|
||||||
"""
|
"""
|
||||||
abstract_machine_id = f"{definition_id}_abstract_machine"
|
abstract_machine_id = f"{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()
|
|
||||||
|
|
||||||
if registry.findContainerStacks(is_abstract_machine = "True", id = abstract_machine_id):
|
abstract_machines = registry.findContainerStacks(id = abstract_machine_id)
|
||||||
# This abstract machine already exists
|
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
|
return None
|
||||||
|
|
||||||
match registry.findDefinitionContainers(type = "machine", id = definition_id):
|
stack.setName(name)
|
||||||
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_abstract_machine", True)
|
stack.setMetaDataEntry("is_online", 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)
|
return stack
|
||||||
|
|
||||||
registry.addContainer(stack)
|
|
||||||
|
|
||||||
return stack
|
|
|
@ -292,7 +292,6 @@ class GlobalStack(CuraContainerStack):
|
||||||
for extruder_train in extruder_trains:
|
for extruder_train in extruder_trains:
|
||||||
extruder_position = extruder_train.getMetaDataEntry("position")
|
extruder_position = extruder_train.getMetaDataEntry("position")
|
||||||
extruder_check_position.add(extruder_position)
|
extruder_check_position.add(extruder_position)
|
||||||
|
|
||||||
for check_position in range(machine_extruder_count):
|
for check_position in range(machine_extruder_count):
|
||||||
if str(check_position) not in extruder_check_position:
|
if str(check_position) not in extruder_check_position:
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue