MaterialNode.py 1.1 KB

12345678910111213141516171819202122232425
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional, Dict, Any
  4. from collections import OrderedDict
  5. from .ContainerNode import ContainerNode
  6. #
  7. # A MaterialNode is a node in the material lookup tree/map/table. It contains 2 (extra) fields:
  8. # - material_map: a one-to-one map of "material_root_id" to material_node.
  9. # - children_map: the key-value map for child nodes of this node. This is used in a lookup tree.
  10. #
  11. #
  12. class MaterialNode(ContainerNode):
  13. __slots__ = ("material_map", "children_map")
  14. def __init__(self, metadata: Optional[Dict[str, Any]] = None) -> None:
  15. super().__init__(metadata = metadata)
  16. self.material_map = {} # type: Dict[str, MaterialNode] # material_root_id -> material_node
  17. # We overide this as we want to indicate that MaterialNodes can only contain other material nodes.
  18. self.children_map = OrderedDict() # type: OrderedDict[str, "MaterialNode"]
  19. def getChildNode(self, child_key: str) -> Optional["MaterialNode"]:
  20. return self.children_map.get(child_key)