UserProfilesModel.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 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 multiple_extrusion:
  30. # Place the active extruder at the front of the list.
  31. extruder_stacks.remove(active_extruder)
  32. extruder_stacks = [active_extruder] + extruder_stacks
  33. # Fetch the list of useable qualities across all extruders.
  34. # The actual list of quality profiles come from the first extruder in the extruder list.
  35. quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
  36. extruder_stacks)
  37. # Filter the quality_change by the list of available quality_types
  38. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  39. if multiple_extrusion:
  40. # If the printer has multiple extruders then quality changes related to the current extruder are kept
  41. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  42. qc.getMetaDataEntry("extruder") is not None and
  43. qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
  44. qc.getMetaDataEntry("extruder") == active_extruder.definition.getId()]
  45. else:
  46. # If not, the quality changes of the global stack are selected
  47. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  48. qc.getMetaDataEntry("extruder") is None]
  49. return filtered_quality_changes