-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add evaluation context processing for ContainerStack and SettingFunction
CURA-4358 - Make getProperty() and getRawProperty() in ContainerStack to be evaluation-context-aware. - Allow getRawProperty() to skip some containers if this info is provided by the context. - SettingFunction can now override operators with those provided in the evaluation context.
- Loading branch information
Showing
2 changed files
with
18 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,7 +196,7 @@ def setDirty(self, dirty: bool) -> None: | |
# result of evaluating that property with the current stack. If you need the | ||
# actual function, use getRawProperty() | ||
def getProperty(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None): | ||
value = self.getRawProperty(key, property_name) | ||
value = self.getRawProperty(key, property_name, context = context) | ||
if isinstance(value, SettingFunction): | ||
if context is not None: | ||
context.pushContainer(self) | ||
|
@@ -222,18 +222,28 @@ def getProperty(self, key: str, property_name: str, context: Optional[PropertyEv | |
# \return The raw property value of the property, or None if not found. Note that | ||
# the value might be a SettingFunction instance. | ||
# | ||
def getRawProperty(self, key, property_name, *, use_next = True, skip_until_container = None): | ||
for container in self._containers: | ||
def getRawProperty(self, key, property_name, *, context: Optional[PropertyEvaluationContext] = None, | ||
use_next = True, skip_until_container = None): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
diegopradogesto
Contributor
|
||
containers = self._containers | ||
if context is not None: | ||
# if context is provided, check if there is any container that needs to be skipped. | ||
start_index = context.context.get("evaluate_from_container_index", 0) | ||
if start_index >= len(self._containers): | ||
return None | ||
containers = self._containers[start_index:] | ||
|
||
for container in containers: | ||
if skip_until_container and container.getId() != skip_until_container: | ||
continue #Skip. | ||
skip_until_container = None #When we find the container, stop skipping. | ||
|
||
value = container.getProperty(key, property_name) | ||
value = container.getProperty(key, property_name, context) | ||
if value is not None: | ||
return value | ||
|
||
if self._next_stack and use_next: | ||
return self._next_stack.getRawProperty(key, property_name, use_next = use_next, skip_until_container = skip_until_container) | ||
return self._next_stack.getRawProperty(key, property_name, context = context, | ||
use_next = use_next, skip_until_container = skip_until_container) | ||
else: | ||
return None | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The changes seem to have the same functionality as skip_until_container, but I'm a bit confused about the PropertyEvaluationContext context. Here self._containers is used in combination with some keys being set in the context, but the PropertyEvaluationContext can contain its own stacks. So, is it the correct usage of PropertyEvaluationContext? The usage in getProperty is a bit different.