ContainerGroup.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import List, Optional
  4. from PyQt5.Qt import QObject, pyqtSlot
  5. from cura.Machines.ContainerNode import ContainerNode
  6. #
  7. # A ContainerGroup 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 InstanceConstainers 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 ContainerGroup 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 ContainerGroup(QObject):
  20. def __init__(self, name: str, parent = None):
  21. super().__init__(parent)
  22. self.name = name
  23. self.node_for_global = None # type: Optional[ContainerNode]
  24. self.nodes_for_extruders = dict()
  25. @pyqtSlot(result = str)
  26. def getName(self) -> str:
  27. return self.name
  28. def getAllKeys(self) -> set:
  29. result = set()
  30. for node in [self.node_for_global] + list(self.nodes_for_extruders.values()):
  31. if node is None:
  32. continue
  33. for key in node.getContainer().getAllKeys():
  34. result.add(key)
  35. return result
  36. def getAllNodes(self) -> List[ContainerNode]:
  37. result = []
  38. if self.node_for_global is not None:
  39. result.append(self.node_for_global)
  40. for extruder_node in self.nodes_for_extruders.values():
  41. result.append(extruder_node)
  42. return result