mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-18 03:35:56 +08:00
Merge pull request #6533 from Ultimaker/CURA-6863_duplicated_material_oddness
CURA-6863 duplicated material oddness
This commit is contained in:
commit
d105150f53
@ -141,6 +141,21 @@ class MaterialManagementModel(QObject):
|
|||||||
new_container.getMetaData().update(new_metadata)
|
new_container.getMetaData().update(new_metadata)
|
||||||
new_containers.append(new_container)
|
new_containers.append(new_container)
|
||||||
|
|
||||||
|
# CURA-6863: Nodes in ContainerTree will be updated upon ContainerAdded signals, one at a time. It will use the
|
||||||
|
# best fit material container at the time it sees one. For example, if you duplicate and get generic_pva #2,
|
||||||
|
# if the node update function sees the containers in the following order:
|
||||||
|
#
|
||||||
|
# - generic_pva #2
|
||||||
|
# - generic_pva #2_um3_aa04
|
||||||
|
#
|
||||||
|
# It will first use "generic_pva #2" because that's the best fit it has ever seen, and later "generic_pva #2_um3_aa04"
|
||||||
|
# once it sees that. Because things run in the Qt event loop, they don't happen at the same time. This means if
|
||||||
|
# between those two events, the ContainerTree will have nodes that contain invalid data.
|
||||||
|
#
|
||||||
|
# This sort fixes the problem by emitting the most specific containers first.
|
||||||
|
new_containers = sorted(new_containers, key = lambda x: x.getId(), reverse = True)
|
||||||
|
|
||||||
|
# Optimization. Serving the same purpose as the postponeSignals() in removeMaterial()
|
||||||
# postpone the signals emitted when duplicating materials. This is easier on the event loop; changes the
|
# postpone the signals emitted when duplicating materials. This is easier on the event loop; changes the
|
||||||
# behavior to be like a transaction. Prevents concurrency issues.
|
# behavior to be like a transaction. Prevents concurrency issues.
|
||||||
with postponeSignals(container_registry.containerAdded, compress=CompressTechnique.CompressPerParameterValue):
|
with postponeSignals(container_registry.containerAdded, compress=CompressTechnique.CompressPerParameterValue):
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
from UM.Settings.Interfaces import ContainerInterface
|
from UM.Settings.Interfaces import ContainerInterface
|
||||||
from UM.Signal import Signal
|
from UM.Signal import Signal
|
||||||
|
|
||||||
|
from cura.Settings.cura_empty_instance_containers import empty_variant_container
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
from cura.Machines.MaterialNode import MaterialNode
|
from cura.Machines.MaterialNode import MaterialNode
|
||||||
|
|
||||||
import UM.FlameProfiler
|
import UM.FlameProfiler
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from cura.Machines.MachineNode import MachineNode
|
from cura.Machines.MachineNode import MachineNode
|
||||||
@ -119,18 +122,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 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:
|
if material_definition != "fdmprinter" and material_definition != self.machine.container_id:
|
||||||
return
|
return
|
||||||
material_variant = container.getMetaDataEntry("variant_name", "empty")
|
material_variant = container.getMetaDataEntry("variant_name", empty_variant_container.getName())
|
||||||
if material_variant != "empty" and material_variant != self.variant_name:
|
if material_variant != self.variant_name:
|
||||||
return
|
return
|
||||||
else: # We already have this base profile. Replace the base profile if the new one is more specific.
|
else: # We already have this base profile. Replace the base profile if the new one is more specific.
|
||||||
new_definition = container.getMetaDataEntry("definition")
|
new_definition = container.getMetaDataEntry("definition")
|
||||||
if new_definition == "fdmprinter":
|
if new_definition == "fdmprinter":
|
||||||
return # Just as unspecific or worse.
|
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.
|
return # Doesn't match this set-up.
|
||||||
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
|
original_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = self.materials[base_file].container_id)[0]
|
||||||
original_variant = original_metadata.get("variant_name", "empty")
|
if "variant_name" in original_metadata or material_variant is None:
|
||||||
if original_variant != "empty" or container.getMetaDataEntry("variant_name", "empty") == "empty":
|
|
||||||
return # Original was already specific or just as unspecific as the new one.
|
return # Original was already specific or just as unspecific as the new one.
|
||||||
|
|
||||||
if "empty_material" in self.materials:
|
if "empty_material" in self.materials:
|
||||||
|
@ -25,7 +25,8 @@ class ExtruderConfigurationModel(QObject):
|
|||||||
return self._position
|
return self._position
|
||||||
|
|
||||||
def setMaterial(self, material: Optional[MaterialOutputModel]) -> None:
|
def setMaterial(self, material: Optional[MaterialOutputModel]) -> None:
|
||||||
if self._material != material:
|
if material is None or self._material == material:
|
||||||
|
return
|
||||||
self._material = material
|
self._material = material
|
||||||
self.extruderConfigurationChanged.emit()
|
self.extruderConfigurationChanged.emit()
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ Item
|
|||||||
if (base.toActivateNewMaterial)
|
if (base.toActivateNewMaterial)
|
||||||
{
|
{
|
||||||
var position = Cura.ExtruderManager.activeExtruderIndex
|
var position = Cura.ExtruderManager.activeExtruderIndex
|
||||||
Cura.MachineManager.setMaterial(position, base.currentItem.container_node)
|
Cura.MachineManager.setMaterialById(position, base.newRootMaterialIdToSwitchTo)
|
||||||
}
|
}
|
||||||
base.newRootMaterialIdToSwitchTo = ""
|
base.newRootMaterialIdToSwitchTo = ""
|
||||||
base.toActivateNewMaterial = false
|
base.toActivateNewMaterial = false
|
||||||
|
@ -21,6 +21,7 @@ Item
|
|||||||
property var colorsModel: materialType != null ? materialType.colors: null
|
property var colorsModel: materialType != null ? materialType.colors: null
|
||||||
height: childrenRect.height
|
height: childrenRect.height
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
anchors.left: parent.left
|
||||||
Rectangle
|
Rectangle
|
||||||
{
|
{
|
||||||
id: material_type_header_background
|
id: material_type_header_background
|
||||||
|
Loading…
x
Reference in New Issue
Block a user