UserProfilesModel.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # 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. else:
  40. # if there is no active extruder, use the first one in the active extruder stacks
  41. active_extruder = extruder_stacks[0]
  42. extruder_stacks = new_extruder_stacks + extruder_stacks
  43. # Fetch the list of useable qualities across all extruders.
  44. # The actual list of quality profiles come from the first extruder in the extruder list.
  45. quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
  46. extruder_stacks)
  47. # Filter the quality_change by the list of available quality_types
  48. quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
  49. if multiple_extrusion:
  50. # If the printer has multiple extruders then quality changes related to the current extruder are kept
  51. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  52. qc.getMetaDataEntry("extruder") is not None and
  53. (qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
  54. qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())]
  55. else:
  56. # If not, the quality changes of the global stack are selected
  57. filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
  58. qc.getMetaDataEntry("extruder") is None]
  59. return filtered_quality_changes