MachineManager.py 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import collections
  4. import time
  5. #Type hinting.
  6. from typing import Union, List, Dict, TYPE_CHECKING, Optional
  7. from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
  8. from UM.Signal import Signal
  9. from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
  10. import UM.FlameProfiler
  11. from UM.FlameProfiler import pyqtSlot
  12. from UM import Util
  13. from UM.Application import Application
  14. from UM.Preferences import Preferences
  15. from UM.Logger import Logger
  16. from UM.Message import Message
  17. from UM.Settings.ContainerRegistry import ContainerRegistry
  18. from UM.Settings.InstanceContainer import InstanceContainer
  19. from UM.Settings.SettingFunction import SettingFunction
  20. from UM.Signal import postponeSignals, CompressTechnique
  21. from cura.Machines.QualityManager import getMachineDefinitionIDForQualitySearch
  22. from cura.PrinterOutputDevice import PrinterOutputDevice
  23. from cura.Settings.ExtruderManager import ExtruderManager
  24. from .CuraStackBuilder import CuraStackBuilder
  25. from UM.i18n import i18nCatalog
  26. catalog = i18nCatalog("cura")
  27. if TYPE_CHECKING:
  28. from cura.Settings.CuraContainerStack import CuraContainerStack
  29. from cura.Settings.GlobalStack import GlobalStack
  30. class MachineManager(QObject):
  31. def __init__(self, parent = None):
  32. super().__init__(parent)
  33. self._active_container_stack = None # type: CuraContainerStack
  34. self._global_container_stack = None # type: GlobalStack
  35. self._current_root_material_id = {}
  36. self._current_root_material_name = {}
  37. self._current_quality_group = None
  38. self._current_quality_changes_group = None
  39. self._default_extruder_position = "0" # to be updated when extruders are switched on and off
  40. self.machine_extruder_material_update_dict = collections.defaultdict(list)
  41. self._error_check_timer = QTimer()
  42. self._error_check_timer.setInterval(250)
  43. self._error_check_timer.setSingleShot(True)
  44. self._error_check_timer.timeout.connect(self._updateStacksHaveErrors)
  45. self._instance_container_timer = QTimer()
  46. self._instance_container_timer.setInterval(250)
  47. self._instance_container_timer.setSingleShot(True)
  48. self._instance_container_timer.timeout.connect(self.__emitChangedSignals)
  49. self._application = Application.getInstance()
  50. self._application.globalContainerStackChanged.connect(self._onGlobalContainerChanged)
  51. self._application.getContainerRegistry().containerLoadComplete.connect(self._onInstanceContainersChanged)
  52. ## When the global container is changed, active material probably needs to be updated.
  53. self.globalContainerChanged.connect(self.activeMaterialChanged)
  54. self.globalContainerChanged.connect(self.activeVariantChanged)
  55. self.globalContainerChanged.connect(self.activeQualityChanged)
  56. self.globalContainerChanged.connect(self.activeQualityChangesGroupChanged)
  57. self.globalContainerChanged.connect(self.activeQualityGroupChanged)
  58. self._stacks_have_errors = None # type:Optional[bool]
  59. self._empty_definition_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_definition_changes")[0]
  60. self._empty_variant_container = ContainerRegistry.getInstance().findContainers(id = "empty_variant")[0]
  61. self._empty_material_container = ContainerRegistry.getInstance().findContainers(id = "empty_material")[0]
  62. self._empty_quality_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality")[0]
  63. self._empty_quality_changes_container = ContainerRegistry.getInstance().findContainers(id = "empty_quality_changes")[0]
  64. self._onGlobalContainerChanged()
  65. ExtruderManager.getInstance().activeExtruderChanged.connect(self._onActiveExtruderStackChanged)
  66. self._onActiveExtruderStackChanged()
  67. ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeMaterialChanged)
  68. ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeVariantChanged)
  69. ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeQualityChanged)
  70. self.globalContainerChanged.connect(self.activeStackChanged)
  71. self.globalValueChanged.connect(self.activeStackValueChanged)
  72. ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
  73. self.activeStackChanged.connect(self.activeStackValueChanged)
  74. Preferences.getInstance().addPreference("cura/active_machine", "")
  75. self._global_event_keys = set()
  76. self._printer_output_devices = []
  77. Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged)
  78. # There might already be some output devices by the time the signal is connected
  79. self._onOutputDevicesChanged()
  80. self._application.callLater(self.setInitialActiveMachine)
  81. self._material_incompatible_message = Message(catalog.i18nc("@info:status",
  82. "The selected material is incompatible with the selected machine or configuration."),
  83. title = catalog.i18nc("@info:title", "Incompatible Material"))
  84. containers = ContainerRegistry.getInstance().findInstanceContainers(id = self.activeMaterialId)
  85. if containers:
  86. containers[0].nameChanged.connect(self._onMaterialNameChanged)
  87. # NEW
  88. self._material_manager = self._application._material_manager
  89. self._material_manager.materialsUpdated.connect(self._onMaterialsUpdated)
  90. def _onMaterialsUpdated(self):
  91. # When the materials lookup table gets updated, it can mean that a material has its name changed, which should
  92. # be reflected on the GUI. This signal emission makes sure that it happens.
  93. self.rootMaterialChanged.emit()
  94. ### NEW
  95. activeQualityGroupChanged = pyqtSignal()
  96. activeQualityChangesGroupChanged = pyqtSignal()
  97. globalContainerChanged = pyqtSignal() # Emitted whenever the global stack is changed (ie: when changing between printers, changing a global profile, but not when changing a value)
  98. activeMaterialChanged = pyqtSignal()
  99. activeVariantChanged = pyqtSignal()
  100. activeQualityChanged = pyqtSignal()
  101. activeStackChanged = pyqtSignal() # Emitted whenever the active stack is changed (ie: when changing between extruders, changing a profile, but not when changing a value)
  102. extruderChanged = pyqtSignal()
  103. globalValueChanged = pyqtSignal() # Emitted whenever a value inside global container is changed.
  104. activeStackValueChanged = pyqtSignal() # Emitted whenever a value inside the active stack is changed.
  105. activeStackValidationChanged = pyqtSignal() # Emitted whenever a validation inside active container is changed
  106. stacksValidationChanged = pyqtSignal() # Emitted whenever a validation is changed
  107. blurSettings = pyqtSignal() # Emitted to force fields in the advanced sidebar to un-focus, so they update properly
  108. outputDevicesChanged = pyqtSignal()
  109. rootMaterialChanged = pyqtSignal()
  110. def setInitialActiveMachine(self):
  111. active_machine_id = Preferences.getInstance().getValue("cura/active_machine")
  112. if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacksMetadata(id = active_machine_id):
  113. # An active machine was saved, so restore it.
  114. self.setActiveMachine(active_machine_id)
  115. # Make sure _active_container_stack is properly initiated
  116. ExtruderManager.getInstance().setActiveExtruderIndex(0)
  117. def _onOutputDevicesChanged(self) -> None:
  118. self._printer_output_devices = []
  119. for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
  120. if isinstance(printer_output_device, PrinterOutputDevice):
  121. self._printer_output_devices.append(printer_output_device)
  122. self.outputDevicesChanged.emit()
  123. @pyqtProperty("QVariantList", notify = outputDevicesChanged)
  124. def printerOutputDevices(self):
  125. return self._printer_output_devices
  126. @pyqtProperty(int, constant=True)
  127. def totalNumberOfSettings(self) -> int:
  128. return len(ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0].getAllKeys())
  129. def _onGlobalContainerChanged(self) -> None:
  130. if self._global_container_stack:
  131. try:
  132. self._global_container_stack.nameChanged.disconnect(self._onMachineNameChanged)
  133. except TypeError: # pyQtSignal gives a TypeError when disconnecting from something that was already disconnected.
  134. pass
  135. try:
  136. self._global_container_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
  137. except TypeError:
  138. pass
  139. try:
  140. self._global_container_stack.propertyChanged.disconnect(self._onPropertyChanged)
  141. except TypeError:
  142. pass
  143. for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
  144. extruder_stack.propertyChanged.disconnect(self._onPropertyChanged)
  145. extruder_stack.containersChanged.disconnect(self._onInstanceContainersChanged)
  146. # Update the local global container stack reference
  147. self._global_container_stack = Application.getInstance().getGlobalContainerStack()
  148. self.globalContainerChanged.emit()
  149. # after switching the global stack we reconnect all the signals and set the variant and material references
  150. if self._global_container_stack:
  151. Preferences.getInstance().setValue("cura/active_machine", self._global_container_stack.getId())
  152. self._global_container_stack.nameChanged.connect(self._onMachineNameChanged)
  153. self._global_container_stack.containersChanged.connect(self._onInstanceContainersChanged)
  154. self._global_container_stack.propertyChanged.connect(self._onPropertyChanged)
  155. # Global stack can have only a variant if it is a buildplate
  156. global_variant = self._global_container_stack.variant
  157. if global_variant != self._empty_variant_container:
  158. if global_variant.getMetaDataEntry("hardware_type") != "buildplate":
  159. self._global_container_stack.setVariant(self._empty_variant_container)
  160. # set the global material to empty as we now use the extruder stack at all times - CURA-4482
  161. global_material = self._global_container_stack.material
  162. if global_material != self._empty_material_container:
  163. self._global_container_stack.setMaterial(self._empty_material_container)
  164. # Listen for changes on all extruder stacks
  165. for extruder_stack in ExtruderManager.getInstance().getActiveExtruderStacks():
  166. extruder_stack.propertyChanged.connect(self._onPropertyChanged)
  167. extruder_stack.containersChanged.connect(self._onInstanceContainersChanged)
  168. if self._global_container_stack.getId() in self.machine_extruder_material_update_dict:
  169. for func in self.machine_extruder_material_update_dict[self._global_container_stack.getId()]:
  170. Application.getInstance().callLater(func)
  171. del self.machine_extruder_material_update_dict[self._global_container_stack.getId()]
  172. self.activeQualityGroupChanged.emit()
  173. self._error_check_timer.start()
  174. ## Update self._stacks_valid according to _checkStacksForErrors and emit if change.
  175. def _updateStacksHaveErrors(self) -> None:
  176. old_stacks_have_errors = self._stacks_have_errors
  177. self._stacks_have_errors = self._checkStacksHaveErrors()
  178. if old_stacks_have_errors != self._stacks_have_errors:
  179. self.stacksValidationChanged.emit()
  180. Application.getInstance().stacksValidationFinished.emit()
  181. def _onActiveExtruderStackChanged(self) -> None:
  182. self.blurSettings.emit() # Ensure no-one has focus.
  183. old_active_container_stack = self._active_container_stack
  184. self._active_container_stack = ExtruderManager.getInstance().getActiveExtruderStack()
  185. if old_active_container_stack != self._active_container_stack:
  186. # Many methods and properties related to the active quality actually depend
  187. # on _active_container_stack. If it changes, then the properties change.
  188. self.activeQualityChanged.emit()
  189. def __emitChangedSignals(self) -> None:
  190. self.activeQualityChanged.emit()
  191. self.activeVariantChanged.emit()
  192. self.activeMaterialChanged.emit()
  193. self.rootMaterialChanged.emit()
  194. self._error_check_timer.start()
  195. def _onInstanceContainersChanged(self, container) -> None:
  196. self._instance_container_timer.start()
  197. def _onPropertyChanged(self, key: str, property_name: str) -> None:
  198. if property_name == "value":
  199. # Notify UI items, such as the "changed" star in profile pull down menu.
  200. self.activeStackValueChanged.emit()
  201. elif property_name == "validationState":
  202. self._error_check_timer.start()
  203. ## Given a global_stack, make sure that it's all valid by searching for this quality group and applying it again
  204. def _initMachineState(self, global_stack):
  205. material_dict = {}
  206. for position, extruder in global_stack.extruders.items():
  207. material_dict[position] = extruder.material.getMetaDataEntry("base_file")
  208. self._current_root_material_id = material_dict
  209. global_quality = global_stack.quality
  210. quality_type = global_quality.getMetaDataEntry("quality_type")
  211. global_quality_changes = global_stack.qualityChanges
  212. global_quality_changes_name = global_quality_changes.getName()
  213. if global_quality_changes.getId() != "empty_quality_changes":
  214. quality_changes_groups = self._application._quality_manager.getQualityChangesGroups(global_stack)
  215. if global_quality_changes_name in quality_changes_groups:
  216. new_quality_changes_group = quality_changes_groups[global_quality_changes_name]
  217. self._setQualityChangesGroup(new_quality_changes_group)
  218. else:
  219. quality_groups = self._application._quality_manager.getQualityGroups(global_stack)
  220. if quality_type not in quality_groups:
  221. Logger.log("w", "Quality type [%s] not found in available qualities [%s]", quality_type, str(quality_groups.values()))
  222. self._setEmptyQuality()
  223. return
  224. new_quality_group = quality_groups[quality_type]
  225. self._setQualityGroup(new_quality_group, empty_quality_changes = True)
  226. @pyqtSlot(str)
  227. def setActiveMachine(self, stack_id: str) -> None:
  228. self.blurSettings.emit() # Ensure no-one has focus.
  229. container_registry = ContainerRegistry.getInstance()
  230. containers = container_registry.findContainerStacks(id = stack_id)
  231. if containers:
  232. global_stack = containers[0]
  233. ExtruderManager.getInstance().setActiveExtruderIndex(0) # Switch to first extruder
  234. Application.getInstance().setGlobalContainerStack(global_stack)
  235. self._global_container_stack = global_stack
  236. Application.getInstance().setGlobalContainerStack(global_stack)
  237. ExtruderManager.getInstance()._globalContainerStackChanged()
  238. self._initMachineState(containers[0])
  239. self.globalContainerChanged.emit()
  240. self._onGlobalContainerChanged()
  241. self.__emitChangedSignals()
  242. @pyqtSlot(str, str)
  243. def addMachine(self, name: str, definition_id: str) -> None:
  244. new_stack = CuraStackBuilder.createMachine(name, definition_id)
  245. if new_stack:
  246. # Instead of setting the global container stack here, we set the active machine and so the signals are emitted
  247. self.setActiveMachine(new_stack.getId())
  248. else:
  249. Logger.log("w", "Failed creating a new machine!")
  250. def _checkStacksHaveErrors(self) -> bool:
  251. time_start = time.time()
  252. if self._global_container_stack is None: #No active machine.
  253. return False
  254. if self._global_container_stack.hasErrors():
  255. Logger.log("d", "Checking global stack for errors took %0.2f s and we found and error" % (time.time() - time_start))
  256. return True
  257. # Not a very pretty solution, but the extruder manager doesn't really know how many extruders there are
  258. machine_extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value")
  259. extruder_stacks = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  260. count = 1 # we start with the global stack
  261. for stack in extruder_stacks:
  262. md = stack.getMetaData()
  263. if "position" in md and int(md["position"]) >= machine_extruder_count:
  264. continue
  265. count += 1
  266. if stack.hasErrors():
  267. Logger.log("d", "Checking %s stacks for errors took %.2f s and we found an error in stack [%s]" % (count, time.time() - time_start, str(stack)))
  268. return True
  269. Logger.log("d", "Checking %s stacks for errors took %.2f s" % (count, time.time() - time_start))
  270. return False
  271. ## Check if the global_container has instances in the user container
  272. @pyqtProperty(bool, notify = activeStackValueChanged)
  273. def hasUserSettings(self) -> bool:
  274. if not self._global_container_stack:
  275. return False
  276. if self._global_container_stack.getTop().findInstances():
  277. return True
  278. stacks = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  279. for stack in stacks:
  280. if stack.getTop().findInstances():
  281. return True
  282. return False
  283. @pyqtProperty(int, notify = activeStackValueChanged)
  284. def numUserSettings(self) -> int:
  285. if not self._global_container_stack:
  286. return 0
  287. num_user_settings = 0
  288. num_user_settings += len(self._global_container_stack.getTop().findInstances())
  289. stacks = list(ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId()))
  290. for stack in stacks:
  291. num_user_settings += len(stack.getTop().findInstances())
  292. return num_user_settings
  293. ## Delete a user setting from the global stack and all extruder stacks.
  294. # \param key \type{str} the name of the key to delete
  295. @pyqtSlot(str)
  296. def clearUserSettingAllCurrentStacks(self, key: str) -> None:
  297. if not self._global_container_stack:
  298. return
  299. send_emits_containers = []
  300. top_container = self._global_container_stack.getTop()
  301. top_container.removeInstance(key, postpone_emit=True)
  302. send_emits_containers.append(top_container)
  303. linked = not self._global_container_stack.getProperty(key, "settable_per_extruder") or \
  304. self._global_container_stack.getProperty(key, "limit_to_extruder") != "-1"
  305. if not linked:
  306. stack = ExtruderManager.getInstance().getActiveExtruderStack()
  307. stacks = [stack]
  308. else:
  309. stacks = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  310. for stack in stacks:
  311. if stack is not None:
  312. container = stack.getTop()
  313. container.removeInstance(key, postpone_emit=True)
  314. send_emits_containers.append(container)
  315. for container in send_emits_containers:
  316. container.sendPostponedEmits()
  317. ## Check if none of the stacks contain error states
  318. # Note that the _stacks_have_errors is cached due to performance issues
  319. # Calling _checkStack(s)ForErrors on every change is simply too expensive
  320. @pyqtProperty(bool, notify = stacksValidationChanged)
  321. def stacksHaveErrors(self) -> bool:
  322. return bool(self._stacks_have_errors)
  323. @pyqtProperty(str, notify = globalContainerChanged)
  324. def activeMachineName(self) -> str:
  325. if self._global_container_stack:
  326. return self._global_container_stack.getName()
  327. return ""
  328. @pyqtProperty(str, notify = globalContainerChanged)
  329. def activeMachineId(self) -> str:
  330. if self._global_container_stack:
  331. return self._global_container_stack.getId()
  332. return ""
  333. @pyqtProperty(QObject, notify = globalContainerChanged)
  334. def activeMachine(self) -> Optional["GlobalStack"]:
  335. return self._global_container_stack
  336. @pyqtProperty(str, notify = activeStackChanged)
  337. def activeStackId(self) -> str:
  338. if self._active_container_stack:
  339. return self._active_container_stack.getId()
  340. return ""
  341. @pyqtProperty(QObject, notify = activeStackChanged)
  342. def activeStack(self) -> Optional["ExtruderStack"]:
  343. return self._active_container_stack
  344. @pyqtProperty(str, notify=activeMaterialChanged)
  345. def activeMaterialId(self) -> str:
  346. if self._active_container_stack:
  347. material = self._active_container_stack.material
  348. if material:
  349. return material.getId()
  350. return ""
  351. ## Gets a dict with the active materials ids set in all extruder stacks and the global stack
  352. # (when there is one extruder, the material is set in the global stack)
  353. #
  354. # \return The material ids in all stacks
  355. @pyqtProperty("QVariantMap", notify = activeMaterialChanged)
  356. def allActiveMaterialIds(self) -> Dict[str, str]:
  357. result = {}
  358. active_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
  359. if active_stacks is not None: # If we have extruder stacks
  360. for stack in active_stacks:
  361. material_container = stack.material
  362. if not material_container:
  363. continue
  364. result[stack.getId()] = material_container.getId()
  365. return result
  366. ## Gets the layer height of the currently active quality profile.
  367. #
  368. # This is indicated together with the name of the active quality profile.
  369. #
  370. # \return The layer height of the currently active quality profile. If
  371. # there is no quality profile, this returns 0.
  372. @pyqtProperty(float, notify = activeQualityGroupChanged)
  373. def activeQualityLayerHeight(self) -> float:
  374. if not self._global_container_stack:
  375. return 0
  376. if self._current_quality_changes_group:
  377. value = self._global_container_stack.getRawProperty("layer_height", "value", skip_until_container = self._global_container_stack.qualityChanges.getId())
  378. if isinstance(value, SettingFunction):
  379. value = value(self._global_container_stack)
  380. return value
  381. elif self._current_quality_group:
  382. value = self._global_container_stack.getRawProperty("layer_height", "value", skip_until_container = self._global_container_stack.quality.getId())
  383. if isinstance(value, SettingFunction):
  384. value = value(self._global_container_stack)
  385. return value
  386. return 0
  387. @pyqtProperty(str, notify = activeVariantChanged)
  388. def globalVariantName(self) -> str:
  389. if self._global_container_stack:
  390. variant = self._global_container_stack.variant
  391. if variant and not isinstance(variant, type(self._empty_variant_container)):
  392. return variant.getName()
  393. return ""
  394. @pyqtProperty(str, notify = activeQualityGroupChanged)
  395. def activeQualityType(self) -> str:
  396. quality_type = ""
  397. if self._active_container_stack:
  398. if self._current_quality_group:
  399. quality_type = self._current_quality_group.quality_type
  400. return quality_type
  401. @pyqtProperty(bool, notify = activeQualityGroupChanged)
  402. def isActiveQualitySupported(self) -> bool:
  403. is_supported = False
  404. if self._global_container_stack:
  405. if self._current_quality_group:
  406. is_supported = self._current_quality_group.is_available
  407. return is_supported
  408. ## Returns whether there is anything unsupported in the current set-up.
  409. #
  410. # The current set-up signifies the global stack and all extruder stacks,
  411. # so this indicates whether there is any container in any of the container
  412. # stacks that is not marked as supported.
  413. @pyqtProperty(bool, notify = activeQualityChanged)
  414. def isCurrentSetupSupported(self) -> bool:
  415. if not self._global_container_stack:
  416. return False
  417. for stack in [self._global_container_stack] + list(self._global_container_stack.extruders.values()):
  418. for container in stack.getContainers():
  419. if not container:
  420. return False
  421. if not Util.parseBool(container.getMetaDataEntry("supported", True)):
  422. return False
  423. return True
  424. ## Check if a container is read_only
  425. @pyqtSlot(str, result = bool)
  426. def isReadOnly(self, container_id: str) -> bool:
  427. return ContainerRegistry.getInstance().isReadOnly(container_id)
  428. ## Copy the value of the setting of the current extruder to all other extruders as well as the global container.
  429. @pyqtSlot(str)
  430. def copyValueToExtruders(self, key: str):
  431. new_value = self._active_container_stack.getProperty(key, "value")
  432. extruder_stacks = [stack for stack in ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())]
  433. # check in which stack the value has to be replaced
  434. for extruder_stack in extruder_stacks:
  435. if extruder_stack != self._active_container_stack and extruder_stack.getProperty(key, "value") != new_value:
  436. extruder_stack.userChanges.setProperty(key, "value", new_value) # TODO: nested property access, should be improved
  437. @pyqtProperty(str, notify = activeVariantChanged)
  438. def activeVariantName(self) -> str:
  439. if self._active_container_stack:
  440. variant = self._active_container_stack.variant
  441. if variant:
  442. return variant.getName()
  443. return ""
  444. @pyqtProperty(str, notify = activeVariantChanged)
  445. def activeVariantBuildplateName(self) -> str:
  446. if self._global_container_stack:
  447. variant = self._global_container_stack.variant
  448. if variant:
  449. return variant.getName()
  450. return ""
  451. @pyqtProperty(str, notify = globalContainerChanged)
  452. def activeDefinitionId(self) -> str:
  453. if self._global_container_stack:
  454. return self._global_container_stack.definition.id
  455. return ""
  456. ## Get the Definition ID to use to select quality profiles for the currently active machine
  457. # \returns DefinitionID (string) if found, empty string otherwise
  458. @pyqtProperty(str, notify = globalContainerChanged)
  459. def activeQualityDefinitionId(self) -> str:
  460. if self._global_container_stack:
  461. return getMachineDefinitionIDForQualitySearch(self._global_container_stack)
  462. return ""
  463. ## Gets how the active definition calls variants
  464. # Caveat: per-definition-variant-title is currently not translated (though the fallback is)
  465. @pyqtProperty(str, notify = globalContainerChanged)
  466. def activeDefinitionVariantsName(self) -> str:
  467. fallback_title = catalog.i18nc("@label", "Nozzle")
  468. if self._global_container_stack:
  469. return self._global_container_stack.definition.getMetaDataEntry("variants_name", fallback_title)
  470. return fallback_title
  471. @pyqtSlot(str, str)
  472. def renameMachine(self, machine_id: str, new_name: str):
  473. container_registry = ContainerRegistry.getInstance()
  474. machine_stack = container_registry.findContainerStacks(id = machine_id)
  475. if machine_stack:
  476. new_name = container_registry.createUniqueName("machine", machine_stack[0].getName(), new_name, machine_stack[0].definition.getName())
  477. machine_stack[0].setName(new_name)
  478. self.globalContainerChanged.emit()
  479. @pyqtSlot(str)
  480. def removeMachine(self, machine_id: str):
  481. # If the machine that is being removed is the currently active machine, set another machine as the active machine.
  482. activate_new_machine = (self._global_container_stack and self._global_container_stack.getId() == machine_id)
  483. # activate a new machine before removing a machine because this is safer
  484. if activate_new_machine:
  485. machine_stacks = ContainerRegistry.getInstance().findContainerStacksMetadata(type = "machine")
  486. other_machine_stacks = [s for s in machine_stacks if s["id"] != machine_id]
  487. if other_machine_stacks:
  488. self.setActiveMachine(other_machine_stacks[0]["id"])
  489. ExtruderManager.getInstance().removeMachineExtruders(machine_id)
  490. containers = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "user", machine = machine_id)
  491. for container in containers:
  492. ContainerRegistry.getInstance().removeContainer(container["id"])
  493. ContainerRegistry.getInstance().removeContainer(machine_id)
  494. @pyqtProperty(bool, notify = globalContainerChanged)
  495. def hasMaterials(self) -> bool:
  496. if self._global_container_stack:
  497. return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_materials", False))
  498. return False
  499. @pyqtProperty(bool, notify = globalContainerChanged)
  500. def hasVariants(self) -> bool:
  501. if self._global_container_stack:
  502. return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_variants", False))
  503. return False
  504. @pyqtProperty(bool, notify = globalContainerChanged)
  505. def hasVariantBuildplates(self) -> bool:
  506. if self._global_container_stack:
  507. return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_variant_buildplates", False))
  508. return False
  509. ## The selected buildplate is compatible if it is compatible with all the materials in all the extruders
  510. @pyqtProperty(bool, notify = activeMaterialChanged)
  511. def variantBuildplateCompatible(self) -> bool:
  512. if not self._global_container_stack:
  513. return True
  514. buildplate_compatible = True # It is compatible by default
  515. extruder_stacks = self._global_container_stack.extruders.values()
  516. for stack in extruder_stacks:
  517. material_container = stack.material
  518. if material_container == self._empty_material_container:
  519. continue
  520. if material_container.getMetaDataEntry("buildplate_compatible"):
  521. buildplate_compatible = buildplate_compatible and material_container.getMetaDataEntry("buildplate_compatible")[self.activeVariantBuildplateName]
  522. return buildplate_compatible
  523. ## The selected buildplate is usable if it is usable for all materials OR it is compatible for one but not compatible
  524. # for the other material but the buildplate is still usable
  525. @pyqtProperty(bool, notify = activeMaterialChanged)
  526. def variantBuildplateUsable(self) -> bool:
  527. if not self._global_container_stack:
  528. return True
  529. # Here the next formula is being calculated:
  530. # result = (not (material_left_compatible and material_right_compatible)) and
  531. # (material_left_compatible or material_left_usable) and
  532. # (material_right_compatible or material_right_usable)
  533. result = not self.variantBuildplateCompatible
  534. extruder_stacks = self._global_container_stack.extruders.values()
  535. for stack in extruder_stacks:
  536. material_container = stack.material
  537. if material_container == self._empty_material_container:
  538. continue
  539. buildplate_compatible = material_container.getMetaDataEntry("buildplate_compatible")[self.activeVariantBuildplateName] if material_container.getMetaDataEntry("buildplate_compatible") else True
  540. buildplate_usable = material_container.getMetaDataEntry("buildplate_recommended")[self.activeVariantBuildplateName] if material_container.getMetaDataEntry("buildplate_recommended") else True
  541. result = result and (buildplate_compatible or buildplate_usable)
  542. return result
  543. ## Property to indicate if a machine has "specialized" material profiles.
  544. # Some machines have their own material profiles that "override" the default catch all profiles.
  545. @pyqtProperty(bool, notify = globalContainerChanged)
  546. def filterMaterialsByMachine(self) -> bool:
  547. if self._global_container_stack:
  548. return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_machine_materials", False))
  549. return False
  550. ## Property to indicate if a machine has "specialized" quality profiles.
  551. # Some machines have their own quality profiles that "override" the default catch all profiles.
  552. @pyqtProperty(bool, notify = globalContainerChanged)
  553. def filterQualityByMachine(self) -> bool:
  554. if self._global_container_stack:
  555. return Util.parseBool(self._global_container_stack.getMetaDataEntry("has_machine_quality", False))
  556. return False
  557. ## Get the Definition ID of a machine (specified by ID)
  558. # \param machine_id string machine id to get the definition ID of
  559. # \returns DefinitionID (string) if found, None otherwise
  560. @pyqtSlot(str, result = str)
  561. def getDefinitionByMachineId(self, machine_id: str) -> str:
  562. containers = ContainerRegistry.getInstance().findContainerStacks(id = machine_id)
  563. if containers:
  564. return containers[0].definition.getId()
  565. ## Update extruder number to a valid value when the number of extruders are changed, or when an extruder is changed
  566. def correctExtruderSettings(self):
  567. extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value")
  568. # reset all extruder number settings whose value is no longer valid
  569. for setting_instance in self._global_container_stack.userChanges.findInstances():
  570. setting_key = setting_instance.definition.key
  571. if not self._global_container_stack.getProperty(setting_key, "type") in ("extruder", "optional_extruder"):
  572. continue
  573. old_value = self._global_container_stack.userChanges.getProperty(setting_key, "value")
  574. if int(old_value) >= extruder_count:
  575. self._global_container_stack.userChanges.removeInstance(setting_key)
  576. Logger.log("d", "Reset [%s] because its old value [%s] is no longer valid", setting_key, old_value)
  577. if not self._global_container_stack.extruders[str(old_value)].isEnabled:
  578. self._global_container_stack.userChanges.removeInstance(setting_key)
  579. Logger.log("d", "Reset [%s] because its old value [%s] is no longer valid (2)", setting_key, old_value)
  580. ## Set the amount of extruders on the active machine (global stack)
  581. # \param extruder_count int the number of extruders to set
  582. def setActiveMachineExtruderCount(self, extruder_count):
  583. extruder_manager = Application.getInstance().getExtruderManager()
  584. definition_changes_container = self._global_container_stack.definitionChanges
  585. if not self._global_container_stack or definition_changes_container == self._empty_definition_changes_container:
  586. return
  587. previous_extruder_count = self._global_container_stack.getProperty("machine_extruder_count", "value")
  588. if extruder_count == previous_extruder_count:
  589. return
  590. definition_changes_container.setProperty("machine_extruder_count", "value", extruder_count)
  591. self.updateDefaultExtruder()
  592. self.correctExtruderSettings()
  593. # Check to see if any objects are set to print with an extruder that will no longer exist
  594. root_node = Application.getInstance().getController().getScene().getRoot()
  595. for node in DepthFirstIterator(root_node):
  596. if node.getMeshData():
  597. extruder_nr = node.callDecoration("getActiveExtruderPosition")
  598. if extruder_nr is not None and int(extruder_nr) > extruder_count - 1:
  599. node.callDecoration("setActiveExtruder", extruder_manager.getExtruderStack(extruder_count - 1).getId())
  600. # Make sure one of the extruder stacks is active
  601. extruder_manager.setActiveExtruderIndex(0)
  602. # Move settable_per_extruder values out of the global container
  603. # After CURA-4482 this should not be the case anymore, but we still want to support older project files.
  604. global_user_container = self._global_container_stack.getTop()
  605. # Make sure extruder_stacks exists
  606. extruder_stacks = []
  607. if previous_extruder_count == 1:
  608. extruder_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
  609. global_user_container = self._global_container_stack.getTop()
  610. for setting_instance in global_user_container.findInstances():
  611. setting_key = setting_instance.definition.key
  612. settable_per_extruder = self._global_container_stack.getProperty(setting_key, "settable_per_extruder")
  613. if settable_per_extruder:
  614. limit_to_extruder = int(self._global_container_stack.getProperty(setting_key, "limit_to_extruder"))
  615. extruder_stack = extruder_stacks[max(0, limit_to_extruder)]
  616. extruder_stack.getTop().setProperty(setting_key, "value", global_user_container.getProperty(setting_key, "value"))
  617. global_user_container.removeInstance(setting_key)
  618. # Signal that the global stack has changed
  619. Application.getInstance().globalContainerStackChanged.emit()
  620. @pyqtSlot(int, result = QObject)
  621. def getExtruder(self, position: int):
  622. extruder = None
  623. if self._global_container_stack:
  624. extruder = self._global_container_stack.extruders.get(str(position))
  625. return extruder
  626. def updateDefaultExtruder(self):
  627. extruder_items = sorted(self._global_container_stack.extruders.items())
  628. new_default_position = "0"
  629. for position, extruder in extruder_items:
  630. if extruder.isEnabled:
  631. new_default_position = position
  632. break
  633. self._default_extruder_position = new_default_position
  634. @pyqtProperty(str, notify = extruderChanged)
  635. def defaultExtruderPosition(self):
  636. return self._default_extruder_position
  637. @pyqtSlot(int, bool)
  638. def setExtruderEnabled(self, position: int, enabled) -> None:
  639. extruder = self.getExtruder(position)
  640. extruder.setEnabled(enabled)
  641. self.updateDefaultExtruder()
  642. if enabled == False:
  643. self.correctExtruderSettings()
  644. self.extruderChanged.emit()
  645. # HACK to update items in SettingExtruder
  646. ExtruderManager.getInstance().extrudersChanged.emit(self._global_container_stack.getId())
  647. def _onMachineNameChanged(self):
  648. self.globalContainerChanged.emit()
  649. def _onMaterialNameChanged(self):
  650. self.activeMaterialChanged.emit()
  651. def _onQualityNameChanged(self):
  652. self.activeQualityChanged.emit()
  653. def _getContainerChangedSignals(self) -> List[Signal]:
  654. stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
  655. stacks.append(self._global_container_stack)
  656. return [ s.containersChanged for s in stacks ]
  657. @pyqtSlot(str, str, str)
  658. def setSettingForAllExtruders(self, setting_name: str, property_name: str, property_value: str):
  659. for key, extruder in self._global_container_stack.extruders.items():
  660. container = extruder.userChanges
  661. container.setProperty(setting_name, property_name, property_value)
  662. #
  663. # New
  664. #
  665. # We not fetch it from _current_root_material_id, but later we can get it from somewhere else
  666. @pyqtProperty("QVariantList", notify = rootMaterialChanged)
  667. def currentExtruderPositions(self):
  668. return sorted(list(self._current_root_material_id.keys()))
  669. @pyqtProperty("QVariant", notify = rootMaterialChanged)
  670. def currentRootMaterialId(self):
  671. # initial filling the current_root_material_id
  672. self._current_root_material_id = {}
  673. for position in self._global_container_stack.extruders:
  674. self._current_root_material_id[position] = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file")
  675. return self._current_root_material_id
  676. @pyqtProperty("QVariant", notify = rootMaterialChanged)
  677. def currentRootMaterialName(self):
  678. # initial filling the current_root_material_name
  679. if self._global_container_stack:
  680. self._current_root_material_name = {}
  681. for position in self._global_container_stack.extruders:
  682. if position not in self._current_root_material_name:
  683. material = self._global_container_stack.extruders[position].material
  684. self._current_root_material_name[position] = material.getName()
  685. return self._current_root_material_name
  686. ## Return the variant names in the extruder stack(s).
  687. ## For the variant in the global stack, use activeVariantBuildplateName
  688. @pyqtProperty("QVariant", notify = activeVariantChanged)
  689. def activeVariantNames(self):
  690. result = {}
  691. active_stacks = ExtruderManager.getInstance().getActiveExtruderStacks()
  692. if active_stacks is not None:
  693. for stack in active_stacks:
  694. variant_container = stack.variant
  695. position = stack.getMetaDataEntry("position")
  696. if variant_container and variant_container != self._empty_variant_container:
  697. result[position] = variant_container.getName()
  698. return result
  699. def _setEmptyQuality(self):
  700. self._current_quality_group = None
  701. self._current_quality_changes_group = None
  702. self._global_container_stack.quality = self._empty_quality_container
  703. self._global_container_stack.qualityChanges = self._empty_quality_changes_container
  704. for extruder in self._global_container_stack.extruders.values():
  705. extruder.quality = self._empty_quality_container
  706. extruder.qualityChanges = self._empty_quality_changes_container
  707. self.activeQualityGroupChanged.emit()
  708. self.activeQualityChangesGroupChanged.emit()
  709. def _setQualityGroup(self, quality_group, empty_quality_changes = True):
  710. self._current_quality_group = quality_group
  711. if empty_quality_changes:
  712. self._current_quality_changes_group = None
  713. # Set quality and quality_changes for the GlobalStack
  714. self._global_container_stack.quality = quality_group.node_for_global.getContainer()
  715. if empty_quality_changes:
  716. self._global_container_stack.qualityChanges = self._empty_quality_changes_container
  717. # Set quality and quality_changes for each ExtruderStack
  718. for position, node in quality_group.nodes_for_extruders.items():
  719. self._global_container_stack.extruders[position].quality = node.getContainer()
  720. if empty_quality_changes:
  721. self._global_container_stack.extruders[position].qualityChanges = self._empty_quality_changes_container
  722. self.activeQualityGroupChanged.emit()
  723. self.activeQualityChangesGroupChanged.emit()
  724. def _setQualityChangesGroup(self, quality_changes_group):
  725. # TODO: quality_changes groups depend on a quality_type. Here it's fetching the quality_types every time.
  726. # Can we do this better, like caching the quality group a quality_changes group depends on?
  727. quality_type = quality_changes_group.quality_type
  728. quality_manager = Application.getInstance()._quality_manager
  729. quality_group_dict = quality_manager.getQualityGroups(self._global_container_stack)
  730. quality_group = quality_group_dict[quality_type]
  731. quality_changes_container = self._empty_quality_changes_container
  732. quality_container = self._empty_quality_changes_container
  733. if quality_changes_group.node_for_global:
  734. quality_changes_container = quality_changes_group.node_for_global.getContainer()
  735. if quality_group.node_for_global:
  736. quality_container = quality_group.node_for_global.getContainer()
  737. self._global_container_stack.quality = quality_container
  738. self._global_container_stack.qualityChanges = quality_changes_container
  739. for position, extruder in self._global_container_stack.extruders.items():
  740. quality_changes_node = quality_changes_group.nodes_for_extruders.get(position)
  741. quality_node = quality_group.nodes_for_extruders.get(position)
  742. quality_changes_container = self._empty_quality_changes_container
  743. quality_container = self._empty_quality_changes_container
  744. if quality_changes_node:
  745. quality_changes_container = quality_changes_node.getContainer()
  746. if quality_node:
  747. quality_container = quality_node.getContainer()
  748. extruder.quality = quality_container
  749. extruder.qualityChanges = quality_changes_container
  750. self._current_quality_group = quality_group
  751. self._current_quality_changes_group = quality_changes_group
  752. self.activeQualityGroupChanged.emit()
  753. self.activeQualityChangesGroupChanged.emit()
  754. def _setVariantNode(self, position, container_node):
  755. self._global_container_stack.extruders[position].variant = container_node.getContainer()
  756. self.activeVariantChanged.emit()
  757. def _setGlobalVariant(self, container_node):
  758. self._global_container_stack.variant = container_node.getContainer()
  759. def _setMaterial(self, position, container_node = None):
  760. if container_node:
  761. self._global_container_stack.extruders[position].material = container_node.getContainer()
  762. else:
  763. self._global_container_stack.extruders[position].material = self._empty_material_container
  764. # The _current_root_material_id is used in the MaterialMenu to see which material is selected
  765. root_material_id = container_node.metadata["base_file"]
  766. root_material_name = container_node.getContainer().getName()
  767. if root_material_id != self._current_root_material_id[position]:
  768. self._current_root_material_id[position] = root_material_id
  769. self._current_root_material_name[position] = root_material_name
  770. self.rootMaterialChanged.emit()
  771. def activeMaterialsCompatible(self):
  772. # check material - variant compatibility
  773. if Util.parseBool(self._global_container_stack.getMetaDataEntry("has_materials", False)):
  774. for position, extruder in self._global_container_stack.extruders.items():
  775. if not extruder.material.getMetaDataEntry("compatible"):
  776. return False
  777. return True
  778. ## Update current quality type and machine after setting material
  779. def _updateQualityWithMaterial(self):
  780. current_quality = None
  781. if self._current_quality_group:
  782. current_quality = self._current_quality_group.quality_type
  783. quality_manager = Application.getInstance()._quality_manager
  784. candidate_quality_groups = quality_manager.getQualityGroups(self._global_container_stack)
  785. available_quality_types = {qt for qt, g in candidate_quality_groups.items() if g.is_available}
  786. if not self.activeMaterialsCompatible():
  787. self._setEmptyQuality()
  788. return
  789. if not available_quality_types:
  790. self._setEmptyQuality()
  791. return
  792. if current_quality in available_quality_types:
  793. self._setQualityGroup(candidate_quality_groups[current_quality], empty_quality_changes = False)
  794. return
  795. quality_type = sorted(list(available_quality_types))[0]
  796. preferred_quality_type = self._global_container_stack.getMetaDataEntry("preferred_quality_type")
  797. if preferred_quality_type in available_quality_types:
  798. quality_type = preferred_quality_type
  799. self._setQualityGroup(candidate_quality_groups[quality_type], empty_quality_changes = True)
  800. def _updateMaterialWithVariant(self, position: Optional[str]):
  801. if position is None:
  802. position_list = list(self._global_container_stack.extruders.keys())
  803. else:
  804. position_list = [position]
  805. for position in position_list:
  806. extruder = self._global_container_stack.extruders[position]
  807. current_material_base_name = extruder.material.getMetaDataEntry("base_file")
  808. current_variant_name = extruder.variant.getMetaDataEntry("name")
  809. material_manager = Application.getInstance()._material_manager
  810. material_diameter = self._global_container_stack.getProperty("material_diameter", "value")
  811. candidate_materials = material_manager.getAvailableMaterials(
  812. self._global_container_stack.definition.getId(),
  813. current_variant_name,
  814. material_diameter)
  815. if not candidate_materials:
  816. self._setMaterial(position, container_node = None)
  817. continue
  818. if current_material_base_name in candidate_materials:
  819. new_material = candidate_materials[current_material_base_name]
  820. self._setMaterial(position, new_material)
  821. continue
  822. # # Find a fallback material
  823. # preferred_material_query = self._global_container_stack.getMetaDataEntry("preferred_material")
  824. # preferred_material_key = preferred_material_query.replace("*", "")
  825. # if preferred_material_key in candidate_materials:
  826. # self._setMaterial(position, candidate_materials[preferred_material_key])
  827. # return
  828. @pyqtSlot("QVariant")
  829. def setGlobalVariant(self, container_node):
  830. self.blurSettings.emit()
  831. with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
  832. self._setGlobalVariant(container_node)
  833. self._updateMaterialWithVariant(None) # Update all materials
  834. self._updateQualityWithMaterial()
  835. @pyqtSlot(str, "QVariant")
  836. def setMaterial(self, position, container_node):
  837. position = str(position)
  838. self.blurSettings.emit()
  839. with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
  840. self._setMaterial(position, container_node)
  841. self._updateQualityWithMaterial()
  842. @pyqtSlot(str, "QVariant")
  843. def setVariantGroup(self, position, container_node):
  844. position = str(position)
  845. self.blurSettings.emit()
  846. with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
  847. self._setVariantNode(position, container_node)
  848. self._updateMaterialWithVariant(position)
  849. self._updateQualityWithMaterial()
  850. @pyqtSlot(QObject)
  851. def setQualityGroup(self, quality_group):
  852. self.blurSettings.emit()
  853. with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
  854. self._setQualityGroup(quality_group)
  855. # See if we need to show the Discard or Keep changes screen
  856. if self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
  857. Application.getInstance().discardOrKeepProfileChanges()
  858. @pyqtProperty(QObject, fset = setQualityGroup, notify = activeQualityGroupChanged)
  859. def activeQualityGroup(self):
  860. return self._current_quality_group
  861. @pyqtSlot(QObject)
  862. def setQualityChangesGroup(self, quality_changes_group):
  863. self.blurSettings.emit()
  864. with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
  865. self._setQualityChangesGroup(quality_changes_group)
  866. # See if we need to show the Discard or Keep changes screen
  867. if self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
  868. Application.getInstance().discardOrKeepProfileChanges()
  869. @pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
  870. def activeQualityChangesGroup(self):
  871. return self._current_quality_changes_group
  872. @pyqtProperty(str, notify = activeQualityGroupChanged)
  873. def activeQualityOrQualityChangesName(self):
  874. name = self._empty_quality_container.getName()
  875. if self._current_quality_changes_group:
  876. name = self._current_quality_changes_group.name
  877. elif self._current_quality_group:
  878. name = self._current_quality_group.name
  879. return name