mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-24 06:39:38 +08:00
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:
parent
d3b1563369
commit
852e59f310
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user