Add a cache for settable_per_extruder property

This commit is contained in:
Jaime van Kessel 2020-08-14 14:51:46 +02:00
parent 51737dccd6
commit 9c904f95ce
No known key found for this signature in database
GPG key ID: 3710727397403C91
2 changed files with 13 additions and 1 deletions

View file

@ -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 = {}
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,16 @@ 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.
if key not in self._settable_per_extruder_cache:
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."""

View file

@ -192,7 +192,7 @@ class GlobalStack(CuraContainerStack):
self._extruders[position] = extruder self._extruders[position] = extruder
self.extrudersChanged.emit() self.extrudersChanged.emit()
Logger.log("i", "Extruder[%s] added to [%s] at position [%s]", extruder.id, self.id, position) Logger.log("i", "Extruder[%s] added to [%s] at position [%s]", extruder.id, self.id, position)
@override(ContainerStack) @override(ContainerStack)
def getProperty(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None) -> Any: def getProperty(self, key: str, property_name: str, context: Optional[PropertyEvaluationContext] = None) -> Any:
"""Overridden from ContainerStack """Overridden from ContainerStack