RecommendedMode.py 2.2 KB

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