QualityAndUserProfilesModel.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 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 and quality changes profiles.
  8. #
  9. class QualityAndUserProfilesModel(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
  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. # This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
  32. # Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
  33. # cases the active_extruder is still None.
  34. if active_extruder in extruder_stacks:
  35. extruder_stacks.remove(active_extruder)
  36. new_extruder_stacks = []
  37. if active_extruder is not None:
  38. new_extruder_stacks = [active_extruder]
  39. extruder_stacks = new_extruder_stacks + extruder_stacks
  40. # Fetch the list of useable qualities across all extruders.
  41. # The actual list of quality profiles come from the first extruder in the extruder list.
  42. quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
  43. extruder_stacks)
  44. # Filter the quality_change by the list of available quality_types
  45. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  46. if multiple_extrusion:
  47. # If the printer has multiple extruders then quality changes related to the current extruder are kept
  48. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  49. qc.getMetaDataEntry("extruder") is not None and
  50. qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
  51. qc.getMetaDataEntry("extruder") == active_extruder.definition.getId()]
  52. else:
  53. # If not, the quality changes of the global stack are selected
  54. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  55. qc.getMetaDataEntry("extruder") is None]
  56. return quality_list + filtered_quality_changes