Merge pull request #19539 from Ultimaker/CURA-11501_switching_printers_loads_3rd_party_materials

CURA-11501 Fix excluded materials being sometimes visible
This commit is contained in:
HellAholic 2024-08-16 14:19:51 +02:00 committed by GitHub
commit 6030d9f1a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View file

@ -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
@ -168,13 +169,18 @@ class MachineNode(ContainerNode):
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values())))
def isExcludedMaterial(self, material: MaterialNode) -> 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["id"]:
if exclude_material in material_base_file:
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)
@UM.FlameProfiler.profile
def _loadAll(self) -> None:
"""(Re)loads all variants under this printer."""

View file

@ -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 not self.machine.isExcludedMaterial(material)]
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 @@ class VariantNode(ContainerNode):
material_definition = container.getMetaDataEntry("definition")
base_file = container.getMetaDataEntry("base_file")
if base_file in self.machine.exclude_materials:
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:

View file

@ -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
@ -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