RecommendedMode.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt6.QtCore import QObject, pyqtSlot
  4. from cura import CuraApplication
  5. #
  6. # This object contains helper/convenience functions for Recommended mode.
  7. #
  8. class RecommendedMode(QObject):
  9. # Sets to use the adhesion or not for the "Adhesion" CheckBox in Recommended mode.
  10. @pyqtSlot(bool)
  11. def setAdhesion(self, checked: bool) -> None:
  12. application = CuraApplication.CuraApplication.getInstance()
  13. global_stack = application.getMachineManager().activeMachine
  14. if global_stack is None:
  15. return
  16. # Remove the adhesion type value set by the user.
  17. adhesion_type_key = "adhesion_type"
  18. user_changes_container = global_stack.userChanges
  19. if adhesion_type_key in user_changes_container.getAllKeys():
  20. user_changes_container.removeInstance(adhesion_type_key)
  21. # Get the default value of adhesion type after user's value has been removed.
  22. # skirt and none are counted as "no adhesion", the others are considered as "with adhesion". The conditions are
  23. # as the following:
  24. # - if the user checks the adhesion checkbox, get the default value (including the custom quality) for adhesion
  25. # type.
  26. # (1) If the default value is "skirt" or "none" (no adhesion), set adhesion_type to "brim".
  27. # (2) If the default value is "with adhesion", do nothing.
  28. # - if the user unchecks the adhesion checkbox, get the default value (including the custom quality) for
  29. # adhesion type.
  30. # (1) If the default value is "skirt" or "none" (no adhesion), do nothing.
  31. # (2) Otherwise, set adhesion_type to "skirt".
  32. value = global_stack.getProperty(adhesion_type_key, "value")
  33. if checked:
  34. if value in ("skirt", "none"):
  35. value = "brim"
  36. else:
  37. if value not in ("skirt", "none"):
  38. value = "skirt"
  39. user_changes_container.setProperty(adhesion_type_key, "value", value)
  40. __all__ = ["RecommendedMode"]