diff options
author | Lipu Fei <lipu.fei815@gmail.com> | 2017-10-09 13:24:08 +0300 |
---|---|---|
committer | Lipu Fei <lipu.fei815@gmail.com> | 2017-10-09 13:24:08 +0300 |
commit | 852e59f310017978360cdea217afb498b55aeddc (patch) | |
tree | b4d3dec35c257e67f6837b4796152e1766b1ff62 /cura/Settings | |
parent | d3b1563369f21c153f6d8ddbd6f21740277abffa (diff) |
Fix retrieving default values with "extruderValue()"
CURA-4358
Use evaluation context to override the default extruderValue()
function with getDefaultExtruderValue() so it can get the correct
default values from each extruder.
Diffstat (limited to 'cura/Settings')
-rwxr-xr-x | cura/Settings/ExtruderManager.py | 17 | ||||
-rw-r--r-- | cura/Settings/UserChangesModel.py | 13 |
2 files changed, 26 insertions, 4 deletions
diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 9e17ce028d..1c01b1fc8a 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -16,6 +16,7 @@ from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.SettingFunction import SettingFunction from UM.Settings.ContainerStack import ContainerStack from UM.Settings.Interfaces import DefinitionContainerInterface +from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext from typing import Optional, List, TYPE_CHECKING, Union if TYPE_CHECKING: @@ -620,6 +621,22 @@ class ExtruderManager(QObject): return value + ## Get the default value from the given extruder. This function will skip the user settings container. + @staticmethod + def getDefaultExtruderValue(extruder_index, key): + extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index) + context = PropertyEvaluationContext() + context.context["evaluate_from_container_index"] = 1 # skip the user settings container + + if extruder: + value = extruder.getRawProperty(key, "value", context = context) + if isinstance(value, SettingFunction): + value = value(extruder, context = context) + else: # Just a value from global. + value = Application.getInstance().getGlobalContainerStack().getProperty(key, "value", context = context) + + return value + ## Get the resolve value or value for a given key # # This is the effective value for a given key, it is used for values in the global stack. diff --git a/cura/Settings/UserChangesModel.py b/cura/Settings/UserChangesModel.py index 8b61186650..d47468b808 100644 --- a/cura/Settings/UserChangesModel.py +++ b/cura/Settings/UserChangesModel.py @@ -6,6 +6,7 @@ from cura.Settings.ExtruderManager import ExtruderManager from UM.Settings.ContainerRegistry import ContainerRegistry from UM.i18n import i18nCatalog from UM.Settings.SettingFunction import SettingFunction +from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext from collections import OrderedDict import os @@ -66,8 +67,12 @@ class UserChangesModel(ListModel): containers.extend(latest_stack.getContainers()) latest_stack = latest_stack.getNextStack() - # Drop the user container. + # Override "getExtruderValue" with "getDefaultExtruderValue" so we can get the default values user_changes = containers.pop(0) + default_value_resolve_context = PropertyEvaluationContext(stack) + default_value_resolve_context.context["override_operators"] = { + "extruderValue": ExtruderManager.getDefaultExtruderValue + } for setting_key in user_changes.getAllKeys(): original_value = None @@ -90,16 +95,16 @@ class UserChangesModel(ListModel): for container in containers: if stack == global_stack: - resolve = global_stack.getProperty(setting_key, "resolve") + resolve = global_stack.getProperty(setting_key, "resolve", default_value_resolve_context) if resolve is not None: original_value = resolve break - original_value = container.getProperty(setting_key, "value") + original_value = container.getProperty(setting_key, "value", default_value_resolve_context) # If a value is a function, ensure it's called with the stack it's in. if isinstance(original_value, SettingFunction): - original_value = original_value(stack) + original_value = original_value(stack, default_value_resolve_context) if original_value is not None: break |