UserProfilesModel.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from UM.Application import Application
  4. from cura.QualityManager import QualityManager
  5. from cura.Settings.ProfilesModel import ProfilesModel
  6. from cura.Settings.ExtruderManager import ExtruderManager
  7. ## QML Model for listing the current list of valid quality changes profiles.
  8. #
  9. class UserProfilesModel(ProfilesModel):
  10. def __init__(self, parent = None):
  11. super().__init__(parent)
  12. ## Fetch the list of containers to display.
  13. #
  14. # See UM.Settings.Models.InstanceContainersModel._fetchInstanceContainers().
  15. def _fetchInstanceContainers(self):
  16. global_container_stack = Application.getInstance().getGlobalContainerStack()
  17. if not global_container_stack:
  18. return []
  19. # Fetch the list of quality changes.
  20. quality_manager = QualityManager.getInstance()
  21. machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
  22. quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
  23. # Fetch the list of qualities
  24. quality_list = QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
  25. ExtruderManager.getInstance().getActiveExtruderStacks())
  26. # Filter the quality_change by the list of available quality_types
  27. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  28. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set]
  29. #Only display the global quality changes.
  30. #Otherwise you get multiple copies of every quality changes profile.
  31. #The actual profile switching goes by profile name (not ID), and as long as the names are consistent, switching to any of the profiles will cause all stacks to switch.
  32. filtered_quality_changes = list(filter(lambda quality_changes: quality_changes.getMetaDataEntry("extruder") is None, filtered_quality_changes))
  33. return filtered_quality_changes