From 1e5fa8523f27178c47318741d2c75a4cbad726f9 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 15 Aug 2024 11:13:15 +0200 Subject: [PATCH 1/6] Use proper method to check for excluded materials CURA-11501 --- cura/Machines/MachineNode.py | 5 ++--- cura/Machines/VariantNode.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index aa4db8bb8f9..1f6ccb6a245 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -14,7 +14,6 @@ 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 @@ -168,10 +167,10 @@ def preferredGlobalQuality(self) -> "QualityNode": return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values()))) - def isExcludedMaterial(self, material: MaterialNode) -> bool: + def isExcludedMaterial(self, material_base_file: str) -> 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"]: + if exclude_material in material_base_file: return True return False diff --git a/cura/Machines/VariantNode.py b/cura/Machines/VariantNode.py index b976841aa75..9806f12cd1c 100644 --- a/cura/Machines/VariantNode.py +++ b/cura/Machines/VariantNode.py @@ -60,7 +60,7 @@ def _loadAll(self) -> None: materials = list(materials_per_base_file.values()) # Filter materials based on the exclude_materials property. - filtered_materials = [material for material in materials if not self.machine.isExcludedMaterial(material)] + filtered_materials = [material for material in materials if not self.machine.isExcludedMaterial(material["id"])] for material in filtered_materials: base_file = material["base_file"] @@ -127,7 +127,7 @@ def _materialAdded(self, container: ContainerInterface) -> None: material_definition = container.getMetaDataEntry("definition") base_file = container.getMetaDataEntry("base_file") - if base_file in self.machine.exclude_materials: + if self.machine.isExcludedMaterial(base_file): 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 material_definition != "fdmprinter" and material_definition != self.machine.container_id: From b8bba655ca37b32e0e598121f7add037bddef954 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 15 Aug 2024 11:54:29 +0200 Subject: [PATCH 2/6] Fix unit test --- tests/Machines/TestVariantNode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index e15d64a4444..f3174599fbe 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -96,7 +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") + machine_node.isExcludedMaterial = MagicMock(side_effect=lambda material: material == "material_1") node = createVariantNode("variant_1", machine_node, container_registry) assert "material_1" not in node.materials From 8805c6a1b5aaa10cbd57ff8704936ea341d3a81e Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 15 Aug 2024 15:54:05 +0200 Subject: [PATCH 3/6] Split methods to prevent API-break. done as part of CURA-11501 --- cura/Machines/MachineNode.py | 7 ++++++- cura/Machines/VariantNode.py | 4 ++-- tests/Machines/TestVariantNode.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index 1f6ccb6a245..f39496ecc8d 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -14,6 +14,7 @@ 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,17 @@ def preferredGlobalQuality(self) -> "QualityNode": 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.""" for exclude_material in self.exclude_materials: if exclude_material in material_base_file: return True 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 def _loadAll(self) -> None: """(Re)loads all variants under this printer.""" diff --git a/cura/Machines/VariantNode.py b/cura/Machines/VariantNode.py index 9806f12cd1c..e037c9259dd 100644 --- a/cura/Machines/VariantNode.py +++ b/cura/Machines/VariantNode.py @@ -60,7 +60,7 @@ def _loadAll(self) -> None: materials = list(materials_per_base_file.values()) # 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: base_file = material["base_file"] @@ -127,7 +127,7 @@ def _materialAdded(self, container: ContainerInterface) -> None: material_definition = container.getMetaDataEntry("definition") 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. 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: diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index f3174599fbe..e15d64a4444 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -96,7 +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 == "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 From 922c8ccbc9c2d7e4caf65678173e60aaface44b9 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 16 Aug 2024 00:39:35 +0200 Subject: [PATCH 4/6] Fix unit test. It's not enough (or even nescesary) to mock the (now wrapper) method, since we use the underlaying method in our code now. done as part of CURA-11501 --- tests/Machines/TestVariantNode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index e15d64a4444..124010a4b3d 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -96,7 +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") + machine_node.isExcludedMaterialBaseFile = MagicMock(side_effect=lambda material: material == "material_1") node = createVariantNode("variant_1", machine_node, container_registry) assert "material_1" not in node.materials From 268fd354b2e0dcf5368778b6c9e8a9b77712a969 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 16 Aug 2024 00:44:37 +0200 Subject: [PATCH 5/6] Mark isExcludedMaterial as deprecated. done as part of CURA-11501 --- cura/Machines/MachineNode.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index f39496ecc8d..67b8559b2e0 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -1,8 +1,9 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2024 UltiMaker # Cura is released under the terms of the LGPLv3 or higher. from typing import Dict, List +from UM.Decorators import deprecated from UM.Logger import Logger from UM.Signal import Signal from UM.Util import parseBool @@ -175,6 +176,7 @@ def isExcludedMaterialBaseFile(self, material_base_file: str) -> bool: return True return False + @deprecated("Use isExcludedMaterialBaseFile instead.", since = "5.9.0") def isExcludedMaterial(self, material: MaterialNode) -> bool: """Returns whether the material should be excluded from the list of materials.""" return self.isExcludedMaterialBaseFile(material.base_file) From 785287ef9b9c9297914ecc31936c8d52fc16a8d4 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Fri, 16 Aug 2024 08:32:24 +0200 Subject: [PATCH 6/6] Fix unit test CURA-11501 --- tests/Machines/TestVariantNode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index 124010a4b3d..c84aaae36dc 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -46,7 +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.isExcludedMaterialBaseFile = MagicMock(return_value=False) mocked_machine_node.preferred_material = "preferred_material" return mocked_machine_node