MachineNode.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import TYPE_CHECKING
  4. from UM.Util import parseBool
  5. from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
  6. from UM.Settings.Interfaces import ContainerInterface
  7. from cura.Machines.ContainerNode import ContainerNode
  8. from cura.Machines.VariantNode import VariantNode
  9. if TYPE_CHECKING:
  10. from typing import Dict
  11. ## This class represents a machine in the container tree.
  12. #
  13. # The subnodes of these nodes are variants.
  14. class MachineNode(ContainerNode):
  15. def __init__(self, container_id: str) -> None:
  16. super().__init__(container_id, None)
  17. self.variants = {} # type: Dict[str, VariantNode] # mapping variant names to their nodes.
  18. container_registry = ContainerRegistry.getInstance()
  19. self.has_machine_materials = parseBool(container_registry.findContainersMetadata(id = container_id)[0].get("has_machine_materials", "true"))
  20. container_registry.containerAdded.connect(self._variantAdded)
  21. self._loadAll()
  22. ## (Re)loads all variants under this printer.
  23. def _loadAll(self):
  24. # Find all the variants for this definition ID.
  25. variants = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "variant", definition = self.container_id, hardware_type = "nozzle")
  26. for variant in variants:
  27. variant_name = variant["name"]
  28. if variant_name not in self.variants:
  29. self.variants[variant_name] = VariantNode(variant["id"], parent = self)
  30. ## When a variant gets added to the set of profiles, we need to update our
  31. # tree here.
  32. def _variantAdded(self, container: ContainerInterface):
  33. if container.getMetaDataEntry("type") != "variant":
  34. return # Not interested.
  35. name = container.getMetaDataEntry("name")
  36. if name in self.variants:
  37. return # Already have this one.
  38. self.variants[name] = VariantNode(container.getId(), parent = self)