QualityGroup.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 UM.Logger import Logger
  5. from UM.Util import parseBool
  6. from cura.Machines.ContainerNode import ContainerNode
  7. class QualityGroup:
  8. """A QualityGroup represents a group of quality containers that must be applied to each ContainerStack when it's
  9. used.
  10. A concrete example: When there are two extruders and the user selects the quality type "normal", this quality
  11. type must be applied to all stacks in a machine, although each stack can have different containers. So one global
  12. profile gets put on the global stack and one extruder profile gets put on each extruder stack. This quality group
  13. then contains the following profiles (for instance):
  14. - GlobalStack
  15. - ExtruderStack 1
  16. - ExtruderStack 2
  17. quality container:
  18. - um3_global_normal
  19. - um3_aa04_pla_normal
  20. - um3_aa04_abs_normal
  21. The purpose of these quality groups is to group the containers that can be applied to a configuration,
  22. so that when a quality level is selected, the container can directly be applied to each stack instead of looking
  23. them up again.
  24. """
  25. def __init__(self, name: str, quality_type: str) -> None:
  26. """Constructs a new group.
  27. :param name: The user-visible name for the group.
  28. :param quality_type: The quality level that each profile in this group has.
  29. """
  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