QualityAndUserProfilesModel.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Application import Application
  4. from UM.Settings.ContainerRegistry import ContainerRegistry
  5. from cura.QualityManager import QualityManager
  6. from cura.Settings.ProfilesModel import ProfilesModel
  7. from cura.Settings.ExtruderManager import ExtruderManager
  8. ## QML Model for listing the current list of valid quality and quality changes profiles.
  9. #
  10. class QualityAndUserProfilesModel(ProfilesModel):
  11. def __init__(self, parent = None):
  12. super().__init__(parent)
  13. self._empty_quality = ContainerRegistry.getInstance().findInstanceContainers(id = "empty_quality")[0]
  14. ## Fetch the list of containers to display.
  15. #
  16. # See UM.Settings.Models.InstanceContainersModel._fetchInstanceContainers().
  17. def _fetchInstanceContainers(self):
  18. global_container_stack = Application.getInstance().getGlobalContainerStack()
  19. if not global_container_stack:
  20. return {}, {}
  21. # Fetch the list of quality changes.
  22. quality_manager = QualityManager.getInstance()
  23. machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.definition)
  24. quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
  25. extruder_manager = ExtruderManager.getInstance()
  26. active_extruder = extruder_manager.getActiveExtruderStack()
  27. extruder_stacks = self._getOrderedExtruderStacksList()
  28. # Fetch the list of usable qualities across all extruders.
  29. # The actual list of quality profiles come from the first extruder in the extruder list.
  30. quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
  31. # Filter the quality_change by the list of available quality_types
  32. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  33. # Also show custom profiles based on "Not Supported" quality profile
  34. quality_type_set.add(self._empty_quality.getMetaDataEntry("quality_type"))
  35. filtered_quality_changes = {qc.getId(): qc for qc in quality_changes_list if
  36. qc.getMetaDataEntry("quality_type") in quality_type_set and
  37. qc.getMetaDataEntry("extruder") is not None and
  38. (qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
  39. qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())}
  40. result = filtered_quality_changes
  41. for q in quality_list:
  42. if q.getId() != "empty_quality":
  43. result[q.getId()] = q
  44. return result, {} #Only return true profiles for now, no metadata. The quality manager is not able to get only metadata yet.