mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Encode empty containers in container tree if necessary
You can now be assured that there is ALWAYS at least one child node, except for child nodes of intent profiles which don't exist. Contributes to issue CURA-6600.
This commit is contained in:
parent
81a33af3aa
commit
46cf7aafa9
4 changed files with 24 additions and 12 deletions
|
@ -92,17 +92,19 @@ class MachineNode(ContainerNode):
|
|||
|
||||
## (Re)loads all variants under this printer.
|
||||
def _loadAll(self):
|
||||
if not self.has_variants:
|
||||
return
|
||||
|
||||
# Find all the variants for this definition ID.
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
if not self.has_variants:
|
||||
self.variants["empty"] = VariantNode("empty_variant", machine = self)
|
||||
else:
|
||||
# Find all the variants for this definition ID.
|
||||
variants = container_registry.findInstanceContainersMetadata(type = "variant", definition = self.container_id, hardware_type = "nozzle")
|
||||
for variant in variants:
|
||||
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)
|
||||
if not self.variants:
|
||||
self.variants["empty"] = VariantNode("empty_variant", machine = self)
|
||||
|
||||
# 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.
|
||||
|
|
|
@ -53,6 +53,8 @@ class MaterialNode(ContainerNode):
|
|||
quality_id = quality["id"]
|
||||
if quality_id not in self.qualities:
|
||||
self.qualities[quality_id] = QualityNode(quality_id, parent = self)
|
||||
if not self.qualities:
|
||||
self.qualities["empty_quality"] = QualityNode("empty_quality", parent = self)
|
||||
|
||||
## Triggered when any container is removed, but only handles it when the
|
||||
# container is removed that this node represents.
|
||||
|
@ -62,6 +64,8 @@ class MaterialNode(ContainerNode):
|
|||
# Remove myself from my parent.
|
||||
if self.base_file in self.variant.materials:
|
||||
del self.variant.materials[self.base_file]
|
||||
if not self.variant.materials:
|
||||
self.variant.materials["empty_material"] = MaterialNode("empty_material", variant = self.variant)
|
||||
self.materialChanged.emit(self)
|
||||
|
||||
## Triggered when any metadata changed in any container, but only handles
|
||||
|
|
|
@ -29,4 +29,6 @@ class QualityNode(ContainerNode):
|
|||
if not isinstance(self.parent, MachineNode): # Not a global profile.
|
||||
for intent in container_registry.findInstanceContainersMetadata(type = "intent", definition = self.parent.variant.machine.quality_definition, variant = self.parent.variant.variant_name, material = self.parent.base_file):
|
||||
self.intents[intent["id"]] = IntentNode(intent["id"], quality = self)
|
||||
if not self.intents:
|
||||
self.intents["empty_intent"] = IntentNode("empty_intent", quality = self)
|
||||
# Otherwise, there are no intents for global profiles.
|
|
@ -6,7 +6,6 @@ from typing import Optional, TYPE_CHECKING
|
|||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.Interfaces import ContainerInterface
|
||||
from UM.Signal import Signal
|
||||
from UM.Util import parseBool
|
||||
from cura.Machines.ContainerNode import ContainerNode
|
||||
from cura.Machines.MaterialNode import MaterialNode
|
||||
|
||||
|
@ -40,6 +39,7 @@ class VariantNode(ContainerNode):
|
|||
container_registry = ContainerRegistry.getInstance()
|
||||
|
||||
if not self.machine.has_materials:
|
||||
self.materials["empty_material"] = MaterialNode("empty_material", variant = self)
|
||||
return # There should not be any materials loaded for this printer.
|
||||
|
||||
# Find all the materials for this variant's name.
|
||||
|
@ -48,7 +48,7 @@ class VariantNode(ContainerNode):
|
|||
else: # Printer has its own material profiles. Look for material profiles with this printer's definition.
|
||||
all_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = "fdmprinter")
|
||||
printer_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.machine.container_id)
|
||||
variant_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.machine.container_id, variant = self.variant_name)
|
||||
variant_specific_materials = container_registry.findInstanceContainersMetadata(type = "material", definition = self.machine.container_id, variant = self.variant_name) # If empty_variant, this won't return anything.
|
||||
materials_per_base_file = {material["base_file"]: material for material in all_materials}
|
||||
materials_per_base_file.update({material["base_file"]: material for material in printer_specific_materials}) # Printer-specific profiles override global ones.
|
||||
materials_per_base_file.update({material["base_file"]: material for material in variant_specific_materials}) # Variant-specific profiles override all of those.
|
||||
|
@ -64,6 +64,8 @@ class VariantNode(ContainerNode):
|
|||
if base_file not in self.materials:
|
||||
self.materials[base_file] = MaterialNode(material["id"], variant = self)
|
||||
self.materials[base_file].materialChanged.connect(self.materialsChanged)
|
||||
if not self.materials:
|
||||
self.materials["empty_material"] = MaterialNode("empty_material", variant = self)
|
||||
|
||||
## Finds the preferred material for this printer with this nozzle in one of
|
||||
# the extruders.
|
||||
|
@ -112,5 +114,7 @@ class VariantNode(ContainerNode):
|
|||
if original_variant != "empty" or container.getMetaDataEntry("variant", "empty") == "empty":
|
||||
return # Original was already specific or just as unspecific as the new one.
|
||||
|
||||
if "empty_material" in self.materials:
|
||||
del self.materials["empty_material"]
|
||||
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