mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 23:23:57 -06:00
Merge branch 'CURA-10599_fix_exclude_materials' of github.com:Ultimaker/Cura into 5.4
This commit is contained in:
commit
5d0d1d485b
3 changed files with 12 additions and 2 deletions
|
@ -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.
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue