QualityNode.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Union, TYPE_CHECKING
  4. from UM.Settings.ContainerRegistry import ContainerRegistry
  5. from cura.Machines.ContainerNode import ContainerNode
  6. from cura.Machines.IntentNode import IntentNode
  7. import UM.FlameProfiler
  8. if TYPE_CHECKING:
  9. from typing import Dict
  10. from cura.Machines.MaterialNode import MaterialNode
  11. from cura.Machines.MachineNode import MachineNode
  12. class QualityNode(ContainerNode):
  13. """Represents a quality profile in the container tree.
  14. This may either be a normal quality profile or a global quality profile.
  15. Its subcontainers are intent profiles.
  16. """
  17. def __init__(self, container_id: str, parent: Union["MaterialNode", "MachineNode"]) -> None:
  18. super().__init__(container_id)
  19. self.parent = parent
  20. self.intents = {} # type: Dict[str, IntentNode]
  21. my_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = container_id)[0]
  22. self.quality_type = my_metadata["quality_type"]
  23. # The material type of the parent doesn't need to be the same as this due to generic fallbacks.
  24. self._material = my_metadata.get("material")
  25. self._loadAll()
  26. @UM.FlameProfiler.profile
  27. def _loadAll(self) -> None:
  28. container_registry = ContainerRegistry.getInstance()
  29. # Find all intent profiles that fit the current configuration.
  30. from cura.Machines.MachineNode import MachineNode
  31. if not isinstance(self.parent, MachineNode): # Not a global profile.
  32. for intent in container_registry.findInstanceContainersMetadata(type = "intent", definition = self.parent.variant.machine.quality_definition, variant = self.parent.variant.variant_name, material = self._material, quality_type = self.quality_type):
  33. self.intents[intent["id"]] = IntentNode(intent["id"], quality = self)
  34. self.intents["empty_intent"] = IntentNode("empty_intent", quality = self)
  35. # Otherwise, there are no intents for global profiles.