Fix 1/2 of the duplication material bug.

The material is added multiple times to the variant nodes, and overwriting it with the eventual right one was going wrong.
This does not solve it entirely (because the less specific one still ends up selected _initially_ because it gets added first, and the order can't be guaranteed.
part of CURA-6863
This commit is contained in:
Remco Burema 2019-10-14 01:01:19 +02:00
parent 25db711adc
commit 4277ede64f
2 changed files with 6 additions and 7 deletions

View file

@ -1,6 +1,5 @@
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Optional, TYPE_CHECKING
from UM.Logger import Logger
@ -111,18 +110,18 @@ class VariantNode(ContainerNode):
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:
return
material_variant = container.getMetaDataEntry("variant_name", "empty")
if material_variant != "empty" and material_variant != self.variant_name:
material_variant = container.getMetaDataEntry("variant_name")
if material_variant is not None and material_variant != self.variant_name:
return
else: # We already have this base profile. Replace the base profile if the new one is more specific.
new_definition = container.getMetaDataEntry("definition")
if new_definition == "fdmprinter":
return # Just as unspecific or worse.
if new_definition != self.machine.container_id:
material_variant = container.getMetaDataEntry("variant_name")
if new_definition != self.machine.container_id or material_variant != self.variant_name:
return # Doesn't match this set-up.
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
original_variant = original_metadata.get("variant_name", "empty")
if original_variant != "empty" or container.getMetaDataEntry("variant_name", "empty") == "empty":
if "variant_name" in original_metadata or material_variant is not None:
return # Original was already specific or just as unspecific as the new one.
if "empty_material" in self.materials:

View file

@ -114,7 +114,7 @@ Item
if (base.toActivateNewMaterial)
{
var position = Cura.ExtruderManager.activeExtruderIndex
Cura.MachineManager.setMaterial(position, base.currentItem.container_node)
Cura.MachineManager.setMaterialById(position, base.newRootMaterialIdToSwitchTo)
}
base.newRootMaterialIdToSwitchTo = ""
base.toActivateNewMaterial = false