QualityGroup.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Dict, Optional, List, Set
  4. from PyQt5.QtCore import QObject, pyqtSlot
  5. from cura.Machines.ContainerNode import ContainerNode
  6. #
  7. # A QualityGroup represents a group of containers that must be applied to each ContainerStack when it's used.
  8. # Some concrete examples are Quality and QualityChanges: when we select quality type "normal", this quality type
  9. # must be applied to all stacks in a machine, although each stack can have different containers. Use an Ultimaker 3
  10. # as an example, suppose we choose quality type "normal", the actual InstanceContainers on each stack may look
  11. # as below:
  12. # GlobalStack ExtruderStack 1 ExtruderStack 2
  13. # quality container: um3_global_normal um3_aa04_pla_normal um3_aa04_abs_normal
  14. #
  15. # This QualityGroup is mainly used in quality and quality_changes to group the containers that can be applied to
  16. # a machine, so when a quality/custom quality is selected, the container can be directly applied to each stack instead
  17. # of looking them up again.
  18. #
  19. class QualityGroup(QObject):
  20. def __init__(self, name: str, quality_type: str, parent = None) -> None:
  21. super().__init__(parent)
  22. self.name = name
  23. self.node_for_global = None # type: Optional[ContainerNode]
  24. self.nodes_for_extruders = {} # type: Dict[int, ContainerNode]
  25. self.quality_type = quality_type
  26. self.is_available = False
  27. @pyqtSlot(result = str)
  28. def getName(self) -> str:
  29. return self.name
  30. def getAllKeys(self) -> Set[str]:
  31. result = set() #type: Set[str]
  32. for node in [self.node_for_global] + list(self.nodes_for_extruders.values()):
  33. if node is None:
  34. continue
  35. container = node.getContainer()
  36. if container:
  37. result.update(container.getAllKeys())
  38. return result
  39. def getAllNodes(self) -> List[ContainerNode]:
  40. result = []
  41. if self.node_for_global is not None:
  42. result.append(self.node_for_global)
  43. for extruder_node in self.nodes_for_extruders.values():
  44. result.append(extruder_node)
  45. return result