Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Prado Gesto <d.pradogesto@ultimaker.com>2017-10-11 12:05:01 +0300
committerDiego Prado Gesto <d.pradogesto@ultimaker.com>2017-10-11 12:05:01 +0300
commit71e8de13a83198846c9758803ae1f4f9349b6f91 (patch)
treefc6feacb1a24a62c40f6274be60f7e20c104f35b /cura/Settings/ExtruderManager.py
parent852e59f310017978360cdea217afb498b55aeddc (diff)
Fix retrieving setting values with "extruderValues()" and "resolveOrValue()"
CURA-4358 Using the context for override the extruderValues() and resolveOrValue() functions, for getting the correct values. Also indicate in the context to skip the first container in the stacks (user container)
Diffstat (limited to 'cura/Settings/ExtruderManager.py')
-rwxr-xr-xcura/Settings/ExtruderManager.py77
1 files changed, 76 insertions, 1 deletions
diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py
index 1c01b1fc8a..c8daca7f92 100755
--- a/cura/Settings/ExtruderManager.py
+++ b/cura/Settings/ExtruderManager.py
@@ -588,6 +588,46 @@ class ExtruderManager(QObject):
return result
+ ## Get all extruder values for a certain setting. This function will skip the user settings container.
+ #
+ # This is exposed to SettingFunction so it can be used in value functions.
+ #
+ # \param key The key of the setting to retrieve values for.
+ #
+ # \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list.
+ # If no extruder has the value, the list will contain the global value.
+ @staticmethod
+ def getDefaultExtruderValues(key):
+ global_stack = Application.getInstance().getGlobalContainerStack()
+ context = PropertyEvaluationContext(global_stack)
+ context.context["evaluate_from_container_index"] = 1 # skip the user settings container
+ context.context["override_operators"] = {
+ "extruderValue": ExtruderManager.getDefaultExtruderValue,
+ "extruderValues": ExtruderManager.getDefaultExtruderValues,
+ "resolveOrValue": ExtruderManager.getDefaultResolveOrValue
+ }
+
+ result = []
+ for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
+ # only include values from extruders that are "active" for the current machine instance
+ if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value", context = context):
+ continue
+
+ value = extruder.getRawProperty(key, "value", context = context)
+
+ if value is None:
+ continue
+
+ if isinstance(value, SettingFunction):
+ value = value(extruder, context = context)
+
+ result.append(value)
+
+ if not result:
+ result.append(global_stack.getProperty(key, "value", context = context))
+
+ return result
+
## Get all extruder values for a certain setting.
#
# This is exposed to qml for display purposes
@@ -622,11 +662,24 @@ class ExtruderManager(QObject):
return value
## Get the default value from the given extruder. This function will skip the user settings container.
+ #
+ # This is exposed to SettingFunction to use in value functions.
+ #
+ # \param extruder_index The index of the extruder to get the value from.
+ # \param key The key of the setting to get the value of.
+ #
+ # \return The value of the setting for the specified extruder or for the
+ # global stack if not found.
@staticmethod
def getDefaultExtruderValue(extruder_index, key):
extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index)
- context = PropertyEvaluationContext()
+ context = PropertyEvaluationContext(extruder)
context.context["evaluate_from_container_index"] = 1 # skip the user settings container
+ context.context["override_operators"] = {
+ "extruderValue": ExtruderManager.getDefaultExtruderValue,
+ "extruderValues": ExtruderManager.getDefaultExtruderValues,
+ "resolveOrValue": ExtruderManager.getDefaultResolveOrValue
+ }
if extruder:
value = extruder.getRawProperty(key, "value", context = context)
@@ -650,3 +703,25 @@ class ExtruderManager(QObject):
resolved_value = global_stack.getProperty(key, "value")
return resolved_value
+
+ ## Get the resolve value or value for a given key without looking the first container (user container)
+ #
+ # This is the effective value for a given key, it is used for values in the global stack.
+ # This is exposed to SettingFunction to use in value functions.
+ # \param key The key of the setting to get the value of.
+ #
+ # \return The effective value
+ @staticmethod
+ def getDefaultResolveOrValue(key):
+ global_stack = Application.getInstance().getGlobalContainerStack()
+ context = PropertyEvaluationContext(global_stack)
+ context.context["evaluate_from_container_index"] = 1 # skip the user settings container
+ context.context["override_operators"] = {
+ "extruderValue": ExtruderManager.getDefaultExtruderValue,
+ "extruderValues": ExtruderManager.getDefaultExtruderValues,
+ "resolveOrValue": ExtruderManager.getDefaultResolveOrValue
+ }
+
+ resolved_value = global_stack.getProperty(key, "value", context = context)
+
+ return resolved_value