QualityNode.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional
  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] = None):
  11. super().__init__(metadata = metadata)
  12. self.quality_type_map = {} # quality_type -> QualityNode for InstanceContainer
  13. def addQualityMetadata(self, quality_type: str, metadata: dict):
  14. if quality_type not in self.quality_type_map:
  15. self.quality_type_map[quality_type] = QualityNode(metadata)
  16. def getQualityNode(self, quality_type: str) -> Optional["QualityNode"]:
  17. return self.quality_type_map.get(quality_type)
  18. def addQualityChangesMetadata(self, quality_type: str, metadata: dict):
  19. if quality_type not in self.quality_type_map:
  20. self.quality_type_map[quality_type] = QualityNode()
  21. quality_type_node = self.quality_type_map[quality_type]
  22. name = metadata["name"]
  23. if name not in quality_type_node.children_map:
  24. quality_type_node.children_map[name] = QualityChangesGroup(name, quality_type)
  25. quality_changes_group = quality_type_node.children_map[name]
  26. quality_changes_group.addNode(QualityNode(metadata))