QualityGroup.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (c) 2019 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.Logger import Logger
  6. from UM.Util import parseBool
  7. from cura.Machines.ContainerNode import ContainerNode
  8. ## A QualityGroup represents a group of quality containers that must be applied
  9. # to each ContainerStack when it's used.
  10. #
  11. # A concrete example: When there are two extruders and the user selects the
  12. # quality type "normal", this quality type must be applied to all stacks in a
  13. # machine, although each stack can have different containers. So one global
  14. # profile gets put on the global stack and one extruder profile gets put on
  15. # each extruder stack. This quality group then contains the following
  16. # profiles (for instance):
  17. # GlobalStack ExtruderStack 1 ExtruderStack 2
  18. # quality container: um3_global_normal um3_aa04_pla_normal um3_aa04_abs_normal
  19. #
  20. # The purpose of these quality groups is to group the containers that can be
  21. # applied to a configuration, so that when a quality level is selected, the
  22. # container can directly be applied to each stack instead of looking them up
  23. # again.
  24. class QualityGroup:
  25. ## Constructs a new group.
  26. # \param name The user-visible name for the group.
  27. # \param quality_type The quality level that each profile in this group
  28. # has.
  29. def __init__(self, name: str, quality_type: str) -> None:
  30. self.name = name
  31. self.node_for_global = None # type: Optional[ContainerNode]
  32. self.nodes_for_extruders = {} # type: Dict[int, ContainerNode]
  33. self.quality_type = quality_type
  34. self.is_available = False
  35. self.is_experimental = False
  36. def getName(self) -> str:
  37. return self.name
  38. def getAllKeys(self) -> Set[str]:
  39. result = set() # type: Set[str]
  40. for node in [self.node_for_global] + list(self.nodes_for_extruders.values()):
  41. if node is None:
  42. continue
  43. container = node.container
  44. if container:
  45. result.update(container.getAllKeys())
  46. return result
  47. def getAllNodes(self) -> List[ContainerNode]:
  48. result = []
  49. if self.node_for_global is not None:
  50. result.append(self.node_for_global)
  51. for extruder_node in self.nodes_for_extruders.values():
  52. result.append(extruder_node)
  53. return result
  54. def setGlobalNode(self, node: "ContainerNode") -> None:
  55. self.node_for_global = node
  56. # Update is_experimental flag
  57. if not node.container:
  58. Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
  59. return
  60. is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
  61. self.is_experimental |= is_experimental
  62. def setExtruderNode(self, position: int, node: "ContainerNode") -> None:
  63. self.nodes_for_extruders[position] = node
  64. # Update is_experimental flag
  65. if not node.container:
  66. Logger.log("w", "Node {0} doesn't have a container.".format(node.container_id))
  67. return
  68. is_experimental = parseBool(node.getMetaDataEntry("is_experimental", False))
  69. self.is_experimental |= is_experimental