diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index 88736826fd..aa4db8bb8f 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -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.QualityNode import QualityNode from cura.Machines.VariantNode import VariantNode +from cura.Machines.MaterialNode import MaterialNode import UM.FlameProfiler @@ -167,13 +168,20 @@ class MachineNode(ContainerNode): return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values()))) + def isExcludedMaterial(self, material: MaterialNode) -> bool: + """Returns whether the material should be excluded from the list of materials.""" + for exclude_material in self.exclude_materials: + if exclude_material in material["id"]: + return True + return False + @UM.FlameProfiler.profile def _loadAll(self) -> None: """(Re)loads all variants under this printer.""" container_registry = ContainerRegistry.getInstance() if not self.has_variants: - self.variants["empty"] = VariantNode("empty_variant", machine = self) + self.variants["empty"] = VariantNode("empty_variant", machine=self) self.variants["empty"].materialsChanged.connect(self.materialsChanged) else: # Find all the variants for this definition ID. diff --git a/cura/Machines/VariantNode.py b/cura/Machines/VariantNode.py index 39664946a3..6c3e9359d0 100644 --- a/cura/Machines/VariantNode.py +++ b/cura/Machines/VariantNode.py @@ -60,7 +60,7 @@ class VariantNode(ContainerNode): materials = list(materials_per_base_file.values()) # Filter materials based on the exclude_materials property. - filtered_materials = [material for material in materials if material["id"] not in self.machine.exclude_materials] + filtered_materials = [material for material in materials if not self.machine.isExcludedMaterial(material)] for material in filtered_materials: base_file = material["base_file"] diff --git a/resources/definitions/ultimaker2_plus_connect.def.json b/resources/definitions/ultimaker2_plus_connect.def.json index 2e7a98fdd6..dc55d8febf 100644 --- a/resources/definitions/ultimaker2_plus_connect.def.json +++ b/resources/definitions/ultimaker2_plus_connect.def.json @@ -20,6 +20,9 @@ "ultimaker_tough_pla_green", "ultimaker_tough_pla_red", "ultimaker_tough_pla_white", + "ultimaker_tough_pla_blue", + "ultimaker_tough_pla_gray", + "ultimaker_tough_pla_yellow", "generic_cffcpe", "generic_cffpa", "generic_gffcpe", diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index 7f06ad468c..e15d64a444 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -46,6 +46,7 @@ def getInstanceContainerSideEffect(*args, **kwargs): def machine_node(): mocked_machine_node = MagicMock() mocked_machine_node.container_id = "machine_1" + mocked_machine_node.isExcludedMaterial = MagicMock(return_value=False) mocked_machine_node.preferred_material = "preferred_material" return mocked_machine_node @@ -95,6 +96,7 @@ def test_variantNodeInit(container_registry, machine_node): def test_variantNodeInit_excludedMaterial(container_registry, machine_node): machine_node.exclude_materials = ["material_1"] + machine_node.isExcludedMaterial = MagicMock(side_effect=lambda material: material["id"] == "material_1") node = createVariantNode("variant_1", machine_node, container_registry) assert "material_1" not in node.materials