VersionUpgrade21to22.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. _profile_translations = {
  60. "Low Quality": "low",
  61. "Normal Quality": "normal",
  62. "High Quality": "high",
  63. "Ulti Quality": "high" #This one doesn't have an equivalent. Map it to high.
  64. }
  65. ## How to translate setting names from the old version to the new.
  66. _setting_name_translations = {
  67. "remove_overlapping_walls_0_enabled": "travel_compensate_overlapping_walls_0_enabled",
  68. "remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled",
  69. "remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled",
  70. "retraction_hop": "retraction_hop_enabled",
  71. "skirt_line_width": "skirt_brim_line_width",
  72. "skirt_minimal_length": "skirt_brim_minimal_length",
  73. "skirt_speed": "skirt_brim_speed",
  74. "speed_support_lines": "speed_support_infill",
  75. "speed_support_roof": "speed_support_interface",
  76. "support_roof_density": "support_interface_density",
  77. "support_roof_enable": "support_interface_enable",
  78. "support_roof_extruder_nr": "support_interface_extruder_nr",
  79. "support_roof_line_distance": "support_interface_line_distance",
  80. "support_roof_line_width": "support_interface_line_width",
  81. "support_roof_pattern": "support_interface_pattern"
  82. }
  83. ## How to translate variants of specific machines from the old version to the
  84. # new.
  85. _variant_translations = {
  86. "ultimaker2_plus": {
  87. "0.25 mm": "ultimaker2_plus_0.25",
  88. "0.4 mm": "ultimaker2_plus_0.4",
  89. "0.6 mm": "ultimaker2_plus_0.6",
  90. "0.8 mm": "ultimaker2_plus_0.8"
  91. },
  92. "ultimaker2_extended_plus": {
  93. "0.25 mm": "ultimaker2_extended_plus_0.25",
  94. "0.4 mm": "ultimaker2_extended_plus_0.4",
  95. "0.6 mm": "ultimaker2_extended_plus_0.6",
  96. "0.8 mm": "ultimaker2_extended_plus_0.8"
  97. }
  98. }
  99. ## How to translate variant names for in the profile names.
  100. _variant_translations_profiles = {
  101. "0.25 mm": "0.25",
  102. "0.4 mm": "0.4",
  103. "0.6 mm": "0.6",
  104. "0.8 mm": "0.8"
  105. }
  106. ## Cura 2.2's material profiles use a different naming scheme for variants.
  107. #
  108. # Getting pretty stressed out by this sort of thing...
  109. _variant_translations_materials = {
  110. "ultimaker2_plus": {
  111. "0.25 mm": "ultimaker2_plus_0.25_mm",
  112. "0.4 mm": "ultimaker2_plus_0.4_mm",
  113. "0.6 mm": "ultimaker2_plus_0.6_mm",
  114. "0.8 mm": "ultimaker2_plus_0.8_mm"
  115. },
  116. "ultimaker2_extended_plus": {
  117. "0.25 mm": "ultimaker2_plus_0.25_mm",
  118. "0.4 mm": "ultimaker2_plus_0.4_mm",
  119. "0.6 mm": "ultimaker2_plus_0.6_mm",
  120. "0.8 mm": "ultimaker2_plus_0.8_mm"
  121. }
  122. }
  123. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's.
  124. #
  125. # It converts the machine instances and profiles.
  126. class VersionUpgrade21to22(VersionUpgrade):
  127. ## Gets the version number from a config file.
  128. #
  129. # In all config files that concern this version upgrade, the version
  130. # number is stored in general/version, so get the data from that key.
  131. #
  132. # \param serialised The contents of a config file.
  133. # \return \type{int} The version number of that config file.
  134. def getCfgVersion(self, serialised):
  135. parser = configparser.ConfigParser(interpolation = None)
  136. parser.read_string(serialised)
  137. return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  138. ## Gets the set of built-in profile names in Cura 2.1.
  139. #
  140. # This is required to test if profiles should be converted to a quality
  141. # profile or a quality-changes profile.
  142. @staticmethod
  143. def builtInProfiles():
  144. return _profile_translations.keys()
  145. ## Gets a set of the machines which now have per-material quality profiles.
  146. #
  147. # \return A set of machine identifiers.
  148. @staticmethod
  149. def machinesWithMachineQuality():
  150. return _machines_with_machine_quality
  151. ## Converts machine instances from format version 1 to version 2.
  152. #
  153. # \param serialised The serialised machine instance in version 1.
  154. # \param filename The supposed file name of the machine instance, without
  155. # extension.
  156. # \return A tuple containing the new filename and the serialised machine
  157. # instance in version 2, or None if the input was not of the correct
  158. # format.
  159. def upgradeMachineInstance(self, serialised, filename):
  160. machine_instance = MachineInstance.importFrom(serialised, filename)
  161. if not machine_instance: #Invalid file format.
  162. return filename, None
  163. return machine_instance.export()
  164. ## Converts preferences from format version 2 to version 3.
  165. #
  166. # \param serialised The serialised preferences file in version 2.
  167. # \param filename The supposed file name of the preferences file, without
  168. # extension.
  169. # \return A tuple containing the new filename and the serialised
  170. # preferences in version 3, or None if the input was not of the correct
  171. # format.
  172. def upgradePreferences(self, serialised, filename):
  173. preferences = Preferences.importFrom(serialised, filename)
  174. if not preferences: #Invalid file format.
  175. return filename, None
  176. return preferences.export()
  177. ## Converts profiles from format version 1 to version 2.
  178. #
  179. # \param serialised The serialised profile in version 1.
  180. # \param filename The supposed file name of the profile, without
  181. # extension.
  182. # \return A tuple containing the new filename and the serialised profile
  183. # in version 2, or None if the input was not of the correct format.
  184. def upgradeProfile(self, serialised, filename):
  185. profile = Profile.importFrom(serialised, filename)
  186. if not profile: # Invalid file format.
  187. return filename, None
  188. return profile.export()
  189. ## Translates a material name for the change from Cura 2.1 to 2.2.
  190. #
  191. # \param material A material name in Cura 2.1.
  192. # \return The name of the corresponding material in Cura 2.2.
  193. @staticmethod
  194. def translateMaterial(material):
  195. if material in _material_translations:
  196. return _material_translations[material]
  197. return material
  198. ## Translates a material name for the change from Cura 2.1 to 2.2 in
  199. # quality profile names.
  200. #
  201. # \param material A material name in Cura 2.1.
  202. # \return The name of the corresponding material in the quality profiles
  203. # in Cura 2.2.
  204. @staticmethod
  205. def translateMaterialForProfiles(material):
  206. if material in _material_translations_profiles:
  207. return _material_translations_profiles[material]
  208. return material
  209. ## Translates a printer name that might have changed since the last
  210. # version.
  211. #
  212. # \param printer A printer name in Cura 2.1.
  213. # \return The name of the corresponding printer in Cura 2.2.
  214. @staticmethod
  215. def translatePrinter(printer):
  216. if printer in _printer_translations:
  217. return _printer_translations[printer]
  218. return printer #Doesn't need to be translated.
  219. ## Translates a printer name for the change from Cura 2.1 to 2.2 in quality
  220. # profile names.
  221. #
  222. # \param printer A printer name in 2.1.
  223. # \return The name of the corresponding printer in Cura 2.2.
  224. @staticmethod
  225. def translatePrinterForProfile(printer):
  226. if printer in _printer_translations_profiles:
  227. return _printer_translations_profiles[printer]
  228. return printer
  229. ## Translates a built-in profile name that might have changed since the
  230. # last version.
  231. #
  232. # \param profile A profile name in the old version.
  233. # \return The corresponding profile name in the new version.
  234. @staticmethod
  235. def translateProfile(profile):
  236. if profile in _profile_translations:
  237. return _profile_translations[profile]
  238. return profile #Doesn't need to be translated.
  239. ## Updates settings for the change from Cura 2.1 to 2.2.
  240. #
  241. # The keys and values of settings are changed to what they should be in
  242. # the new version. Each setting is changed in-place in the provided
  243. # dictionary. This changes the input parameter.
  244. #
  245. # \param settings A dictionary of settings (as key-value pairs) to update.
  246. # \return The same dictionary.
  247. @staticmethod
  248. def translateSettings(settings):
  249. for key, value in settings.items():
  250. if key == "fill_perimeter_gaps": #Setting is removed.
  251. del settings[key]
  252. elif key == "retraction_combing": #Combing was made into an enum instead of a boolean.
  253. settings[key] = "off" if (value == "False") else "all"
  254. elif key in _setting_name_translations:
  255. del settings[key]
  256. settings[_setting_name_translations[key]] = value
  257. return settings
  258. ## Translates a setting name for the change from Cura 2.1 to 2.2.
  259. #
  260. # \param setting The name of a setting in Cura 2.1.
  261. # \return The name of the corresponding setting in Cura 2.2.
  262. @staticmethod
  263. def translateSettingName(setting):
  264. if setting in _setting_name_translations:
  265. return _setting_name_translations[setting]
  266. return setting #Doesn't need to be translated.
  267. ## Translates a variant name for the change from Cura 2.1 to 2.2
  268. #
  269. # \param variant The name of a variant in Cura 2.1.
  270. # \param machine The name of the machine this variant is part of in Cura
  271. # 2.2's naming.
  272. # \return The name of the corresponding variant in Cura 2.2.
  273. @staticmethod
  274. def translateVariant(variant, machine):
  275. if machine in _variant_translations and variant in _variant_translations[machine]:
  276. return _variant_translations[machine][variant]
  277. return variant
  278. ## Translates a variant name for the change from Cura 2.1 to 2.2 in
  279. # material profiles.
  280. #
  281. # \param variant The name of the variant in Cura 2.1.
  282. # \param machine The name of the machine this variant is part of in Cura
  283. # 2.2's naming.
  284. # \return The name of the corresponding variant for in material profiles
  285. # in Cura 2.2.
  286. @staticmethod
  287. def translateVariantForMaterials(variant, machine):
  288. if machine in _variant_translations_materials and variant in _variant_translations_materials[machine]:
  289. return _variant_translations_materials[machine][variant]
  290. return variant
  291. ## Translates a variant name for the change from Cura 2.1 to 2.2 in quality
  292. # profiles.
  293. #
  294. # \param variant The name of the variant in Cura 2.1.
  295. # \return The name of the corresponding variant for in quality profiles in
  296. # Cura 2.2.
  297. @staticmethod
  298. def translateVariantForProfiles(variant):
  299. if variant in _variant_translations_profiles:
  300. return _variant_translations_profiles[variant]
  301. return variant