QualityManager.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import TYPE_CHECKING, Optional, cast
  4. from PyQt5.QtCore import QObject, QTimer, pyqtSignal, pyqtSlot
  5. from UM.Application import Application
  6. from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
  7. from UM.Logger import Logger
  8. from UM.Util import parseBool
  9. from UM.Settings.InstanceContainer import InstanceContainer
  10. from cura.Settings.ExtruderStack import ExtruderStack
  11. from .QualityGroup import QualityGroup
  12. from .QualityNode import QualityNode
  13. if TYPE_CHECKING:
  14. from UM.Settings.DefinitionContainer import DefinitionContainer
  15. from cura.Settings.GlobalStack import GlobalStack
  16. from .QualityChangesGroup import QualityChangesGroup
  17. #
  18. # Similar to MaterialManager, QualityManager maintains a number of maps and trees for quality profile lookup.
  19. # The models GUI and QML use are now only dependent on the QualityManager. That means as long as the data in
  20. # QualityManager gets updated correctly, the GUI models should be updated correctly too, and the same goes for GUI.
  21. #
  22. # For now, updating the lookup maps and trees here is very simple: we discard the old data completely and recreate them
  23. # again. This means the update is exactly the same as initialization. There are performance concerns about this approach
  24. # but so far the creation of the tables and maps is very fast and there is no noticeable slowness, we keep it like this
  25. # because it's simple.
  26. #
  27. class QualityManager(QObject):
  28. qualitiesUpdated = pyqtSignal()
  29. def __init__(self, container_registry, parent = None):
  30. super().__init__(parent)
  31. self._application = Application.getInstance()
  32. self._material_manager = self._application.getMaterialManager()
  33. self._container_registry = container_registry
  34. self._empty_quality_container = self._application.empty_quality_container
  35. self._empty_quality_changes_container = self._application.empty_quality_changes_container
  36. self._machine_nozzle_buildplate_material_quality_type_to_quality_dict = {} # for quality lookup
  37. self._machine_quality_type_to_quality_changes_dict = {} # for quality_changes lookup
  38. self._default_machine_definition_id = "fdmprinter"
  39. self._container_registry.containerMetaDataChanged.connect(self._onContainerMetadataChanged)
  40. self._container_registry.containerAdded.connect(self._onContainerMetadataChanged)
  41. self._container_registry.containerRemoved.connect(self._onContainerMetadataChanged)
  42. # When a custom quality gets added/imported, there can be more than one InstanceContainers. In those cases,
  43. # we don't want to react on every container/metadata changed signal. The timer here is to buffer it a bit so
  44. # we don't react too many time.
  45. self._update_timer = QTimer(self)
  46. self._update_timer.setInterval(300)
  47. self._update_timer.setSingleShot(True)
  48. self._update_timer.timeout.connect(self._updateMaps)
  49. def initialize(self):
  50. # Initialize the lookup tree for quality profiles with following structure:
  51. # <machine> -> <nozzle> -> <buildplate> -> <material>
  52. # <machine> -> <material>
  53. self._machine_nozzle_buildplate_material_quality_type_to_quality_dict = {} # for quality lookup
  54. self._machine_quality_type_to_quality_changes_dict = {} # for quality_changes lookup
  55. quality_metadata_list = self._container_registry.findContainersMetadata(type = "quality")
  56. for metadata in quality_metadata_list:
  57. if metadata["id"] == "empty_quality":
  58. continue
  59. definition_id = metadata["definition"]
  60. quality_type = metadata["quality_type"]
  61. root_material_id = metadata.get("material")
  62. nozzle_name = metadata.get("variant")
  63. buildplate_name = metadata.get("buildplate")
  64. is_global_quality = metadata.get("global_quality", False)
  65. is_global_quality = is_global_quality or (root_material_id is None and nozzle_name is None and buildplate_name is None)
  66. # Sanity check: material+variant and is_global_quality cannot be present at the same time
  67. if is_global_quality and (root_material_id or nozzle_name):
  68. ConfigurationErrorMessage.getInstance().addFaultyContainers(metadata["id"])
  69. continue
  70. if definition_id not in self._machine_nozzle_buildplate_material_quality_type_to_quality_dict:
  71. self._machine_nozzle_buildplate_material_quality_type_to_quality_dict[definition_id] = QualityNode()
  72. machine_node = cast(QualityNode, self._machine_nozzle_buildplate_material_quality_type_to_quality_dict[definition_id])
  73. if is_global_quality:
  74. # For global qualities, save data in the machine node
  75. machine_node.addQualityMetadata(quality_type, metadata)
  76. continue
  77. current_node = machine_node
  78. intermediate_node_info_list = [nozzle_name, buildplate_name, root_material_id]
  79. current_intermediate_node_info_idx = 0
  80. while current_intermediate_node_info_idx < len(intermediate_node_info_list):
  81. node_name = intermediate_node_info_list[current_intermediate_node_info_idx]
  82. if node_name is not None:
  83. # There is specific information, update the current node to go deeper so we can add this quality
  84. # at the most specific branch in the lookup tree.
  85. if node_name not in current_node.children_map:
  86. current_node.children_map[node_name] = QualityNode()
  87. current_node = cast(QualityNode, current_node.children_map[node_name])
  88. current_intermediate_node_info_idx += 1
  89. current_node.addQualityMetadata(quality_type, metadata)
  90. # Initialize the lookup tree for quality_changes profiles with following structure:
  91. # <machine> -> <quality_type> -> <name>
  92. quality_changes_metadata_list = self._container_registry.findContainersMetadata(type = "quality_changes")
  93. for metadata in quality_changes_metadata_list:
  94. if metadata["id"] == "empty_quality_changes":
  95. continue
  96. machine_definition_id = metadata["definition"]
  97. quality_type = metadata["quality_type"]
  98. if machine_definition_id not in self._machine_quality_type_to_quality_changes_dict:
  99. self._machine_quality_type_to_quality_changes_dict[machine_definition_id] = QualityNode()
  100. machine_node = self._machine_quality_type_to_quality_changes_dict[machine_definition_id]
  101. machine_node.addQualityChangesMetadata(quality_type, metadata)
  102. Logger.log("d", "Lookup tables updated.")
  103. self.qualitiesUpdated.emit()
  104. def _updateMaps(self):
  105. self.initialize()
  106. def _onContainerMetadataChanged(self, container):
  107. self._onContainerChanged(container)
  108. def _onContainerChanged(self, container):
  109. container_type = container.getMetaDataEntry("type")
  110. if container_type not in ("quality", "quality_changes"):
  111. return
  112. # update the cache table
  113. self._update_timer.start()
  114. # Updates the given quality groups' availabilities according to which extruders are being used/ enabled.
  115. def _updateQualityGroupsAvailability(self, machine: "GlobalStack", quality_group_list):
  116. used_extruders = set()
  117. for i in range(machine.getProperty("machine_extruder_count", "value")):
  118. if str(i) in machine.extruders and machine.extruders[str(i)].isEnabled:
  119. used_extruders.add(str(i))
  120. # Update the "is_available" flag for each quality group.
  121. for quality_group in quality_group_list:
  122. is_available = True
  123. if quality_group.node_for_global is None:
  124. is_available = False
  125. if is_available:
  126. for position in used_extruders:
  127. if position not in quality_group.nodes_for_extruders:
  128. is_available = False
  129. break
  130. quality_group.is_available = is_available
  131. # Returns a dict of "custom profile name" -> QualityChangesGroup
  132. def getQualityChangesGroups(self, machine: "GlobalStack") -> dict:
  133. machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
  134. machine_node = self._machine_quality_type_to_quality_changes_dict.get(machine_definition_id)
  135. if not machine_node:
  136. Logger.log("i", "Cannot find node for machine def [%s] in QualityChanges lookup table", machine_definition_id)
  137. return dict()
  138. # Update availability for each QualityChangesGroup:
  139. # A custom profile is always available as long as the quality_type it's based on is available
  140. quality_group_dict = self.getQualityGroups(machine)
  141. available_quality_type_list = [qt for qt, qg in quality_group_dict.items() if qg.is_available]
  142. # Iterate over all quality_types in the machine node
  143. quality_changes_group_dict = dict()
  144. for quality_type, quality_changes_node in machine_node.quality_type_map.items():
  145. for quality_changes_name, quality_changes_group in quality_changes_node.children_map.items():
  146. quality_changes_group_dict[quality_changes_name] = quality_changes_group
  147. quality_changes_group.is_available = quality_type in available_quality_type_list
  148. return quality_changes_group_dict
  149. #
  150. # Gets all quality groups for the given machine. Both available and none available ones will be included.
  151. # It returns a dictionary with "quality_type"s as keys and "QualityGroup"s as values.
  152. # Whether a QualityGroup is available can be unknown via the field QualityGroup.is_available.
  153. # For more details, see QualityGroup.
  154. #
  155. def getQualityGroups(self, machine: "GlobalStack") -> dict:
  156. machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
  157. # This determines if we should only get the global qualities for the global stack and skip the global qualities for the extruder stacks
  158. has_machine_specific_qualities = machine.getHasMachineQuality()
  159. # To find the quality container for the GlobalStack, check in the following fall-back manner:
  160. # (1) the machine-specific node
  161. # (2) the generic node
  162. machine_node = self._machine_nozzle_buildplate_material_quality_type_to_quality_dict.get(machine_definition_id)
  163. # Check if this machine has specific quality profiles for its extruders, if so, when looking up extruder
  164. # qualities, we should not fall back to use the global qualities.
  165. has_extruder_specific_qualities = False
  166. if machine_node:
  167. if machine_node.children_map:
  168. has_extruder_specific_qualities = True
  169. default_machine_node = self._machine_nozzle_buildplate_material_quality_type_to_quality_dict.get(self._default_machine_definition_id)
  170. nodes_to_check = [machine_node, default_machine_node]
  171. # Iterate over all quality_types in the machine node
  172. quality_group_dict = {}
  173. for node in nodes_to_check:
  174. if node and node.quality_type_map:
  175. quality_node = list(node.quality_type_map.values())[0]
  176. is_global_quality = parseBool(quality_node.metadata.get("global_quality", False))
  177. if not is_global_quality:
  178. continue
  179. for quality_type, quality_node in node.quality_type_map.items():
  180. quality_group = QualityGroup(quality_node.metadata["name"], quality_type)
  181. quality_group.node_for_global = quality_node
  182. quality_group_dict[quality_type] = quality_group
  183. break
  184. buildplate_name = machine.getBuildplateName()
  185. # Iterate over all extruders to find quality containers for each extruder
  186. for position, extruder in machine.extruders.items():
  187. nozzle_name = None
  188. if extruder.variant.getId() != "empty_variant":
  189. nozzle_name = extruder.variant.getName()
  190. # This is a list of root material IDs to use for searching for suitable quality profiles.
  191. # The root material IDs in this list are in prioritized order.
  192. root_material_id_list = []
  193. has_material = False # flag indicating whether this extruder has a material assigned
  194. root_material_id = None
  195. if extruder.material.getId() != "empty_material":
  196. has_material = True
  197. root_material_id = extruder.material.getMetaDataEntry("base_file")
  198. # Convert possible generic_pla_175 -> generic_pla
  199. root_material_id = self._material_manager.getRootMaterialIDWithoutDiameter(root_material_id)
  200. root_material_id_list.append(root_material_id)
  201. # Also try to get the fallback material
  202. material_type = extruder.material.getMetaDataEntry("material")
  203. fallback_root_material_id = self._material_manager.getFallbackMaterialIdByMaterialType(material_type)
  204. if fallback_root_material_id:
  205. root_material_id_list.append(fallback_root_material_id)
  206. # Here we construct a list of nodes we want to look for qualities with the highest priority first.
  207. # The use case is that, when we look for qualities for a machine, we first want to search in the following
  208. # order:
  209. # 1. machine-nozzle-buildplate-and-material-specific qualities if exist
  210. # 2. machine-nozzle-and-material-specific qualities if exist
  211. # 3. machine-nozzle-specific qualities if exist
  212. # 4. machine-material-specific qualities if exist
  213. # 5. machine-specific global qualities if exist, otherwise generic global qualities
  214. # NOTE: We DO NOT fail back to generic global qualities if machine-specific global qualities exist.
  215. # This is because when a machine defines its own global qualities such as Normal, Fine, etc.,
  216. # it is intended to maintain those specific qualities ONLY. If we still fail back to the generic
  217. # global qualities, there can be unimplemented quality types e.g. "coarse", and this is not
  218. # correct.
  219. # Each points above can be represented as a node in the lookup tree, so here we simply put those nodes into
  220. # the list with priorities as the order. Later, we just need to loop over each node in this list and fetch
  221. # qualities from there.
  222. node_info_list_0 = [nozzle_name, buildplate_name, root_material_id]
  223. nodes_to_check = []
  224. # This function tries to recursively find the deepest (the most specific) branch and add those nodes to
  225. # the search list in the order described above. So, by iterating over that search node list, we first look
  226. # in the more specific branches and then the less specific (generic) ones.
  227. def addNodesToCheck(node, nodes_to_check_list, node_info_list, node_info_idx):
  228. if node_info_idx < len(node_info_list):
  229. node_name = node_info_list[node_info_idx]
  230. if node_name is not None:
  231. current_node = node.getChildNode(node_name)
  232. if current_node is not None and has_material:
  233. addNodesToCheck(current_node, nodes_to_check_list, node_info_list, node_info_idx + 1)
  234. if has_material:
  235. for rmid in root_material_id_list:
  236. material_node = node.getChildNode(rmid)
  237. if material_node:
  238. nodes_to_check_list.append(material_node)
  239. break
  240. nodes_to_check_list.append(node)
  241. addNodesToCheck(machine_node, nodes_to_check, node_info_list_0, 0)
  242. # The last fall back will be the global qualities (either from the machine-specific node or the generic
  243. # node), but we only use one. For details see the overview comments above.
  244. if machine_node.quality_type_map:
  245. nodes_to_check += [machine_node]
  246. else:
  247. nodes_to_check += [default_machine_node]
  248. for node_idx, node in enumerate(nodes_to_check):
  249. if node and node.quality_type_map:
  250. if has_extruder_specific_qualities:
  251. # Only include variant qualities; skip non global qualities
  252. quality_node = list(node.quality_type_map.values())[0]
  253. is_global_quality = parseBool(quality_node.metadata.get("global_quality", False))
  254. if is_global_quality:
  255. continue
  256. for quality_type, quality_node in node.quality_type_map.items():
  257. if quality_type not in quality_group_dict:
  258. quality_group = QualityGroup(quality_node.metadata["name"], quality_type)
  259. quality_group_dict[quality_type] = quality_group
  260. quality_group = quality_group_dict[quality_type]
  261. if position not in quality_group.nodes_for_extruders:
  262. quality_group.nodes_for_extruders[position] = quality_node
  263. # If the machine has its own specific qualities, for extruders, it should skip the global qualities
  264. # and use the material/variant specific qualities.
  265. if has_extruder_specific_qualities:
  266. if node_idx == len(nodes_to_check) - 1:
  267. break
  268. # Update availabilities for each quality group
  269. self._updateQualityGroupsAvailability(machine, quality_group_dict.values())
  270. return quality_group_dict
  271. def getQualityGroupsForMachineDefinition(self, machine: "GlobalStack") -> dict:
  272. machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
  273. # To find the quality container for the GlobalStack, check in the following fall-back manner:
  274. # (1) the machine-specific node
  275. # (2) the generic node
  276. machine_node = self._machine_nozzle_buildplate_material_quality_type_to_quality_dict.get(machine_definition_id)
  277. default_machine_node = self._machine_nozzle_buildplate_material_quality_type_to_quality_dict.get(
  278. self._default_machine_definition_id)
  279. nodes_to_check = [machine_node, default_machine_node]
  280. # Iterate over all quality_types in the machine node
  281. quality_group_dict = dict()
  282. for node in nodes_to_check:
  283. if node and node.quality_type_map:
  284. for quality_type, quality_node in node.quality_type_map.items():
  285. quality_group = QualityGroup(quality_node.metadata["name"], quality_type)
  286. quality_group.node_for_global = quality_node
  287. quality_group_dict[quality_type] = quality_group
  288. break
  289. return quality_group_dict
  290. def getDefaultQualityType(self, machine: "GlobalStack") -> Optional[QualityGroup]:
  291. preferred_quality_type = machine.definition.getMetaDataEntry("preferred_quality_type")
  292. quality_group_dict = self.getQualityGroups(machine)
  293. quality_group = quality_group_dict.get(preferred_quality_type)
  294. return quality_group
  295. #
  296. # Methods for GUI
  297. #
  298. #
  299. # Remove the given quality changes group.
  300. #
  301. @pyqtSlot(QObject)
  302. def removeQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup"):
  303. Logger.log("i", "Removing quality changes group [%s]", quality_changes_group.name)
  304. removed_quality_changes_ids = set()
  305. for node in quality_changes_group.getAllNodes():
  306. container_id = node.getMetaDataEntry("id")
  307. self._container_registry.removeContainer(container_id)
  308. removed_quality_changes_ids.add(container_id)
  309. # Reset all machines that have activated this quality changes to empty.
  310. for global_stack in self._container_registry.findContainerStacks(type = "machine"):
  311. if global_stack.qualityChanges.getId() in removed_quality_changes_ids:
  312. global_stack.qualityChanges = self._empty_quality_changes_container
  313. for extruder_stack in self._container_registry.findContainerStacks(type = "extruder_train"):
  314. if extruder_stack.qualityChanges.getId() in removed_quality_changes_ids:
  315. extruder_stack.qualityChanges = self._empty_quality_changes_container
  316. #
  317. # Rename a set of quality changes containers. Returns the new name.
  318. #
  319. @pyqtSlot(QObject, str, result = str)
  320. def renameQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup", new_name: str) -> str:
  321. Logger.log("i", "Renaming QualityChangesGroup[%s] to [%s]", quality_changes_group.name, new_name)
  322. if new_name == quality_changes_group.name:
  323. Logger.log("i", "QualityChangesGroup name [%s] unchanged.", quality_changes_group.name)
  324. return new_name
  325. new_name = self._container_registry.uniqueName(new_name)
  326. for node in quality_changes_group.getAllNodes():
  327. container = node.getContainer()
  328. if container:
  329. container.setName(new_name)
  330. quality_changes_group.name = new_name
  331. self._application.getMachineManager().activeQualityChanged.emit()
  332. self._application.getMachineManager().activeQualityGroupChanged.emit()
  333. return new_name
  334. #
  335. # Duplicates the given quality.
  336. #
  337. @pyqtSlot(str, "QVariantMap")
  338. def duplicateQualityChanges(self, quality_changes_name, quality_model_item):
  339. global_stack = self._application.getGlobalContainerStack()
  340. if not global_stack:
  341. Logger.log("i", "No active global stack, cannot duplicate quality changes.")
  342. return
  343. quality_group = quality_model_item["quality_group"]
  344. quality_changes_group = quality_model_item["quality_changes_group"]
  345. if quality_changes_group is None:
  346. # create global quality changes only
  347. new_quality_changes = self._createQualityChanges(quality_group.quality_type, quality_changes_name,
  348. global_stack, None)
  349. self._container_registry.addContainer(new_quality_changes)
  350. else:
  351. new_name = self._container_registry.uniqueName(quality_changes_name)
  352. for node in quality_changes_group.getAllNodes():
  353. container = node.getContainer()
  354. if not container:
  355. continue
  356. new_id = self._container_registry.uniqueName(container.getId())
  357. self._container_registry.addContainer(container.duplicate(new_id, new_name))
  358. ## Create quality changes containers from the user containers in the active stacks.
  359. #
  360. # This will go through the global and extruder stacks and create quality_changes containers from
  361. # the user containers in each stack. These then replace the quality_changes containers in the
  362. # stack and clear the user settings.
  363. @pyqtSlot(str)
  364. def createQualityChanges(self, base_name):
  365. machine_manager = Application.getInstance().getMachineManager()
  366. global_stack = machine_manager.activeMachine
  367. if not global_stack:
  368. return
  369. active_quality_name = machine_manager.activeQualityOrQualityChangesName
  370. if active_quality_name == "":
  371. Logger.log("w", "No quality container found in stack %s, cannot create profile", global_stack.getId())
  372. return
  373. machine_manager.blurSettings.emit()
  374. if base_name is None or base_name == "":
  375. base_name = active_quality_name
  376. unique_name = self._container_registry.uniqueName(base_name)
  377. # Go through the active stacks and create quality_changes containers from the user containers.
  378. stack_list = [global_stack] + list(global_stack.extruders.values())
  379. for stack in stack_list:
  380. user_container = stack.userChanges
  381. quality_container = stack.quality
  382. quality_changes_container = stack.qualityChanges
  383. if not quality_container or not quality_changes_container:
  384. Logger.log("w", "No quality or quality changes container found in stack %s, ignoring it", stack.getId())
  385. continue
  386. quality_type = quality_container.getMetaDataEntry("quality_type")
  387. extruder_stack = None
  388. if isinstance(stack, ExtruderStack):
  389. extruder_stack = stack
  390. new_changes = self._createQualityChanges(quality_type, unique_name, global_stack, extruder_stack)
  391. from cura.Settings.ContainerManager import ContainerManager
  392. ContainerManager.getInstance()._performMerge(new_changes, quality_changes_container, clear_settings = False)
  393. ContainerManager.getInstance()._performMerge(new_changes, user_container)
  394. self._container_registry.addContainer(new_changes)
  395. #
  396. # Create a quality changes container with the given setup.
  397. #
  398. def _createQualityChanges(self, quality_type: str, new_name: str, machine: "GlobalStack",
  399. extruder_stack: Optional["ExtruderStack"]) -> "InstanceContainer":
  400. base_id = machine.definition.getId() if extruder_stack is None else extruder_stack.getId()
  401. new_id = base_id + "_" + new_name
  402. new_id = new_id.lower().replace(" ", "_")
  403. new_id = self._container_registry.uniqueName(new_id)
  404. # Create a new quality_changes container for the quality.
  405. quality_changes = InstanceContainer(new_id)
  406. quality_changes.setName(new_name)
  407. quality_changes.setMetaDataEntry("type", "quality_changes")
  408. quality_changes.setMetaDataEntry("quality_type", quality_type)
  409. # If we are creating a container for an extruder, ensure we add that to the container
  410. if extruder_stack is not None:
  411. quality_changes.setMetaDataEntry("position", extruder_stack.getMetaDataEntry("position"))
  412. # If the machine specifies qualities should be filtered, ensure we match the current criteria.
  413. machine_definition_id = getMachineDefinitionIDForQualitySearch(machine.definition)
  414. quality_changes.setDefinition(machine_definition_id)
  415. quality_changes.setMetaDataEntry("setting_version", self._application.SettingVersion)
  416. return quality_changes
  417. #
  418. # Gets the machine definition ID that can be used to search for Quality containers that are suitable for the given
  419. # machine. The rule is as follows:
  420. # 1. By default, the machine definition ID for quality container search will be "fdmprinter", which is the generic
  421. # machine.
  422. # 2. If a machine has its own machine quality (with "has_machine_quality = True"), we should use the given machine's
  423. # own machine definition ID for quality search.
  424. # Example: for an Ultimaker 3, the definition ID should be "ultimaker3".
  425. # 3. When condition (2) is met, AND the machine has "quality_definition" defined in its definition file, then the
  426. # definition ID specified in "quality_definition" should be used.
  427. # Example: for an Ultimaker 3 Extended, it has "quality_definition = ultimaker3". This means Ultimaker 3 Extended
  428. # shares the same set of qualities profiles as Ultimaker 3.
  429. #
  430. def getMachineDefinitionIDForQualitySearch(machine_definition: "DefinitionContainer",
  431. default_definition_id: str = "fdmprinter") -> str:
  432. machine_definition_id = default_definition_id
  433. if parseBool(machine_definition.getMetaDataEntry("has_machine_quality", False)):
  434. # Only use the machine's own quality definition ID if this machine has machine quality.
  435. machine_definition_id = machine_definition.getMetaDataEntry("quality_definition")
  436. if machine_definition_id is None:
  437. machine_definition_id = machine_definition.getId()
  438. return machine_definition_id