VersionUpgrade21to22.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. # Copyright (c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. import configparser #To get version numbers from config files.
  4. from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin.
  5. from . import MachineInstance # To upgrade machine instances.
  6. from . import Preferences #To upgrade preferences.
  7. from . import Profile # To upgrade profiles.
  8. ## Which machines have material-specific profiles in the new version?
  9. #
  10. # These are the 2.1 machine identities with "has_machine_materials": true in
  11. # their definitions in Cura 2.2. So these are the machines for which profiles
  12. # need to split into multiple profiles, one for each material and variant.
  13. #
  14. # Each machine has the materials and variants listed in which it needs to
  15. # split, since those might be different per machine.
  16. #
  17. # This should contain the definition as they are stated in the profiles. The
  18. # inheritance structure cannot be found at this stage, since the definitions
  19. # may have changed in later versions than 2.2.
  20. _machines_with_machine_quality = {
  21. "ultimaker2plus": {
  22. "materials": { "generic_abs", "generic_cpe", "generic_pla", "generic_pva", "generic_cpe_plus", "generic_nylon", "generic_pc", "generic_tpu" },
  23. "variants": { "0.25 mm", "0.4 mm", "0.6 mm", "0.8 mm" }
  24. },
  25. "ultimaker2_extended_plus": {
  26. "materials": { "generic_abs", "generic_cpe", "generic_pla", "generic_pva", "generic_cpe_plus", "generic_nylon", "generic_pc", "generic_tpu" },
  27. "variants": { "0.25 mm", "0.4 mm", "0.6 mm", "0.8 mm" }
  28. }
  29. }
  30. ## How to translate material names from the old version to the new.
  31. _material_translations = {
  32. "PLA": "generic_pla",
  33. "ABS": "generic_abs",
  34. "CPE": "generic_cpe",
  35. "CPE+": "generic_cpe_plus",
  36. "Nylon": "generic_nylon",
  37. "PC": "generic_pc",
  38. "TPU": "generic_tpu",
  39. }
  40. ## How to translate material names for in the profile names.
  41. _material_translations_profiles = {
  42. "PLA": "pla",
  43. "ABS": "abs",
  44. "CPE": "cpe",
  45. "CPE+": "cpep",
  46. "Nylon": "nylon",
  47. "PC": "pc",
  48. "TPU": "tpu",
  49. }
  50. ## How to translate printer names from the old version to the new.
  51. _printer_translations = {
  52. "ultimaker2plus": "ultimaker2_plus"
  53. }
  54. _printer_translations_profiles = {
  55. "ultimaker2plus": "um2p", #Does NOT get included in PLA profiles!
  56. "ultimaker2_extended_plus": "um2ep" #Has no profiles for CPE+, Nylon, PC and TPU!
  57. }
  58. ## How to translate profile names from the old version to the new.
  59. #
  60. # This must have an entry for every built-in profile, since it also services
  61. # as a set for which profiles were built-in.
  62. _profile_translations = {
  63. "Low Quality": "low",
  64. "Normal Quality": "normal",
  65. "High Quality": "high",
  66. "Ulti Quality": "high", #This one doesn't have an equivalent. Map it to high.
  67. "abs_0.25_normal": "um2p_abs_0.25_normal",
  68. "abs_0.4_fast": "um2p_abs_0.4_fast",
  69. "abs_0.4_high": "um2p_abs_0.4_high",
  70. "abs_0.4_normal": "um2p_abs_0.4_normal",
  71. "abs_0.6_normal": "um2p_abs_0.6_normal",
  72. "abs_0.8_normal": "um2p_abs_0.8_normal",
  73. "cpe_0.25_normal": "um2p_cpe_0.25_normal",
  74. "cpe_0.4_fast": "um2p_cpe_0.4_fast",
  75. "cpe_0.4_high": "um2p_cpe_0.4_high",
  76. "cpe_0.4_normal": "um2p_cpe_0.4_normal",
  77. "cpe_0.6_normal": "um2p_cpe_0.6_normal",
  78. "cpe_0.8_normal": "um2p_cpe_0.8_normal",
  79. "cpep_0.4_draft": "um2p_cpep_0.4_draft",
  80. "cpep_0.4_normal": "um2p_cpep_0.4_normal",
  81. "cpep_0.6_draft": "um2p_cpep_0.6_draft",
  82. "cpep_0.6_normal": "um2p_cpep_0.6_normal",
  83. "cpep_0.8_draft": "um2p_cpep_0.8_draft",
  84. "cpep_0.8_normal": "um2p_cpep_0.8_normal",
  85. "nylon_0.25_high": "um2p_nylon_0.25_high",
  86. "nylon_0.25_normal": "um2p_nylon_0.25_normal",
  87. "nylon_0.4_fast": "um2p_nylon_0.4_fast",
  88. "nylon_0.4_normal": "um2p_nylon_0.4_normal",
  89. "nylon_0.6_fast": "um2p_nylon_0.6_fast",
  90. "nylon_0.6_normal": "um2p_nylon_0.6_normal",
  91. "nylon_0.8_draft": "um2p_nylon_0.8_draft",
  92. "nylon_0.8_normal": "um2p_nylon_0.8_normal",
  93. "pc_0.25_high": "um2p_pc_0.25_high",
  94. "pc_0.25_normal": "um2p_pc_0.25_normal",
  95. "pc_0.4_fast": "um2p_pc_0.4_fast",
  96. "pc_0.4_normal": "um2p_pc_0.4_normal",
  97. "pc_0.6_fast": "um2p_pc_0.6_fast",
  98. "pc_0.6_normal": "um2p_pc_0.6_normal",
  99. "pc_0.8_draft": "um2p_pc_0.8_draft",
  100. "pc_0.8_normal": "um2p_pc_0.8_normal",
  101. "pla_0.25_normal": "pla_0.25_normal", #Note that the PLA profiles don't get the um2p_ prefix, though they are for UM2+.
  102. "pla_0.4_fast": "pla_0.4_fast",
  103. "pla_0.4_high": "pla_0.4_high",
  104. "pla_0.4_normal": "pla_0.4_normal",
  105. "pla_0.6_normal": "pla_0.6_normal",
  106. "pla_0.8_normal": "pla_0.8_normal",
  107. "tpu_0.25_high": "um2p_tpu_0.25_high",
  108. "tpu_0.4_normal": "um2p_tpu_0.4_normal",
  109. "tpu_0.6_fast": "um2p_tpu_0.6_fast"
  110. }
  111. ## Settings that are no longer in the new version.
  112. _removed_settings = {
  113. "fill_perimeter_gaps",
  114. "support_area_smoothing"
  115. }
  116. ## How to translate setting names from the old version to the new.
  117. _setting_name_translations = {
  118. "remove_overlapping_walls_0_enabled": "travel_compensate_overlapping_walls_0_enabled",
  119. "remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled",
  120. "remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled",
  121. "retraction_hop": "retraction_hop_enabled",
  122. "skirt_line_width": "skirt_brim_line_width",
  123. "skirt_minimal_length": "skirt_brim_minimal_length",
  124. "skirt_speed": "skirt_brim_speed",
  125. "speed_support_lines": "speed_support_infill",
  126. "speed_support_roof": "speed_support_interface",
  127. "support_roof_density": "support_interface_density",
  128. "support_roof_enable": "support_interface_enable",
  129. "support_roof_extruder_nr": "support_interface_extruder_nr",
  130. "support_roof_line_distance": "support_interface_line_distance",
  131. "support_roof_line_width": "support_interface_line_width",
  132. "support_roof_pattern": "support_interface_pattern"
  133. }
  134. ## Custom profiles become quality_changes. This dictates which quality to base
  135. # the quality_changes profile on.
  136. #
  137. # Which quality profile to base the quality_changes on depends on the machine,
  138. # material and nozzle.
  139. #
  140. # If a current configuration is missing, fall back to "normal".
  141. _quality_fallbacks = {
  142. "ultimaker2_plus": {
  143. "ultimaker2_plus_0.25": {
  144. "generic_abs": "um2p_abs_0.25_normal",
  145. "generic_cpe": "um2p_cpe_0.25_normal",
  146. #No CPE+.
  147. "generic_nylon": "um2p_nylon_0.25_normal",
  148. "generic_pc": "um2p_pc_0.25_normal",
  149. "generic_pla": "pla_0.25_normal",
  150. "generic_tpu": "um2p_tpu_0.25_high"
  151. },
  152. "ultimaker2_plus_0.4": {
  153. "generic_abs": "um2p_abs_0.4_normal",
  154. "generic_cpe": "um2p_cpe_0.4_normal",
  155. "generic_cpep": "um2p_cpep_0.4_normal",
  156. "generic_nylon": "um2p_nylon_0.4_normal",
  157. "generic_pc": "um2p_pc_0.4_normal",
  158. "generic_pla": "pla_0.4_normal",
  159. "generic_tpu": "um2p_tpu_0.4_normal"
  160. },
  161. "ultimaker2_plus_0.6": {
  162. "generic_abs": "um2p_abs_0.6_normal",
  163. "generic_cpe": "um2p_cpe_0.6_normal",
  164. "generic_cpep": "um2p_cpep_0.6_normal",
  165. "generic_nylon": "um2p_nylon_0.6_normal",
  166. "generic_pc": "um2p_pc_0.6_normal",
  167. "generic_pla": "pla_0.6_normal",
  168. "generic_tpu": "um2p_tpu_0.6_fast",
  169. },
  170. "ultimaker2_plus_0.8": {
  171. "generic_abs": "um2p_abs_0.8_normal",
  172. "generic_cpe": "um2p_cpe_0.8_normal",
  173. "generic_cpep": "um2p_cpep_0.8_normal",
  174. "generic_nylon": "um2p_nylon_0.8_normal",
  175. "generic_pc": "um2p_pc_0.8_normal",
  176. "generic_pla": "pla_0.8_normal",
  177. #No TPU.
  178. }
  179. }
  180. }
  181. ## How to translate variants of specific machines from the old version to the
  182. # new.
  183. _variant_translations = {
  184. "ultimaker2_plus": {
  185. "0.25 mm": "ultimaker2_plus_0.25",
  186. "0.4 mm": "ultimaker2_plus_0.4",
  187. "0.6 mm": "ultimaker2_plus_0.6",
  188. "0.8 mm": "ultimaker2_plus_0.8"
  189. },
  190. "ultimaker2_extended_plus": {
  191. "0.25 mm": "ultimaker2_extended_plus_0.25",
  192. "0.4 mm": "ultimaker2_extended_plus_0.4",
  193. "0.6 mm": "ultimaker2_extended_plus_0.6",
  194. "0.8 mm": "ultimaker2_extended_plus_0.8"
  195. }
  196. }
  197. ## How to translate variant names for in the profile names.
  198. _variant_translations_profiles = {
  199. "0.25 mm": "0.25",
  200. "0.4 mm": "0.4",
  201. "0.6 mm": "0.6",
  202. "0.8 mm": "0.8"
  203. }
  204. ## Cura 2.2's material profiles use a different naming scheme for variants.
  205. #
  206. # Getting pretty stressed out by this sort of thing...
  207. _variant_translations_materials = {
  208. "ultimaker2_plus": {
  209. "0.25 mm": "ultimaker2_plus_0.25_mm",
  210. "0.4 mm": "ultimaker2_plus_0.4_mm",
  211. "0.6 mm": "ultimaker2_plus_0.6_mm",
  212. "0.8 mm": "ultimaker2_plus_0.8_mm"
  213. },
  214. "ultimaker2_extended_plus": {
  215. "0.25 mm": "ultimaker2_plus_0.25_mm",
  216. "0.4 mm": "ultimaker2_plus_0.4_mm",
  217. "0.6 mm": "ultimaker2_plus_0.6_mm",
  218. "0.8 mm": "ultimaker2_plus_0.8_mm"
  219. }
  220. }
  221. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's.
  222. #
  223. # It converts the machine instances and profiles.
  224. class VersionUpgrade21to22(VersionUpgrade):
  225. ## Gets the version number from a config file.
  226. #
  227. # In all config files that concern this version upgrade, the version
  228. # number is stored in general/version, so get the data from that key.
  229. #
  230. # \param serialised The contents of a config file.
  231. # \return \type{int} The version number of that config file.
  232. def getCfgVersion(self, serialised):
  233. parser = configparser.ConfigParser(interpolation = None)
  234. parser.read_string(serialised)
  235. return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  236. ## Gets the fallback quality to use for a specific machine-variant-material
  237. # combination.
  238. #
  239. # For custom profiles we fall back onto this quality profile, since we
  240. # don't know which quality profile it was based on.
  241. #
  242. # \param machine The machine ID of the user's configuration in 2.2.
  243. # \param variant The variant ID of the user's configuration in 2.2.
  244. # \param material The material ID of the user's configuration in 2.2.
  245. @staticmethod
  246. def getQualityFallback(machine, variant, material):
  247. if machine not in _quality_fallbacks:
  248. return "normal"
  249. if variant not in _quality_fallbacks[machine]:
  250. return "normal"
  251. if material not in _quality_fallbacks[machine][variant]:
  252. return "normal"
  253. return _quality_fallbacks[machine][variant][material]
  254. ## Gets the set of built-in profile names in Cura 2.1.
  255. #
  256. # This is required to test if profiles should be converted to a quality
  257. # profile or a quality-changes profile.
  258. @staticmethod
  259. def builtInProfiles():
  260. return _profile_translations.keys()
  261. ## Gets a set of the machines which now have per-material quality profiles.
  262. #
  263. # \return A set of machine identifiers.
  264. @staticmethod
  265. def machinesWithMachineQuality():
  266. return _machines_with_machine_quality
  267. ## Converts machine instances from format version 1 to version 2.
  268. #
  269. # \param serialised The serialised machine instance in version 1.
  270. # \param filename The supposed file name of the machine instance, without
  271. # extension.
  272. # \return A tuple containing the new filename and the serialised machine
  273. # instance in version 2, or None if the input was not of the correct
  274. # format.
  275. def upgradeMachineInstance(self, serialised, filename):
  276. machine_instance = MachineInstance.importFrom(serialised, filename)
  277. if not machine_instance: #Invalid file format.
  278. return filename, None
  279. return machine_instance.export()
  280. ## Converts preferences from format version 2 to version 3.
  281. #
  282. # \param serialised The serialised preferences file in version 2.
  283. # \param filename The supposed file name of the preferences file, without
  284. # extension.
  285. # \return A tuple containing the new filename and the serialised
  286. # preferences in version 3, or None if the input was not of the correct
  287. # format.
  288. def upgradePreferences(self, serialised, filename):
  289. preferences = Preferences.importFrom(serialised, filename)
  290. if not preferences: #Invalid file format.
  291. return filename, None
  292. return preferences.export()
  293. ## Converts profiles from format version 1 to version 2.
  294. #
  295. # \param serialised The serialised profile in version 1.
  296. # \param filename The supposed file name of the profile, without
  297. # extension.
  298. # \return A tuple containing the new filename and the serialised profile
  299. # in version 2, or None if the input was not of the correct format.
  300. def upgradeProfile(self, serialised, filename):
  301. profile = Profile.importFrom(serialised, filename)
  302. if not profile: # Invalid file format.
  303. return filename, None
  304. return profile.export()
  305. ## Translates a material name for the change from Cura 2.1 to 2.2.
  306. #
  307. # \param material A material name in Cura 2.1.
  308. # \return The name of the corresponding material in Cura 2.2.
  309. @staticmethod
  310. def translateMaterial(material):
  311. if material in _material_translations:
  312. return _material_translations[material]
  313. return material
  314. ## Translates a material name for the change from Cura 2.1 to 2.2 in
  315. # quality profile names.
  316. #
  317. # \param material A material name in Cura 2.1.
  318. # \return The name of the corresponding material in the quality profiles
  319. # in Cura 2.2.
  320. @staticmethod
  321. def translateMaterialForProfiles(material):
  322. if material in _material_translations_profiles:
  323. return _material_translations_profiles[material]
  324. return material
  325. ## Translates a printer name that might have changed since the last
  326. # version.
  327. #
  328. # \param printer A printer name in Cura 2.1.
  329. # \return The name of the corresponding printer in Cura 2.2.
  330. @staticmethod
  331. def translatePrinter(printer):
  332. if printer in _printer_translations:
  333. return _printer_translations[printer]
  334. return printer #Doesn't need to be translated.
  335. ## Translates a printer name for the change from Cura 2.1 to 2.2 in quality
  336. # profile names.
  337. #
  338. # \param printer A printer name in 2.1.
  339. # \return The name of the corresponding printer in Cura 2.2.
  340. @staticmethod
  341. def translatePrinterForProfile(printer):
  342. if printer in _printer_translations_profiles:
  343. return _printer_translations_profiles[printer]
  344. return printer
  345. ## Translates a built-in profile name that might have changed since the
  346. # last version.
  347. #
  348. # \param profile A profile name in the old version.
  349. # \return The corresponding profile name in the new version.
  350. @staticmethod
  351. def translateProfile(profile):
  352. if profile in _profile_translations:
  353. return _profile_translations[profile]
  354. return profile #Doesn't need to be translated.
  355. ## Updates settings for the change from Cura 2.1 to 2.2.
  356. #
  357. # The keys and values of settings are changed to what they should be in
  358. # the new version. Each setting is changed in-place in the provided
  359. # dictionary. This changes the input parameter.
  360. #
  361. # \param settings A dictionary of settings (as key-value pairs) to update.
  362. # \return The same dictionary.
  363. @staticmethod
  364. def translateSettings(settings):
  365. new_settings = {}
  366. for key, value in settings.items():
  367. if key in _removed_settings:
  368. continue
  369. if key == "retraction_combing": #Combing was made into an enum instead of a boolean.
  370. new_settings[key] = "off" if (value == "False") else "all"
  371. continue
  372. if key in _setting_name_translations:
  373. new_settings[_setting_name_translations[key]] = value
  374. continue
  375. new_settings[key] = value
  376. if "infill_overlap" in settings: # New setting, added in 2.3
  377. new_settings["skin_overlap"] = settings["infill_overlap"]
  378. return new_settings
  379. ## Translates a setting name for the change from Cura 2.1 to 2.2.
  380. #
  381. # \param setting The name of a setting in Cura 2.1.
  382. # \return The name of the corresponding setting in Cura 2.2.
  383. @staticmethod
  384. def translateSettingName(setting):
  385. if setting in _setting_name_translations:
  386. return _setting_name_translations[setting]
  387. return setting #Doesn't need to be translated.
  388. ## Translates a variant name for the change from Cura 2.1 to 2.2
  389. #
  390. # \param variant The name of a variant in Cura 2.1.
  391. # \param machine The name of the machine this variant is part of in Cura
  392. # 2.2's naming.
  393. # \return The name of the corresponding variant in Cura 2.2.
  394. @staticmethod
  395. def translateVariant(variant, machine):
  396. if machine in _variant_translations and variant in _variant_translations[machine]:
  397. return _variant_translations[machine][variant]
  398. return variant
  399. ## Translates a variant name for the change from Cura 2.1 to 2.2 in
  400. # material profiles.
  401. #
  402. # \param variant The name of the variant in Cura 2.1.
  403. # \param machine The name of the machine this variant is part of in Cura
  404. # 2.2's naming.
  405. # \return The name of the corresponding variant for in material profiles
  406. # in Cura 2.2.
  407. @staticmethod
  408. def translateVariantForMaterials(variant, machine):
  409. if machine in _variant_translations_materials and variant in _variant_translations_materials[machine]:
  410. return _variant_translations_materials[machine][variant]
  411. return variant
  412. ## Translates a variant name for the change from Cura 2.1 to 2.2 in quality
  413. # profiles.
  414. #
  415. # \param variant The name of the variant in Cura 2.1.
  416. # \return The name of the corresponding variant for in quality profiles in
  417. # Cura 2.2.
  418. @staticmethod
  419. def translateVariantForProfiles(variant):
  420. if variant in _variant_translations_profiles:
  421. return _variant_translations_profiles[variant]
  422. return variant