SimpleModeSettingsManager.py 3.9 KB

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