SimpleModeSettingsManager.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Set
  4. from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty, pyqtSlot
  5. from UM.Application import Application
  6. class SimpleModeSettingsManager(QObject):
  7. def __init__(self, parent = None):
  8. super().__init__(parent)
  9. self._machine_manager = Application.getInstance().getMachineManager()
  10. self._is_profile_customized = False # True when default profile has user changes
  11. self._is_profile_user_created = False # True when profile was custom created by user
  12. self._machine_manager.activeStackValueChanged.connect(self._updateIsProfileCustomized)
  13. # update on create as the activeQualityChanged signal is emitted before this manager is created when Cura starts
  14. self._updateIsProfileCustomized()
  15. isProfileCustomizedChanged = pyqtSignal()
  16. @pyqtProperty(bool, notify = isProfileCustomizedChanged)
  17. def isProfileCustomized(self):
  18. return self._is_profile_customized
  19. def _updateIsProfileCustomized(self):
  20. user_setting_keys = set()
  21. if not self._machine_manager.activeMachine:
  22. return False
  23. global_stack = self._machine_manager.activeMachine
  24. # check user settings in the global stack
  25. user_setting_keys.update(global_stack.userChanges.getAllKeys())
  26. # check user settings in the extruder stacks
  27. if global_stack.extruderList:
  28. for extruder_stack in global_stack.extruderList:
  29. user_setting_keys.update(extruder_stack.userChanges.getAllKeys())
  30. # remove settings that are visible in recommended (we don't show the reset button for those)
  31. for skip_key in self.__ignored_custom_setting_keys:
  32. if skip_key in user_setting_keys:
  33. user_setting_keys.remove(skip_key)
  34. has_customized_user_settings = len(user_setting_keys) > 0
  35. if has_customized_user_settings != self._is_profile_customized:
  36. self._is_profile_customized = has_customized_user_settings
  37. self.isProfileCustomizedChanged.emit()
  38. # These are the settings included in the Simple ("Recommended") Mode, so only when the other settings have been
  39. # changed, we consider it as a user customized profile in the Simple ("Recommended") Mode.
  40. __ignored_custom_setting_keys = ["support_enable",
  41. "infill_sparse_density",
  42. "gradual_infill_steps",
  43. "adhesion_type",
  44. "support_extruder_nr"]