SimpleModeSettingsManager.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. self._machine_manager.activeQualityChanged.connect(self._updateIsProfileUserCreated)
  13. # update on create as the activeQualityChanged signal is emitted before this manager is created when Cura starts
  14. self._updateIsProfileCustomized()
  15. self._updateIsProfileUserCreated()
  16. isProfileCustomizedChanged = pyqtSignal()
  17. isProfileUserCreatedChanged = pyqtSignal()
  18. @pyqtProperty(bool, notify = isProfileCustomizedChanged)
  19. def isProfileCustomized(self):
  20. return self._is_profile_customized
  21. def _updateIsProfileCustomized(self):
  22. user_setting_keys = set()
  23. if not self._machine_manager.activeMachine:
  24. return False
  25. global_stack = self._machine_manager.activeMachine
  26. # check user settings in the global stack
  27. user_setting_keys.update(set(global_stack.userChanges.getAllKeys()))
  28. # check user settings in the extruder stacks
  29. if global_stack.extruders:
  30. for extruder_stack in global_stack.extruders.values():
  31. user_setting_keys.update(set(extruder_stack.userChanges.getAllKeys()))
  32. # remove settings that are visible in recommended (we don't show the reset button for those)
  33. for skip_key in self.__ignored_custom_setting_keys:
  34. if skip_key in user_setting_keys:
  35. user_setting_keys.remove(skip_key)
  36. has_customized_user_settings = len(user_setting_keys) > 0
  37. if has_customized_user_settings != self._is_profile_customized:
  38. self._is_profile_customized = has_customized_user_settings
  39. self.isProfileCustomizedChanged.emit()
  40. @pyqtProperty(bool, notify = isProfileUserCreatedChanged)
  41. def isProfileUserCreated(self):
  42. return self._is_profile_user_created
  43. def _updateIsProfileUserCreated(self):
  44. quality_changes_keys = set()
  45. if not self._machine_manager.activeMachine:
  46. return False
  47. global_stack = self._machine_manager.activeMachine
  48. # check quality changes settings in the global stack
  49. quality_changes_keys.update(set(global_stack.qualityChanges.getAllKeys()))
  50. # check quality changes settings in the extruder stacks
  51. if global_stack.extruders:
  52. for extruder_stack in global_stack.extruders.values():
  53. quality_changes_keys.update(set(extruder_stack.qualityChanges.getAllKeys()))
  54. # check if the qualityChanges container is not empty (meaning it is a user created profile)
  55. has_quality_changes = len(quality_changes_keys) > 0
  56. if has_quality_changes != self._is_profile_user_created:
  57. self._is_profile_user_created = has_quality_changes
  58. self.isProfileUserCreatedChanged.emit()
  59. # These are the settings included in the Simple ("Recommended") Mode, so only when the other settings have been
  60. # changed, we consider it as a user customized profile in the Simple ("Recommended") Mode.
  61. __ignored_custom_setting_keys = ["support_enable",
  62. "infill_sparse_density",
  63. "gradual_infill_steps",
  64. "adhesion_type",
  65. "support_extruder_nr"]