SimpleModeSettingsManager.py 4.0 KB

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