QualityNode.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, cast, Any
  4. from .ContainerNode import ContainerNode
  5. from .QualityChangesGroup import QualityChangesGroup
  6. #
  7. # QualityNode is used for BOTH quality and quality_changes containers.
  8. #
  9. class QualityNode(ContainerNode):
  10. def __init__(self, metadata: Optional[Dict[str, Any]] = None) -> None:
  11. super().__init__(metadata = metadata)
  12. self.quality_type_map = {} # type: Dict[str, QualityNode] # quality_type -> QualityNode for InstanceContainer
  13. def getChildNode(self, child_key: str) -> Optional["QualityNode"]:
  14. return self.children_map.get(child_key)
  15. def addQualityMetadata(self, quality_type: str, metadata: Dict[str, Any]):
  16. if quality_type not in self.quality_type_map:
  17. self.quality_type_map[quality_type] = QualityNode(metadata)
  18. def getQualityNode(self, quality_type: str) -> Optional["QualityNode"]:
  19. return self.quality_type_map.get(quality_type)
  20. def addQualityChangesMetadata(self, quality_type: str, metadata: Dict[str, Any]):
  21. if quality_type not in self.quality_type_map:
  22. self.quality_type_map[quality_type] = QualityNode()
  23. quality_type_node = self.quality_type_map[quality_type]
  24. name = metadata["name"]
  25. if name not in quality_type_node.children_map:
  26. quality_type_node.children_map[name] = QualityChangesGroup(name, quality_type)
  27. quality_changes_group = quality_type_node.children_map[name]
  28. cast(QualityChangesGroup, quality_changes_group).addNode(QualityNode(metadata))