CuraPackageManager.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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
  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. class CuraPackageManager(PackageManager):
  9. def __init__(self, application, parent = None):
  10. super().__init__(application, parent)
  11. def initialize(self):
  12. self._installation_dirs_dict["materials"] = Resources.getStoragePath(CuraApplication.ResourceTypes.MaterialInstanceContainer)
  13. self._installation_dirs_dict["qualities"] = Resources.getStoragePath(CuraApplication.ResourceTypes.QualityInstanceContainer)
  14. super().initialize()
  15. ## Returns a list of where the package is used
  16. # empty if it is never used.
  17. # It loops through all the package contents and see if some of the ids are used.
  18. # The list consists of 3-tuples: (global_stack, extruder_nr, container_id)
  19. def getMachinesUsingPackage(self, package_id: str) -> Tuple[List[Tuple[GlobalStack, str, str]], List[Tuple[GlobalStack, str, str]]]:
  20. ids = self.getPackageContainerIds(package_id)
  21. container_stacks = self._application.getContainerRegistry().findContainerStacks()
  22. global_stacks = [container_stack for container_stack in container_stacks if isinstance(container_stack, GlobalStack)]
  23. machine_with_materials = []
  24. machine_with_qualities = []
  25. for container_id in ids:
  26. for global_stack in global_stacks:
  27. for extruder_nr, extruder_stack in global_stack.extruders.items():
  28. if container_id in (extruder_stack.material.getId(), extruder_stack.material.getMetaData().get("base_file")):
  29. machine_with_materials.append((global_stack, extruder_nr, container_id))
  30. if container_id == extruder_stack.quality.getId():
  31. machine_with_qualities.append((global_stack, extruder_nr, container_id))
  32. return machine_with_materials, machine_with_qualities