mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-22 12:39:22 +08:00
Merge pull request #8195 from Ultimaker/GetPropertySpeedImprovements
Get property speed improvements
This commit is contained in:
commit
b685da5a24
@ -1,7 +1,7 @@
|
|||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Any, cast, List, Optional
|
from typing import Any, cast, List, Optional, Dict
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject
|
||||||
|
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
@ -60,6 +60,8 @@ class CuraContainerStack(ContainerStack):
|
|||||||
import cura.CuraApplication #Here to prevent circular imports.
|
import cura.CuraApplication #Here to prevent circular imports.
|
||||||
self.setMetaDataEntry("setting_version", cura.CuraApplication.CuraApplication.SettingVersion)
|
self.setMetaDataEntry("setting_version", cura.CuraApplication.CuraApplication.SettingVersion)
|
||||||
|
|
||||||
|
self._settable_per_extruder_cache = {} # type: Dict[str, Any]
|
||||||
|
|
||||||
self.setDirty(False)
|
self.setDirty(False)
|
||||||
|
|
||||||
# This is emitted whenever the containersChanged signal from the ContainerStack base class is emitted.
|
# This is emitted whenever the containersChanged signal from the ContainerStack base class is emitted.
|
||||||
@ -387,6 +389,18 @@ class CuraContainerStack(ContainerStack):
|
|||||||
value = int(Application.getInstance().getMachineManager().defaultExtruderPosition)
|
value = int(Application.getInstance().getMachineManager().defaultExtruderPosition)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def getProperty(self, key: str, property_name: str, context = None) -> Any:
|
||||||
|
if property_name == "settable_per_extruder":
|
||||||
|
# Setable per extruder isn't a value that can ever change. So once we requested it once, we can just keep
|
||||||
|
# that in memory.
|
||||||
|
try:
|
||||||
|
return self._settable_per_extruder_cache[key]
|
||||||
|
except KeyError:
|
||||||
|
self._settable_per_extruder_cache[key] = super().getProperty(key, property_name, context)
|
||||||
|
return self._settable_per_extruder_cache[key]
|
||||||
|
|
||||||
|
return super().getProperty(key, property_name, context)
|
||||||
|
|
||||||
|
|
||||||
class _ContainerIndexes:
|
class _ContainerIndexes:
|
||||||
"""Private helper class to keep track of container positions and their types."""
|
"""Private helper class to keep track of container positions and their types."""
|
||||||
|
@ -131,12 +131,12 @@ class ExtruderStack(CuraContainerStack):
|
|||||||
if not self._next_stack:
|
if not self._next_stack:
|
||||||
raise Exceptions.NoGlobalStackError("Extruder {id} is missing the next stack!".format(id = self.id))
|
raise Exceptions.NoGlobalStackError("Extruder {id} is missing the next stack!".format(id = self.id))
|
||||||
|
|
||||||
if context is None:
|
if context:
|
||||||
context = PropertyEvaluationContext()
|
|
||||||
context.pushContainer(self)
|
context.pushContainer(self)
|
||||||
|
|
||||||
if not super().getProperty(key, "settable_per_extruder", context):
|
if not super().getProperty(key, "settable_per_extruder", context):
|
||||||
result = self.getNextStack().getProperty(key, property_name, context)
|
result = self.getNextStack().getProperty(key, property_name, context)
|
||||||
|
if context:
|
||||||
context.popContainer()
|
context.popContainer()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -150,12 +150,14 @@ class ExtruderStack(CuraContainerStack):
|
|||||||
try:
|
try:
|
||||||
result = self.getNextStack().extruderList[int(limit_to_extruder)].getProperty(key, property_name, context)
|
result = self.getNextStack().extruderList[int(limit_to_extruder)].getProperty(key, property_name, context)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
|
if context:
|
||||||
context.popContainer()
|
context.popContainer()
|
||||||
return result
|
return result
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
result = super().getProperty(key, property_name, context)
|
result = super().getProperty(key, property_name, context)
|
||||||
|
if context:
|
||||||
context.popContainer()
|
context.popContainer()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -211,8 +211,7 @@ class GlobalStack(CuraContainerStack):
|
|||||||
if not self.definition.findDefinitions(key = key):
|
if not self.definition.findDefinitions(key = key):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if context is None:
|
if context:
|
||||||
context = PropertyEvaluationContext()
|
|
||||||
context.pushContainer(self)
|
context.pushContainer(self)
|
||||||
|
|
||||||
# Handle the "resolve" property.
|
# Handle the "resolve" property.
|
||||||
@ -238,12 +237,14 @@ class GlobalStack(CuraContainerStack):
|
|||||||
if super().getProperty(key, "settable_per_extruder", context):
|
if super().getProperty(key, "settable_per_extruder", context):
|
||||||
result = self._extruders[str(limit_to_extruder)].getProperty(key, property_name, context)
|
result = self._extruders[str(limit_to_extruder)].getProperty(key, property_name, context)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
|
if context:
|
||||||
context.popContainer()
|
context.popContainer()
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
Logger.log("e", "Setting {setting} has limit_to_extruder but is not settable per extruder!", setting = key)
|
Logger.log("e", "Setting {setting} has limit_to_extruder but is not settable per extruder!", setting = key)
|
||||||
|
|
||||||
result = super().getProperty(key, property_name, context)
|
result = super().getProperty(key, property_name, context)
|
||||||
|
if context:
|
||||||
context.popContainer()
|
context.popContainer()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -256,8 +257,6 @@ class GlobalStack(CuraContainerStack):
|
|||||||
|
|
||||||
raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!")
|
raise Exceptions.InvalidOperationError("Global stack cannot have a next stack!")
|
||||||
|
|
||||||
# protected:
|
|
||||||
|
|
||||||
# Determine whether or not we should try to get the "resolve" property instead of the
|
# Determine whether or not we should try to get the "resolve" property instead of the
|
||||||
# requested property.
|
# requested property.
|
||||||
def _shouldResolve(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None) -> bool:
|
def _shouldResolve(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None) -> bool:
|
||||||
@ -265,6 +264,10 @@ class GlobalStack(CuraContainerStack):
|
|||||||
# Do not try to resolve anything but the "value" property
|
# Do not try to resolve anything but the "value" property
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not self.definition.getProperty(key, "resolve"):
|
||||||
|
# If there isn't a resolve set for this setting, there isn't anything to do here.
|
||||||
|
return False
|
||||||
|
|
||||||
current_thread = threading.current_thread()
|
current_thread = threading.current_thread()
|
||||||
if key in self._resolving_settings[current_thread.name]:
|
if key in self._resolving_settings[current_thread.name]:
|
||||||
# To prevent infinite recursion, if getProperty is called with the same key as
|
# To prevent infinite recursion, if getProperty is called with the same key as
|
||||||
@ -273,10 +276,8 @@ class GlobalStack(CuraContainerStack):
|
|||||||
# track all settings that are being resolved.
|
# track all settings that are being resolved.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
setting_state = super().getProperty(key, "state", context = context)
|
if self.hasUserValue(key):
|
||||||
if setting_state is not None and setting_state != InstanceState.Default:
|
# When the user has explicitly set a value, we should ignore any resolve and just return that value.
|
||||||
# When the user has explicitly set a value, we should ignore any resolve and
|
|
||||||
# just return that value.
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user