Add function to find preferred material for configuration of printer/nozzle

This is supposed to replace the material manager's getDefaultMaterial function.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-22 15:34:24 +02:00
parent 7b83e51439
commit 295ad564c0
No known key found for this signature in database
GPG Key ID: 86BEF881AE2CF276

View File

@ -1,11 +1,12 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 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 TYPE_CHECKING from typing import Optional, TYPE_CHECKING
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.Interfaces import ContainerInterface from UM.Settings.Interfaces import ContainerInterface
from UM.Signal import Signal from UM.Signal import Signal
from UM.Util import parseBool
from cura.Machines.ContainerNode import ContainerNode from cura.Machines.ContainerNode import ContainerNode
from cura.Machines.MaterialNode import MaterialNode from cura.Machines.MaterialNode import MaterialNode
@ -60,6 +61,21 @@ class VariantNode(ContainerNode):
self.materials[base_file] = MaterialNode(material["id"], variant = self) self.materials[base_file] = MaterialNode(material["id"], variant = self)
self.materials[base_file].materialChanged.connect(self.materialsChanged) self.materials[base_file].materialChanged.connect(self.materialsChanged)
## 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.
# \param approximate_diameter The desired approximate diameter of the
# material.
# \return The node for the preferred material, or None if there is no
# match.
def preferredMaterial(self, approximate_diameter) -> Optional[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")):
return material_node
return None
## 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.
def _materialAdded(self, container: ContainerInterface): def _materialAdded(self, container: ContainerInterface):