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.
This commit is contained in:
Lipu Fei 2017-10-09 12:24:08 +02:00
parent d3b1563369
commit 852e59f310
2 changed files with 26 additions and 4 deletions

View file

@ -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.