Cura/cura/Machines/QualityNode.py
Ghostkeeper 46cf7aafa9
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.
2019-08-22 16:44:52 +02:00

34 lines
No EOL
1.6 KiB
Python

# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Union, TYPE_CHECKING
from UM.Settings.ContainerRegistry import ContainerRegistry
from cura.Machines.ContainerNode import ContainerNode
from cura.Machines.IntentNode import IntentNode
if TYPE_CHECKING:
from typing import Dict
from cura.Machines.MaterialNode import MaterialNode
from cura.Machines.MachineNode import MachineNode
## Represents a material profile in the container tree.
#
# Its subcontainers are intent profiles.
class QualityNode(ContainerNode):
def __init__(self, container_id: str, parent: Union["MaterialNode", "MachineNode"]) -> None:
super().__init__(container_id)
self.parent = parent
self.intents = {} # type: Dict[str, IntentNode]
self._loadAll()
def _loadAll(self) -> None:
container_registry = ContainerRegistry.getInstance()
# Find all intent profiles that fit the current configuration.
from cura.Machines.MachineNode import MachineNode
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.