Rework container tree structure

This sets up a few new classes, subclasses of ContainerNode.

This is intended to simplify the current structure in the QualityManager.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-05 17:39:19 +02:00
parent 037f1967c8
commit 9fda7bd0b9
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
6 changed files with 136 additions and 63 deletions

View file

@ -1,25 +1,19 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Optional, Dict, Any
from collections import OrderedDict
from .ContainerNode import ContainerNode
from typing import TYPE_CHECKING
from cura.Machines.ContainerNode import ContainerNode
from cura.Machines.QualityNode import QualityNode
from cura.Machines.VariantNode import VariantNode
if TYPE_CHECKING:
from typing import Dict
## Represents a material in the container tree.
#
# A MaterialNode is a node in the material lookup tree/map/table. It contains 2 (extra) fields:
# - material_map: a one-to-one map of "material_root_id" to material_node.
# - children_map: the key-value map for child nodes of this node. This is used in a lookup tree.
#
#
# Its subcontainers are quality profiles.
class MaterialNode(ContainerNode):
__slots__ = ("material_map", "children_map")
def __init__(self, metadata: Optional[Dict[str, Any]] = None) -> None:
super().__init__(metadata = metadata)
self.material_map = {} # type: Dict[str, MaterialNode] # material_root_id -> material_node
# We overide this as we want to indicate that MaterialNodes can only contain other material nodes.
self.children_map = OrderedDict() # type: OrderedDict[str, "MaterialNode"]
def getChildNode(self, child_key: str) -> Optional["MaterialNode"]:
return self.children_map.get(child_key)
def __init__(self, container_id, parent: VariantNode) -> None:
super().__init__(container_id, parent)
self.qualities = {} # type: Dict[str, QualityNode] # Mapping container IDs to quality profiles.