mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-03 03:54:01 -06:00
Add signals to signal that a material got changed or removed
The material models need to know this. Contributes to issue CURA-6600.
This commit is contained in:
parent
b7213ad020
commit
6c6dd0efad
4 changed files with 22 additions and 3 deletions
|
@ -6,6 +6,7 @@ from UM.Settings.ContainerRegistry import ContainerRegistry # To listen to cont
|
|||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
import cura.CuraApplication # Imported like this to prevent circular dependencies.
|
||||
from UM.Signal import Signal
|
||||
from cura.Machines.MachineNode import MachineNode
|
||||
|
||||
from typing import Dict, List, TYPE_CHECKING
|
||||
|
@ -30,6 +31,8 @@ class ContainerTree:
|
|||
|
||||
def __init__(self) -> None:
|
||||
self.machines = {} # type: Dict[str, MachineNode] # Mapping from definition ID to machine nodes.
|
||||
self.materialsChanged = Signal() # Emitted when any of the material nodes in the tree got changed.
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
container_registry.containerAdded.connect(self._machineAdded)
|
||||
self._loadAll()
|
||||
|
@ -58,6 +61,7 @@ class ContainerTree:
|
|||
definition_id = stack.definition.getId()
|
||||
if definition_id not in self.machines:
|
||||
self.machines[definition_id] = MachineNode(definition_id)
|
||||
self.machines[definition_id].materialsChanged.connect(self.materialsChanged)
|
||||
|
||||
Logger.log("d", "Building the container tree took %s seconds", time.time() - start_time)
|
||||
|
||||
|
@ -70,3 +74,4 @@ class ContainerTree:
|
|||
return # Already have this definition ID.
|
||||
|
||||
self.machines[definition_id] = MachineNode(definition_id)
|
||||
self.machines[definition_id].materialsChanged.connect(self.materialsChanged)
|
|
@ -4,6 +4,7 @@
|
|||
from typing import Dict, List
|
||||
|
||||
from UM.Logger import Logger
|
||||
from UM.Signal import Signal
|
||||
from UM.Util import parseBool
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
|
||||
from cura.Machines.ContainerNode import ContainerNode
|
||||
|
@ -19,6 +20,8 @@ class MachineNode(ContainerNode):
|
|||
super().__init__(container_id)
|
||||
self.variants = {} # type: Dict[str, VariantNode] # Mapping variant names to their nodes.
|
||||
self.global_qualities = {} # type: Dict[str, QualityNode] # Mapping quality types to the global quality for those types.
|
||||
self.materialsChanged = Signal() # Emitted when one of the materials underneath this machine has been changed.
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
try:
|
||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||
|
@ -93,6 +96,7 @@ class MachineNode(ContainerNode):
|
|||
variant_name = variant["name"]
|
||||
if variant_name not in self.variants:
|
||||
self.variants[variant_name] = VariantNode(variant["id"], machine = self)
|
||||
self.variants[variant_name].materialsChanged.connect(self.materialsChanged)
|
||||
|
||||
# Find the global qualities for this printer.
|
||||
global_qualities = container_registry.findInstanceContainersMetadata(type = "quality", definition = self.container_id, global_quality = True) # First try specific to this printer.
|
||||
|
|
|
@ -5,6 +5,7 @@ from typing import Any, TYPE_CHECKING
|
|||
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
from UM.Signal import Signal
|
||||
from cura.Machines.ContainerNode import ContainerNode
|
||||
from cura.Machines.QualityNode import QualityNode
|
||||
|
||||
|
@ -20,6 +21,8 @@ class MaterialNode(ContainerNode):
|
|||
super().__init__(container_id)
|
||||
self.variant = variant
|
||||
self.qualities = {} # type: Dict[str, QualityNode] # Mapping container IDs to quality profiles.
|
||||
self.materialChanged = Signal() # Triggered when the material is removed or its metadata is updated.
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
my_metadata = container_registry.findContainersMetadata(id = container_id)[0]
|
||||
self.base_file = my_metadata["base_file"]
|
||||
|
@ -59,6 +62,7 @@ class MaterialNode(ContainerNode):
|
|||
# Remove myself from my parent.
|
||||
if self.base_file in self.variant.materials:
|
||||
del self.variant.materials[self.base_file]
|
||||
self.materialChanged.emit(self)
|
||||
|
||||
## Triggered when any metadata changed in any container, but only handles
|
||||
# it when the metadata of this node is changed.
|
||||
|
@ -85,3 +89,4 @@ class MaterialNode(ContainerNode):
|
|||
if self.base_file != old_base_file or self.material_type != old_material_type or self.guid != old_guid: # List of quality profiles could've changed.
|
||||
self.qualities = {}
|
||||
self._loadAll() # Re-load the quality profiles for this node.
|
||||
self.materialChanged.emit(self)
|
|
@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
|||
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
from UM.Signal import Signal
|
||||
from cura.Machines.ContainerNode import ContainerNode
|
||||
from cura.Machines.MaterialNode import MaterialNode
|
||||
|
||||
|
@ -26,6 +27,8 @@ class VariantNode(ContainerNode):
|
|||
super().__init__(container_id)
|
||||
self.machine = machine
|
||||
self.materials = {} # type: Dict[str, MaterialNode] # Mapping material base files to their nodes.
|
||||
self.materialsChanged = Signal()
|
||||
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
self.variant_name = container_registry.findContainersMetadata(id = container_id)[0]["name"] # Store our own name so that we can filter more easily.
|
||||
container_registry.containerAdded.connect(self._materialAdded)
|
||||
|
@ -55,6 +58,7 @@ class VariantNode(ContainerNode):
|
|||
base_file = material["base_file"]
|
||||
if base_file not in self.materials:
|
||||
self.materials[base_file] = MaterialNode(material["id"], variant = self)
|
||||
self.materials[base_file].materialChanged.connect(self.materialsChanged)
|
||||
|
||||
## When a material gets added to the set of profiles, we need to update our
|
||||
# tree here.
|
||||
|
@ -86,3 +90,4 @@ class VariantNode(ContainerNode):
|
|||
return # Original was already specific or just as unspecific as the new one.
|
||||
|
||||
self.materials[base_file] = MaterialNode(container.getId(), variant = self)
|
||||
self.materials[base_file].materialChanged.connect(self.materialsChanged)
|
Loading…
Add table
Add a link
Reference in a new issue