CuraPackageManager.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import List, Tuple, TYPE_CHECKING, Optional
  4. from cura.CuraApplication import CuraApplication #To find some resource types.
  5. from cura.Settings.GlobalStack import GlobalStack
  6. from UM.PackageManager import PackageManager #The class we're extending.
  7. from UM.Resources import Resources #To find storage paths for some resource types.
  8. if TYPE_CHECKING:
  9. from UM.Qt.QtApplication import QtApplication
  10. from PyQt5.QtCore import QObject
  11. class CuraPackageManager(PackageManager):
  12. def __init__(self, application: "QtApplication", parent: Optional["QObject"] = None) -> None:
  13. super().__init__(application, parent)
  14. def initialize(self) -> None:
  15. self._installation_dirs_dict["materials"] = Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer)
  16. self._installation_dirs_dict["qualities"] = Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer)
  17. super().initialize()
  18. def getMachinesUsingPackage(self, package_id: str) -> Tuple[List[Tuple[GlobalStack, str, str]], List[Tuple[GlobalStack, str, str]]]:
  19. """Returns a list of where the package is used
  20. It loops through all the package contents and see if some of the ids are used.
  21. :param package_id: package id to search for
  22. :return: empty if it is never used, otherwise a list consisting of 3-tuples
  23. """
  24. ids = self.getPackageContainerIds(package_id)
  25. container_stacks = self._application.getContainerRegistry().findContainerStacks()
  26. global_stacks = [container_stack for container_stack in container_stacks if isinstance(container_stack, GlobalStack)]
  27. machine_with_materials = []
  28. machine_with_qualities = []
  29. for container_id in ids:
  30. for global_stack in global_stacks:
  31. for extruder_nr, extruder_stack in enumerate(global_stack.extruderList):
  32. if container_id in (extruder_stack.material.getId(), extruder_stack.material.getMetaData().get("base_file")):
  33. machine_with_materials.append((global_stack, str(extruder_nr), container_id))
  34. if container_id == extruder_stack.quality.getId():
  35. machine_with_qualities.append((global_stack, str(extruder_nr), container_id))
  36. return machine_with_materials, machine_with_qualities