From b9f01b30c8661a9560927dd2994f621248d3430b Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Mon, 20 Mar 2017 17:28:01 +0100 Subject: [PATCH] Convert generic "ContainerStack" to an Extruder or Global stack Dependendant on the "type" metadata key, we create either an ExtruderStack or a GlobalStack instance to replace the ContainerStack instance. This should allow for transparent upgrades to the new classes. Contributes to CURA-3497 --- cura/Settings/CuraContainerRegistry.py | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index 3982418070..bbdc7d6d9e 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -26,6 +26,14 @@ class CuraContainerRegistry(ContainerRegistry): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + ## Overridden from ContainerRegistry + def addContainer(self, container): + # Note: Intentional check with type() because we want to ignore subclasses + if type(container) == ContainerStack: + container = self._convertContainerStack(container) + + super().addContainer(container) + ## Create a name that is not empty and unique # \param container_type \type{string} Type of the container (machine, quality, ...) # \param current_name \type{} Current name of the container, which may be an acceptable option @@ -284,3 +292,26 @@ class CuraContainerRegistry(ContainerRegistry): if global_container_stack: return parseBool(global_container_stack.getMetaDataEntry("has_machine_quality", False)) return False + + def _convertContainerStack(self, container): + assert type(container) == ContainerStack + + container_type = container.getMetaDataEntry("type") + if container_type not in ("extruder_train", "machine"): + # It is not an extruder or machine, so do nothing with the stack + return container + + new_stack = None + if container_type == "extruder_train": + new_stack = ExtruderStack(container.getId()) + else: + new_stack = GlobalStack(container.getId()) + + container_contents = container.serialize() + new_stack.deserialize(container_contents) + + # Delete the old configuration file so we do not get double stacks + if os.path.isfile(container.getPath()): + os.remove(container.getPath()) + + return new_stack