mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-29 07:14:24 +08:00

CURA-4186 In a per-object setting, if there is user defined value, use that first. If the value is default, then evaluate it with the normal routine.
54 lines
2.6 KiB
Python
54 lines
2.6 KiB
Python
from typing import Any, Optional
|
|
|
|
from UM.Decorators import override
|
|
from UM.Settings.Interfaces import PropertyEvaluationContext
|
|
from UM.Settings.ContainerStack import ContainerStack
|
|
from UM.Settings.SettingInstance import InstanceState
|
|
|
|
|
|
class PerObjectContainerStack(ContainerStack):
|
|
|
|
@override(ContainerStack)
|
|
def getProperty(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None) -> Any:
|
|
if context is None:
|
|
context = PropertyEvaluationContext()
|
|
context.pushContainer(self)
|
|
|
|
# this import has to be here otherwise there will be a circular import loop
|
|
from cura.CuraApplication import CuraApplication
|
|
global_stack = CuraApplication.getInstance().getGlobalContainerStack()
|
|
|
|
# Return the user defined value if present, otherwise, evaluate the value according to the default routine.
|
|
if self.getContainer(0).hasProperty(key, property_name):
|
|
if self.getContainer(0)._instances[key].state == InstanceState.User:
|
|
result = super().getProperty(key, property_name, context)
|
|
context.popContainer()
|
|
return result
|
|
|
|
# Handle the "limit_to_extruder" property.
|
|
limit_to_extruder = super().getProperty(key, "limit_to_extruder", context)
|
|
if limit_to_extruder is not None:
|
|
limit_to_extruder = str(limit_to_extruder)
|
|
|
|
# if this stack has the limit_to_extruder "not overriden", use the original limit_to_extruder as the current
|
|
# limit_to_extruder, so the values retrieved will be from the perspective of the original limit_to_extruder
|
|
# stack.
|
|
if limit_to_extruder == "-1":
|
|
if 'original_limit_to_extruder' in context.context:
|
|
limit_to_extruder = context.context['original_limit_to_extruder']
|
|
|
|
if limit_to_extruder is not None and limit_to_extruder != "-1" and limit_to_extruder in global_stack.extruders:
|
|
# set the original limit_to_extruder if this is the first stack that has a non-overriden limit_to_extruder
|
|
if 'original_limit_to_extruder' not in context.context:
|
|
context.context['original_limit_to_extruder'] = limit_to_extruder
|
|
|
|
if super().getProperty(key, "settable_per_extruder", context):
|
|
result = global_stack.extruders[str(limit_to_extruder)].getProperty(key, property_name, context)
|
|
if result is not None:
|
|
context.popContainer()
|
|
return result
|
|
|
|
result = super().getProperty(key, property_name, context)
|
|
context.popContainer()
|
|
return result
|