QualityGroup.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 UM.Util import parseBool
  6. from cura.Machines.ContainerNode import ContainerNode
  7. #
  8. # A QualityGroup represents a group of containers that must be applied to each ContainerStack when it's used.
  9. # Some concrete examples are Quality and QualityChanges: when we select quality type "normal", this quality type
  10. # must be applied to all stacks in a machine, although each stack can have different containers. Use an Ultimaker 3
  11. # as an example, suppose we choose quality type "normal", the actual InstanceContainers on each stack may look
  12. # as below:
  13. # GlobalStack ExtruderStack 1 ExtruderStack 2
  14. # quality container: um3_global_normal um3_aa04_pla_normal um3_aa04_abs_normal
  15. #
  16. # This QualityGroup is mainly used in quality and quality_changes to group the containers that can be applied to
  17. # a machine, so when a quality/custom quality is selected, the container can be directly applied to each stack instead
  18. # of looking them up again.
  19. #
  20. class QualityGroup(QObject):
  21. def __init__(self, name: str, quality_type: str, parent = None) -> None:
  22. super().__init__(parent)
  23. self.name = name
  24. self.node_for_global = None # type: Optional[ContainerNode]
  25. self.nodes_for_extruders = {} # type: Dict[int, ContainerNode]
  26. self.quality_type = quality_type
  27. self.is_available = False
  28. self.is_experimental = False
  29. @pyqtSlot(result = str)
  30. def getName(self) -> str:
  31. return self.name
  32. def getAllKeys(self) -> Set[str]:
  33. result = set() # type: Set[str]
  34. for node in [self.node_for_global] + list(self.nodes_for_extruders.values()):
  35. if node is None:
  36. continue
  37. container = node.getContainer()
  38. if container:
  39. result.update(container.getAllKeys())
  40. return result
  41. def getAllNodes(self) -> List[ContainerNode]:
  42. result = []
  43. if self.node_for_global is not None:
  44. result.append(self.node_for_global)
  45. for extruder_node in self.nodes_for_extruders.values():
  46. result.append(extruder_node)
  47. return result
  48. def setGlobalNode(self, node: "ContainerNode") -> None:
  49. self.node_for_global = node
  50. # Update is_experimental flag
  51. is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
  52. self.is_experimental |= is_experimental
  53. def setExtruderNode(self, position: int, node: "ContainerNode") -> None:
  54. self.nodes_for_extruders[position] = node
  55. # Update is_experimental flag
  56. is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
  57. self.is_experimental |= is_experimental