Return empty node if preferred node couldn't be found

Or any node, really. There must now always be a subnode.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-22 16:52:38 +02:00
parent d06ce211ff
commit 9dca6c0127
No known key found for this signature in database
GPG Key ID: 86BEF881AE2CF276

View File

@ -76,11 +76,11 @@ class VariantNode(ContainerNode):
# material. # material.
# \return The node for the preferred material, or None if there is no # \return The node for the preferred material, or None if there is no
# match. # match.
def preferredMaterial(self, approximate_diameter) -> Optional[MaterialNode]: def preferredMaterial(self, approximate_diameter) -> MaterialNode:
for base_material, material_node in self.materials.items(): 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")): if self.machine.preferred_material in base_material and approximate_diameter == int(material_node.getMetaDataEntry("approximate_diameter")):
return material_node return material_node
return None return next(iter(self.materials.values()))
## When a material gets added to the set of profiles, we need to update our ## When a material gets added to the set of profiles, we need to update our
# tree here. # tree here.