diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index c2fe929957..51e7e81fef 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -402,7 +402,8 @@ class ExtruderManager(QObject): # Register the extruder trains by position for extruder_train in extruder_trains: - self._extruder_trains[global_stack_id][extruder_train.getMetaDataEntry("position")] = extruder_train + extruder_position = extruder_train.getMetaDataEntry("position") + self._extruder_trains[global_stack_id][extruder_position] = extruder_train # regardless of what the next stack is, we have to set it again, because of signal routing. ??? extruder_train.setParent(global_stack) diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 5d8a4505a5..cea59bcb70 100755 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -153,6 +153,23 @@ class GlobalStack(CuraContainerStack): return True + ## Perform some sanity checks on the global stack + # Sanity check for extruders; they must have positions 0 and up to machine_extruder_count - 1 + def isValid(self): + container_registry = ContainerRegistry.getInstance() + extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = self.getId()) + + machine_extruder_count = self.getProperty("machine_extruder_count", "value") + extruder_check_position = set() + 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 + return True + ## private: global_stack_mime = MimeType( diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 14f4f5fc33..c2b1e6dc5f 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -6,6 +6,7 @@ import time #Type hinting. from typing import List, Dict, TYPE_CHECKING, Optional +from UM.ConfigurationErrorMessage import ConfigurationErrorMessage from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Signal import Signal @@ -165,8 +166,6 @@ class MachineManager(QObject): if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id): # An active machine was saved, so restore it. self.setActiveMachine(active_machine_id) - # Make sure _active_container_stack is properly initiated - ExtruderManager.getInstance().setActiveExtruderIndex(0) def _onOutputDevicesChanged(self) -> None: self._printer_output_devices = [] @@ -357,6 +356,10 @@ class MachineManager(QObject): return global_stack = containers[0] + if not global_stack.isValid(): + # Mark global stack as invalid + ConfigurationErrorMessage.getInstance().addFaultyContainers(global_stack.getId()) + return # We're done here ExtruderManager.getInstance().setActiveExtruderIndex(0) # Switch to first extruder self._global_container_stack = global_stack Application.getInstance().setGlobalContainerStack(global_stack) diff --git a/plugins/MachineSettingsAction/MachineSettingsAction.py b/plugins/MachineSettingsAction/MachineSettingsAction.py index ded59bf934..7d5b317475 100755 --- a/plugins/MachineSettingsAction/MachineSettingsAction.py +++ b/plugins/MachineSettingsAction/MachineSettingsAction.py @@ -56,8 +56,6 @@ class MachineSettingsAction(MachineAction): if self._isEmptyDefinitionChanges(definition_changes_id): return - self._container_registry.removeContainer(definition_changes_id) - def _reset(self): if not self._global_container_stack: return