QualityGroup.py 3.2 KB

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