CuraPackageManager.py 2.1 KB

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