diff --git a/cura/Machines/MaterialNode.py b/cura/Machines/MaterialNode.py index 0b43b311bf..a5a3bd8e72 100644 --- a/cura/Machines/MaterialNode.py +++ b/cura/Machines/MaterialNode.py @@ -3,6 +3,7 @@ from typing import Any, TYPE_CHECKING +from UM.Logger import Logger from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.Interfaces import ContainerInterface from UM.Signal import Signal @@ -32,6 +33,28 @@ class MaterialNode(ContainerNode): container_registry.containerRemoved.connect(self._onRemoved) container_registry.containerMetaDataChanged.connect(self._onMetadataChanged) + ## Finds the preferred quality for this printer with this material and this + # variant loaded. + # + # If the preferred quality is not available, an arbitrary quality is + # returned. If there is a configuration mistake (like a typo in the + # preferred quality) this returns a random available quality. If there are + # no available qualities, this will return the empty quality node. + # \return The node for the preferred quality, or any arbitrary quality if + # there is no match. + def preferredQuality(self) -> QualityNode: + for quality_id, quality_node in self.qualities.items(): + if self.variant.machine.preferred_quality_type == quality_node.quality_type: + return quality_node + fallback = next(iter(self.qualities.values())) # Should only happen with empty quality node. + Logger.log("w", "Could not find preferred quality type {preferred_quality_type} for material {material_id} and variant {variant_id}, falling back to {fallback}.".format( + preferred_quality_type = self.variant.machine.preferred_quality_type, + material_id = self.container_id, + variant_id = self.variant.container_id, + fallback = fallback.container_id + )) + return fallback + def _loadAll(self) -> None: container_registry = ContainerRegistry.getInstance() # Find all quality profiles that fit on this material. diff --git a/cura/Machines/QualityNode.py b/cura/Machines/QualityNode.py index 01b73a2091..451c8babfb 100644 --- a/cura/Machines/QualityNode.py +++ b/cura/Machines/QualityNode.py @@ -20,6 +20,10 @@ class QualityNode(ContainerNode): super().__init__(container_id) self.parent = parent self.intents = {} # type: Dict[str, IntentNode] + + my_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = container_id)[0] + self.quality_type = my_metadata["quality_type"] + self._loadAll() def _loadAll(self) -> None: diff --git a/cura/Machines/VariantNode.py b/cura/Machines/VariantNode.py index 096c09a81e..f5a1e3006e 100644 --- a/cura/Machines/VariantNode.py +++ b/cura/Machines/VariantNode.py @@ -71,12 +71,14 @@ class VariantNode(ContainerNode): ## Finds the preferred material for this printer with this nozzle in one of # the extruders. # - # If there is no material here (because the printer has no materials or - # because there are no matching material profiles), None is returned. + # If the preferred material is not available, an arbitrary material is + # returned. If there is a configuration mistake (like a typo in the + # preferred material) this returns a random available material. If there + # are no available materials, this will return the empty material node. # \param approximate_diameter The desired approximate diameter of the # material. - # \return The node for the preferred material, or None if there is no - # match. + # \return The node for the preferred material, or any arbitrary material + # if there is no match. def preferredMaterial(self, approximate_diameter) -> MaterialNode: for base_material, material_node in self.materials.items(): if self.machine.preferred_material in base_material and approximate_diameter == int(material_node.getMetaDataEntry("approximate_diameter")):