From 230740ed64b0bc7ff401e4cb6b15545e87678363 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 4 May 2017 15:43:56 +0200 Subject: [PATCH] Fixup extruders that were converted from ContainerStack on load We need to make sure the extruder stacks get the proper next stack set, even when converting them from ContainerStack. Since the conversion can make no guarantees about the loading order, we need to add an extra step to post-process the extruders. Contributes to CURA-3497 --- cura/Settings/CuraContainerRegistry.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index bf8e475c38..2dc341e71b 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -227,6 +227,11 @@ class CuraContainerRegistry(ContainerRegistry): # If it hasn't returned by now, none of the plugins loaded the profile successfully. return {"status": "error", "message": catalog.i18nc("@info:status", "Profile {0} has an unknown file type or is corrupted.", file_name)} + @override(ContainerRegistry) + def load(self): + super().load() + self._fixupExtruders() + def _configureProfile(self, profile, id_seed, new_name): profile.setReadOnly(False) profile.setDirty(True) # Ensure the profiles are correctly saved @@ -309,6 +314,8 @@ class CuraContainerRegistry(ContainerRegistry): # It is not an extruder or machine, so do nothing with the stack return container + Logger.log("d", "Converting ContainerStack {stack} to {type}", stack = container.getId(), type = container_type) + new_stack = None if container_type == "extruder_train": new_stack = ExtruderStack.ExtruderStack(container.getId()) @@ -323,3 +330,21 @@ class CuraContainerRegistry(ContainerRegistry): os.remove(container.getPath()) return new_stack + + # Fix the extruders that were upgraded to ExtruderStack instances during addContainer. + # The stacks are now responsible for setting the next stack on deserialize. However, + # due to problems with loading order, some stacks may not have the proper next stack + # set after upgrading, because the proper global stack was not yet loaded. This method + # makes sure those extruders also get the right stack set. + def _fixupExtruders(self): + extruder_stacks = self.findContainers(ExtruderStack.ExtruderStack) + for extruder_stack in extruder_stacks: + if extruder_stack.getNextStack(): + # Has the right next stack, so ignore it. + continue + + machines = ContainerRegistry.getInstance().findContainerStacks(id=extruder_stack.getMetaDataEntry("machine", "")) + if machines: + extruder_stack.setNextStack(machines[0]) + else: + Logger.log("w", "Could not find machine {machine} for extruder {extruder}", machine = extruder_stack.getMetaDataEntry("machine"), extruder = extruder_stack.getId())