Skip to content

Commit

Permalink
Merge branch 'main' into CURA-11761_container_stack_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
HellAholic authored Sep 19, 2024
2 parents ddd53ff + 7089e09 commit 2be76be
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion UM/Settings/DefinitionContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def _processFunction(self, definition: SettingDefinition, property_name: str) ->
settings_dependencies.update(function.getUsedSettingKeys())

try:
settings_dependencies.update(definition.depends_on_settings)
settings_dependencies.update(definition.force_depends_on_settings)
except AttributeError:
pass

Expand Down
2 changes: 1 addition & 1 deletion UM/Settings/SettingDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def _clearClassCache(cls):
# For bool type: if the value is the same as the error value, the setting will be in the error state.
"error_value": {"type": DefinitionPropertyType.Function, "required": False, "read_only": True, "default": None, "depends_on": None},
# Optional list of settings that a setting explicitely depends on, which is useful when this can not be fully calculated from the formula.
"depends_on_settings": {"type": DefinitionPropertyType.Any, "required": False, "read_only": True, "default": [], "depends_on": None},
"force_depends_on_settings": {"type": DefinitionPropertyType.Any, "required": False, "read_only": True, "default": [], "depends_on": None},
} # type: Dict[str, Dict[str, Any]]

__type_definitions = {
Expand Down
3 changes: 1 addition & 2 deletions UM/Settings/SettingFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def __call__(self, value_provider: ContainerInterface, context: Optional[Propert
local_variables[name] = value

if additional_variables is not None:
for name, value in additional_variables.items():
local_variables[name] = value
local_variables |= additional_variables

globals_variables: Dict[str, Any] = {}
globals_variables.update(globals())
Expand Down
11 changes: 9 additions & 2 deletions UM/Settings/SettingInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def updateRelations(self, container: ContainerInterface, emit_signals: bool = Tr
property_names.insert(0, "value")

CachedMemberFunctions.clearInstanceCache(self)

# Note: The global stack is only used in case of cross-stack relations ('force_depends_on_settings'), see below.
from UM.Application import Application
global_stack_container = Application.getInstance().getGlobalContainerStack()

for property_name in property_names:
if SettingDefinition.isReadOnlyProperty(property_name):
Expand All @@ -259,10 +263,13 @@ def updateRelations(self, container: ContainerInterface, emit_signals: bool = Tr
changed_relations = SettingInstance._listRelations(self.definition.key, frozenset(), self._definition.relationsAsFrozenSet(), frozenset([property_name]))

for relation in changed_relations:
container.propertyChanged.emit(relation.target.key, relation.role)
used_container = container
if self.definition.key in relation.target.force_depends_on_settings:
used_container = global_stack_container
used_container.propertyChanged.emit(relation.target.key, relation.role)
# If the value/minimum value/etc state is updated, the validation state must be re-evaluated
if relation.role in {"value", "minimum_value", "maximum_value", "minimum_value_warning", "maximum_value_warning"}:
container.propertyChanged.emit(relation.target.key, "validationState")
used_container.propertyChanged.emit(relation.target.key, "validationState")

@staticmethod
@lru_cache
Expand Down
1 change: 1 addition & 0 deletions examples/definition_query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
SettingDefinition.addSupportedProperty("settable_per_extruder", DefinitionPropertyType.Any, default = True, read_only = True)
SettingDefinition.addSupportedProperty("settable_per_meshgroup", DefinitionPropertyType.Any, default = True, read_only = True)
SettingDefinition.addSupportedProperty("settable_globally", DefinitionPropertyType.Any, default = True, read_only = True)
SettingDefinition.addSupportedProperty("force_depends_on_settings", DefinitionPropertyType.Any, default = [], read_only = True)
SettingDefinition.addSupportedProperty("limit_to_extruder", DefinitionPropertyType.Function, default = "-1")
SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default = None)
SettingDefinition.addSettingType("extruder", None, str, Validator)
Expand Down

0 comments on commit 2be76be

Please sign in to comment.