QualityGroup.py 2.1 KB

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