Split methods to prevent API-break.

done as part of CURA-11501
This commit is contained in:
Remco Burema 2024-08-15 15:54:05 +02:00
parent b8bba655ca
commit 8805c6a1b5
3 changed files with 9 additions and 4 deletions

View File

@ -14,6 +14,7 @@ from cura.Machines.QualityChangesGroup import QualityChangesGroup # To construc
from cura.Machines.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together. from cura.Machines.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together.
from cura.Machines.QualityNode import QualityNode from cura.Machines.QualityNode import QualityNode
from cura.Machines.VariantNode import VariantNode from cura.Machines.VariantNode import VariantNode
from cura.Machines.MaterialNode import MaterialNode
import UM.FlameProfiler import UM.FlameProfiler
@ -167,13 +168,17 @@ class MachineNode(ContainerNode):
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values()))) return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values())))
def isExcludedMaterial(self, material_base_file: str) -> bool: def isExcludedMaterialBaseFile(self, material_base_file: str) -> bool:
"""Returns whether the material should be excluded from the list of materials.""" """Returns whether the material should be excluded from the list of materials."""
for exclude_material in self.exclude_materials: for exclude_material in self.exclude_materials:
if exclude_material in material_base_file: if exclude_material in material_base_file:
return True return True
return False return False
def isExcludedMaterial(self, material: MaterialNode) -> bool:
"""Returns whether the material should be excluded from the list of materials."""
return self.isExcludedMaterialBaseFile(material.base_file)
@UM.FlameProfiler.profile @UM.FlameProfiler.profile
def _loadAll(self) -> None: def _loadAll(self) -> None:
"""(Re)loads all variants under this printer.""" """(Re)loads all variants under this printer."""

View File

@ -60,7 +60,7 @@ class VariantNode(ContainerNode):
materials = list(materials_per_base_file.values()) materials = list(materials_per_base_file.values())
# Filter materials based on the exclude_materials property. # Filter materials based on the exclude_materials property.
filtered_materials = [material for material in materials if not self.machine.isExcludedMaterial(material["id"])] filtered_materials = [material for material in materials if not self.machine.isExcludedMaterialBaseFile(material["id"])]
for material in filtered_materials: for material in filtered_materials:
base_file = material["base_file"] base_file = material["base_file"]
@ -127,7 +127,7 @@ class VariantNode(ContainerNode):
material_definition = container.getMetaDataEntry("definition") material_definition = container.getMetaDataEntry("definition")
base_file = container.getMetaDataEntry("base_file") base_file = container.getMetaDataEntry("base_file")
if self.machine.isExcludedMaterial(base_file): if self.machine.isExcludedMaterialBaseFile(base_file):
return # Material is forbidden for this printer. return # Material is forbidden for this printer.
if base_file not in self.materials: # Completely new base file. Always better than not having a file as long as it matches our set-up. if base_file not in self.materials: # Completely new base file. Always better than not having a file as long as it matches our set-up.
if material_definition != "fdmprinter" and material_definition != self.machine.container_id: if material_definition != "fdmprinter" and material_definition != self.machine.container_id:

View File

@ -96,7 +96,7 @@ def test_variantNodeInit(container_registry, machine_node):
def test_variantNodeInit_excludedMaterial(container_registry, machine_node): def test_variantNodeInit_excludedMaterial(container_registry, machine_node):
machine_node.exclude_materials = ["material_1"] machine_node.exclude_materials = ["material_1"]
machine_node.isExcludedMaterial = MagicMock(side_effect=lambda material: material == "material_1") machine_node.isExcludedMaterial = MagicMock(side_effect=lambda material: material["id"] == "material_1")
node = createVariantNode("variant_1", machine_node, container_registry) node = createVariantNode("variant_1", machine_node, container_registry)
assert "material_1" not in node.materials assert "material_1" not in node.materials