diff --git a/cura/Settings/GlobalStack.py b/cura/Settings/GlobalStack.py index 6118843095..e1c24cf9e2 100644 --- a/cura/Settings/GlobalStack.py +++ b/cura/Settings/GlobalStack.py @@ -10,6 +10,7 @@ from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackErro from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.DefinitionContainer import DefinitionContainer from UM.Settings.ContainerRegistry import ContainerRegistry +from UM.Settings.Interfaces import ContainerInterface from . import Exceptions @@ -121,6 +122,18 @@ class GlobalStack(ContainerStack): def removeContainer(self, index: int) -> None: raise Exceptions.InvalidOperationError("Cannot remove a container from Global stack") + ## Overridden from ContainerStack + @override(ContainerStack) + def replaceContainer(self, index: int, container: ContainerInterface, postpone_emit: bool = False) -> None: + expected_type = _ContainerIndexes.IndexTypeMap[index] + if expected_type == "definition" and not isinstance(container, DefinitionContainer): + raise Exceptions.InvalidContainerError("Cannot replace container at index {index} with a container that is not a DefinitionContainer".format(index = index)) + if container != self._empty_instance_container and container.getMetaDataEntry("type") != expected_type: + raise Exceptions.InvalidContainerError("Cannot replace container at index {index} with a container that is not of {type} type".format(index = index, type = expected_type)) + + super().replaceContainer(index, container, postpone_emit) + + ## Overridden from ContainerStack @override(ContainerStack) def deserialize(self, contents: str) -> None: super().deserialize(contents) @@ -152,17 +165,18 @@ class GlobalStack(ContainerStack): self._containers = new_containers -## private: +## private: global_stack_mime = MimeType( name = "application/x-cura-globalstack", comment = "Cura Global Stack", - suffixes = [ "global.cfg" ] + suffixes = ["global.cfg"] ) MimeTypeDatabase.addMimeType(global_stack_mime) ContainerRegistry.addContainerTypeByName(GlobalStack, "global_stack", global_stack_mime.name) + class _ContainerIndexes: UserChanges = 0 QualityChanges = 1