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.
This commit is contained in:
Lipu Fei 2017-11-17 12:47:28 +01:00
parent e246784df2
commit 2c39612bc8
4 changed files with 14 additions and 4 deletions

View file

@ -443,7 +443,10 @@ class CuraContainerRegistry(ContainerRegistry):
extruder_stack.setUserChanges(user_container) extruder_stack.setUserChanges(user_container)
self.addContainer(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.setMaterialById("default")
extruder_stack.setQualityById("default") extruder_stack.setQualityById("default")

View file

@ -396,7 +396,9 @@ class CuraContainerStack(ContainerStack):
# \note This method assumes the stack has a valid machine definition. # \note This method assumes the stack has a valid machine definition.
def findDefaultVariant(self) -> Optional[ContainerInterface]: def findDefaultVariant(self) -> Optional[ContainerInterface]:
definition = self._getMachineDefinition() 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. # If the machine does not use variants, we should never set a variant.
return None return None

View file

@ -115,6 +115,11 @@ class ExtruderStack(CuraContainerStack):
if has_global_dependencies: if has_global_dependencies:
self.getNextStack().propertiesChanged.emit(key, properties) 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( extruder_stack_mime = MimeType(
name = "application/x-cura-extruderstack", name = "application/x-cura-extruderstack",

View file

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