QualityNode.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. ## Represents a quality profile in the container tree.
  13. #
  14. # This may either be a normal quality profile or a global quality profile.
  15. #
  16. # Its subcontainers are intent profiles.
  17. class QualityNode(ContainerNode):
  18. def __init__(self, container_id: str, parent: Union["MaterialNode", "MachineNode"]) -> None:
  19. super().__init__(container_id)
  20. self.parent = parent
  21. self.intents = {} # type: Dict[str, IntentNode]
  22. my_metadata = ContainerRegistry.getInstance().findContainersMetadata(id = container_id)[0]
  23. self.quality_type = my_metadata["quality_type"]
  24. # The material type of the parent doesn't need to be the same as this due to generic fallbacks.
  25. self._material = my_metadata.get("material")
  26. self._loadAll()
  27. @UM.FlameProfiler.profile
  28. def _loadAll(self) -> None:
  29. container_registry = ContainerRegistry.getInstance()
  30. # Find all intent profiles that fit the current configuration.
  31. from cura.Machines.MachineNode import MachineNode
  32. if not isinstance(self.parent, MachineNode): # Not a global profile.
  33. 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):
  34. self.intents[intent["id"]] = IntentNode(intent["id"], quality = self)
  35. self.intents["empty_intent"] = IntentNode("empty_intent", quality = self)
  36. # Otherwise, there are no intents for global profiles.