UserProfilesModel.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. # Detecting if the machine has multiple extrusion
  24. multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
  25. # Get the list of extruders and place the selected extruder at the front of the list.
  26. extruder_manager = ExtruderManager.getInstance()
  27. active_extruder = extruder_manager.getActiveExtruderStack()
  28. extruder_stacks = extruder_manager.getActiveExtruderStacks()
  29. if extruder_stacks:
  30. if multiple_extrusion:
  31. # Place the active extruder at the front of the list.
  32. if active_extruder in extruder_stacks:
  33. extruder_stacks.remove(active_extruder)
  34. extruder_stacks = [active_extruder] + extruder_stacks
  35. else:
  36. # The active extruder is the first in the list and only the active extruder is use to compute the usable qualities
  37. active_extruder = None
  38. extruder_stacks = []
  39. # Fetch the list of useable qualities across all extruders.
  40. # The actual list of quality profiles come from the first extruder in the extruder list.
  41. quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
  42. extruder_stacks)
  43. # Filter the quality_change by the list of available quality_types
  44. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  45. if multiple_extrusion:
  46. # If the printer has multiple extruders then quality changes related to the current extruder are kept
  47. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition")]
  48. else:
  49. # If not, the quality changes of the global stack are selected
  50. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and qc.getMetaDataEntry("extruder") is None]
  51. return filtered_quality_changes