CustomQualityProfilesDropDownMenuModel.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Logger import Logger
  4. import cura.CuraApplication # Imported this way to prevent circular references.
  5. from cura.Machines.ContainerTree import ContainerTree
  6. from cura.Machines.Models.QualityProfilesDropDownMenuModel import QualityProfilesDropDownMenuModel
  7. ## This model is used for the custom profile items in the profile drop down
  8. # menu.
  9. class CustomQualityProfilesDropDownMenuModel(QualityProfilesDropDownMenuModel):
  10. def _update(self):
  11. Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
  12. active_global_stack = cura.CuraApplication.CuraApplication.getInstance().getMachineManager().activeMachine
  13. if active_global_stack is None:
  14. self.setItems([])
  15. Logger.log("d", "No active GlobalStack, set %s as empty.", self.__class__.__name__)
  16. return
  17. variant_names = [extruder.variant.getName() for extruder in active_global_stack.extruders.values()]
  18. material_bases = [extruder.material.getMetaDataEntry("base_file") for extruder in active_global_stack.extruders.values()]
  19. extruder_enabled = [extruder.isEnabled for extruder in active_global_stack.extruders.values()]
  20. machine_node = ContainerTree.getInstance().machines[active_global_stack.definition.getId()]
  21. quality_changes_list = machine_node.getQualityChangesGroups(variant_names, material_bases, extruder_enabled)
  22. item_list = []
  23. for quality_changes_group in sorted(quality_changes_list, key = lambda qgc: qgc.name.lower()):
  24. item = {"name": quality_changes_group.name,
  25. "layer_height": "",
  26. "layer_height_without_unit": "",
  27. "available": quality_changes_group.is_available,
  28. "quality_changes_group": quality_changes_group}
  29. item_list.append(item)
  30. self.setItems(item_list)