|
@@ -1,7 +1,7 @@
|
|
|
# Copyright (c) 2018 Ultimaker B.V.
|
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
|
|
|
-from typing import TYPE_CHECKING, Optional, cast
|
|
|
+from typing import TYPE_CHECKING, Optional, cast, Dict, List
|
|
|
|
|
|
from PyQt5.QtCore import QObject, QTimer, pyqtSignal, pyqtSlot
|
|
|
|
|
@@ -20,6 +20,8 @@ if TYPE_CHECKING:
|
|
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
|
|
from cura.Settings.GlobalStack import GlobalStack
|
|
|
from .QualityChangesGroup import QualityChangesGroup
|
|
|
+ from cura.CuraApplication import CuraApplication
|
|
|
+ from UM.Settings.ContainerRegistry import ContainerRegistry
|
|
|
|
|
|
|
|
|
#
|
|
@@ -36,17 +38,20 @@ class QualityManager(QObject):
|
|
|
|
|
|
qualitiesUpdated = pyqtSignal()
|
|
|
|
|
|
- def __init__(self, container_registry, parent = None):
|
|
|
+ def __init__(self, container_registry: "ContainerRegistry", parent = None) -> None:
|
|
|
super().__init__(parent)
|
|
|
- self._application = Application.getInstance()
|
|
|
+ self._application = Application.getInstance() # type: CuraApplication
|
|
|
self._material_manager = self._application.getMaterialManager()
|
|
|
self._container_registry = container_registry
|
|
|
|
|
|
self._empty_quality_container = self._application.empty_quality_container
|
|
|
self._empty_quality_changes_container = self._application.empty_quality_changes_container
|
|
|
|
|
|
- self._machine_nozzle_buildplate_material_quality_type_to_quality_dict = {} # for quality lookup
|
|
|
- self._machine_quality_type_to_quality_changes_dict = {} # for quality_changes lookup
|
|
|
+ # For quality lookup
|
|
|
+ self._machine_nozzle_buildplate_material_quality_type_to_quality_dict = {} # type: Dict[str, QualityNode]
|
|
|
+
|
|
|
+ # For quality_changes lookup
|
|
|
+ self._machine_quality_type_to_quality_changes_dict = {} # type: Dict[str, QualityNode]
|
|
|
|
|
|
self._default_machine_definition_id = "fdmprinter"
|
|
|
|
|
@@ -62,7 +67,7 @@ class QualityManager(QObject):
|
|
|
self._update_timer.setSingleShot(True)
|
|
|
self._update_timer.timeout.connect(self._updateMaps)
|
|
|
|
|
|
- def initialize(self):
|
|
|
+ def initialize(self) -> None:
|
|
|
# Initialize the lookup tree for quality profiles with following structure:
|
|
|
# <machine> -> <nozzle> -> <buildplate> -> <material>
|
|
|
# <machine> -> <material>
|
|
@@ -133,13 +138,13 @@ class QualityManager(QObject):
|
|
|
Logger.log("d", "Lookup tables updated.")
|
|
|
self.qualitiesUpdated.emit()
|
|
|
|
|
|
- def _updateMaps(self):
|
|
|
+ def _updateMaps(self) -> None:
|
|
|
self.initialize()
|
|
|
|
|
|
- def _onContainerMetadataChanged(self, container):
|
|
|
+ def _onContainerMetadataChanged(self, container: InstanceContainer) -> None:
|
|
|
self._onContainerChanged(container)
|
|
|
|
|
|
- def _onContainerChanged(self, container):
|
|
|
+ def _onContainerChanged(self, container: InstanceContainer) -> None:
|
|
|
container_type = container.getMetaDataEntry("type")
|
|
|
if container_type not in ("quality", "quality_changes"):
|
|
|
return
|
|
@@ -148,7 +153,7 @@ class QualityManager(QObject):
|
|
|
self._update_timer.start()
|
|
|
|
|
|
# Updates the given quality groups' availabilities according to which extruders are being used/ enabled.
|
|
|
- def _updateQualityGroupsAvailability(self, machine: "GlobalStack", quality_group_list):
|
|
|
+ def _updateQualityGroupsAvailability(self, machine: "GlobalStack", quality_group_list) -> None:
|
|
|
used_extruders = set()
|
|
|
for i in range(machine.getProperty("machine_extruder_count", "value")):
|
|
|
if str(i) in machine.extruders and machine.extruders[str(i)].isEnabled:
|
|
@@ -196,12 +201,9 @@ class QualityManager(QObject):
|
|
|
# Whether a QualityGroup is available can be unknown via the field QualityGroup.is_available.
|
|
|
# For more details, see QualityGroup.
|
|
|
#
|
|
|
- def getQualityGroups(self, machine: "GlobalStack") -> dict:
|
|
|
+ def getQualityGroups(self, machine: "GlobalStack") -> Dict[str, QualityGroup]:
|
|
|
machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
|
|
|
|
|
|
- # This determines if we should only get the global qualities for the global stack and skip the global qualities for the extruder stacks
|
|
|
- has_machine_specific_qualities = machine.getHasMachineQuality()
|
|
|
-
|
|
|
# To find the quality container for the GlobalStack, check in the following fall-back manner:
|
|
|
# (1) the machine-specific node
|
|
|
# (2) the generic node
|
|
@@ -214,7 +216,12 @@ class QualityManager(QObject):
|
|
|
has_extruder_specific_qualities = True
|
|
|
|
|
|
default_machine_node = self._machine_nozzle_buildplate_material_quality_type_to_quality_dict.get(self._default_machine_definition_id)
|
|
|
- nodes_to_check = [machine_node, default_machine_node]
|
|
|
+
|
|
|
+ nodes_to_check = [] # type: List[QualityNode]
|
|
|
+ if machine_node is not None:
|
|
|
+ nodes_to_check.append(machine_node)
|
|
|
+ if default_machine_node is not None:
|
|
|
+ nodes_to_check.append(default_machine_node)
|
|
|
|
|
|
# Iterate over all quality_types in the machine node
|
|
|
quality_group_dict = {}
|
|
@@ -273,13 +280,16 @@ class QualityManager(QObject):
|
|
|
# Each points above can be represented as a node in the lookup tree, so here we simply put those nodes into
|
|
|
# the list with priorities as the order. Later, we just need to loop over each node in this list and fetch
|
|
|
# qualities from there.
|
|
|
- node_info_list_0 = [nozzle_name, buildplate_name, root_material_id]
|
|
|
+ node_info_list_0 = [nozzle_name, buildplate_name, root_material_id] # type: List[Optional[str]]
|
|
|
nodes_to_check = []
|
|
|
|
|
|
# This function tries to recursively find the deepest (the most specific) branch and add those nodes to
|
|
|
# the search list in the order described above. So, by iterating over that search node list, we first look
|
|
|
# in the more specific branches and then the less specific (generic) ones.
|
|
|
- def addNodesToCheck(node, nodes_to_check_list, node_info_list, node_info_idx):
|
|
|
+ def addNodesToCheck(node: Optional[QualityNode], nodes_to_check_list: List[QualityNode], node_info_list, node_info_idx: int) -> None:
|
|
|
+ if node is None:
|
|
|
+ return
|
|
|
+
|
|
|
if node_info_idx < len(node_info_list):
|
|
|
node_name = node_info_list[node_info_idx]
|
|
|
if node_name is not None:
|
|
@@ -300,9 +310,10 @@ class QualityManager(QObject):
|
|
|
|
|
|
# The last fall back will be the global qualities (either from the machine-specific node or the generic
|
|
|
# node), but we only use one. For details see the overview comments above.
|
|
|
- if machine_node.quality_type_map:
|
|
|
+
|
|
|
+ if machine_node is not None and machine_node.quality_type_map:
|
|
|
nodes_to_check += [machine_node]
|
|
|
- else:
|
|
|
+ elif default_machine_node is not None:
|
|
|
nodes_to_check += [default_machine_node]
|
|
|
|
|
|
for node_idx, node in enumerate(nodes_to_check):
|
|
@@ -334,7 +345,7 @@ class QualityManager(QObject):
|
|
|
|
|
|
return quality_group_dict
|
|
|
|
|
|
- def getQualityGroupsForMachineDefinition(self, machine: "GlobalStack") -> dict:
|
|
|
+ def getQualityGroupsForMachineDefinition(self, machine: "GlobalStack") -> Dict[str, QualityGroup]:
|
|
|
machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
|
|
|
|
|
|
# To find the quality container for the GlobalStack, check in the following fall-back manner:
|
|
@@ -372,7 +383,7 @@ class QualityManager(QObject):
|
|
|
# Remove the given quality changes group.
|
|
|
#
|
|
|
@pyqtSlot(QObject)
|
|
|
- def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup"):
|
|
|
+ def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup") -> None:
|
|
|
Logger.log("i", "Removing quality changes group [%s]", quality_changes_group.name)
|
|
|
removed_quality_changes_ids = set()
|
|
|
for node in quality_changes_group.getAllNodes():
|
|
@@ -415,7 +426,7 @@ class QualityManager(QObject):
|
|
|
# Duplicates the given quality.
|
|
|
#
|
|
|
@pyqtSlot(str, "QVariantMap")
|
|
|
- def duplicateQualityChanges(self, quality_changes_name, quality_model_item):
|
|
|
+ def duplicateQualityChanges(self, quality_changes_name: str, quality_model_item) -> None:
|
|
|
global_stack = self._application.getGlobalContainerStack()
|
|
|
if not global_stack:
|
|
|
Logger.log("i", "No active global stack, cannot duplicate quality changes.")
|
|
@@ -443,7 +454,7 @@ class QualityManager(QObject):
|
|
|
# the user containers in each stack. These then replace the quality_changes containers in the
|
|
|
# stack and clear the user settings.
|
|
|
@pyqtSlot(str)
|
|
|
- def createQualityChanges(self, base_name):
|
|
|
+ def createQualityChanges(self, base_name: str) -> None:
|
|
|
machine_manager = Application.getInstance().getMachineManager()
|
|
|
|
|
|
global_stack = machine_manager.activeMachine
|