Browse Source

Fix UM2 upgrade regarding the variant

CURA-4482

UM2 by default doesn't have variants, but if the user enables Olsson
Block, the variant option will become available. This commit fixes the
following cases:

- Make sure that the variant is set on the extruder stack but not the
  global stack
- Extruder stacks don't contain information such as has_variant. Such
  info should be retrieved from the global stack and not just from the
  definition container because they can be overriden by other
  containers.
Lipu Fei 7 years ago
parent
commit
2c39612bc8

+ 4 - 1
cura/Settings/CuraContainerRegistry.py

@@ -443,7 +443,10 @@ class CuraContainerRegistry(ContainerRegistry):
                 extruder_stack.setUserChanges(user_container)
                 self.addContainer(user_container)
 
-            extruder_stack.setVariantById("default")
+            variant_id = "default"
+            if machine.variant.getId() != "empty_variant":
+                variant_id = machine.variant.getId()
+            extruder_stack.setVariantById(variant_id)
             extruder_stack.setMaterialById("default")
             extruder_stack.setQualityById("default")
 

+ 3 - 1
cura/Settings/CuraContainerStack.py

@@ -396,7 +396,9 @@ class CuraContainerStack(ContainerStack):
     #   \note This method assumes the stack has a valid machine definition.
     def findDefaultVariant(self) -> Optional[ContainerInterface]:
         definition = self._getMachineDefinition()
-        if not definition.getMetaDataEntry("has_variants"):
+        # has_variants can be overridden in other containers and stacks.
+        # In the case of UM2, it is overridden in the GlobalStack
+        if not self.getMetaDataEntry("has_variants"):
             # If the machine does not use variants, we should never set a variant.
             return None
 

+ 5 - 0
cura/Settings/ExtruderStack.py

@@ -115,6 +115,11 @@ class ExtruderStack(CuraContainerStack):
             if has_global_dependencies:
                 self.getNextStack().propertiesChanged.emit(key, properties)
 
+    def findDefaultVariant(self):
+        # The default variant is defined in the machine stack and/or definition, so use the machine stack to find
+        # the default variant.
+        return self.getNextStack().findDefaultVariant()
+
 
 extruder_stack_mime = MimeType(
     name = "application/x-cura-extruderstack",

+ 2 - 2
plugins/UltimakerMachineActions/UM2UpgradeSelection.py

@@ -37,7 +37,7 @@ class UM2UpgradeSelection(MachineAction):
     def setHasVariants(self, has_variants = True):
         global_container_stack = Application.getInstance().getGlobalContainerStack()
         if global_container_stack:
-            variant_container = global_container_stack.variant
+            variant_container = global_container_stack.extruders["0"].variant
             variant_index = global_container_stack.getContainerIndex(variant_container)
 
             if has_variants:
@@ -52,7 +52,7 @@ class UM2UpgradeSelection(MachineAction):
                     search_criteria = { "type": "variant", "definition": "ultimaker2", "id": "*0.4*" }
                     containers = self._container_registry.findInstanceContainers(**search_criteria)
                     if containers:
-                        global_container_stack.variant = containers[0]
+                        global_container_stack.extruders["0"].variant = containers[0]
             else:
                 # The metadata entry is stored in an ini, and ini files are parsed as strings only.
                 # Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.