SimpleModeSettingsManager.py 2.6 KB

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