VersionUpgrade21to22.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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" },
  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" },
  27. "variants": { "0.25 mm", "0.4 mm", "0.6 mm", "0.8 mm" }
  28. }
  29. }
  30. ## How to translate printer names from the old version to the new.
  31. _printer_translations = {
  32. "ultimaker2plus": "ultimaker2_plus"
  33. }
  34. ## How to translate profile names from the old version to the new.
  35. _profile_translations = {
  36. "PLA": "generic_pla",
  37. "ABS": "generic_abs",
  38. "CPE": "generic_cpe",
  39. "Low Quality": "low",
  40. "Normal Quality": "normal",
  41. "High Quality": "high",
  42. "Ulti Quality": "high" #This one doesn't have an equivalent. Map it to high.
  43. }
  44. ## How to translate setting names from the old version to the new.
  45. _setting_name_translations = {
  46. "remove_overlapping_walls_0_enabled": "travel_compensate_overlapping_walls_0_enabled",
  47. "remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled",
  48. "remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled",
  49. "retraction_hop": "retraction_hop_enabled",
  50. "skirt_line_width": "skirt_brim_line_width",
  51. "skirt_minimal_length": "skirt_brim_minimal_length",
  52. "skirt_speed": "skirt_brim_speed",
  53. "speed_support_lines": "speed_support_infill",
  54. "speed_support_roof": "speed_support_interface",
  55. "support_roof_density": "support_interface_density",
  56. "support_roof_enable": "support_interface_enable",
  57. "support_roof_extruder_nr": "support_interface_extruder_nr",
  58. "support_roof_line_distance": "support_interface_line_distance",
  59. "support_roof_line_width": "support_interface_line_width",
  60. "support_roof_pattern": "support_interface_pattern"
  61. }
  62. ## How to translate variants of specific machines from the old version to the
  63. # new.
  64. _variant_translations = {
  65. "ultimaker2_plus": {
  66. "0.25 mm": "ultimaker2_plus_0.25",
  67. "0.4 mm": "ultimaker2_plus_0.4",
  68. "0.6 mm": "ultimaker2_plus_0.6",
  69. "0.8 mm": "ultimaker2_plus_0.8"
  70. },
  71. "ultimaker2_extended_plus": {
  72. "0.25 mm": "ultimaker2_extended_plus_0.25",
  73. "0.4 mm": "ultimaker2_extended_plus_0.4",
  74. "0.6 mm": "ultimaker2_extended_plus_0.6",
  75. "0.8 mm": "ultimaker2_extended_plus_0.8"
  76. }
  77. }
  78. ## Cura 2.2's material profiles use a different naming scheme for variants.
  79. #
  80. # Getting pretty stressed out by this sort of thing...
  81. _variant_translations_materials = {
  82. "ultimaker2_plus": {
  83. "0.25 mm": "ultimaker2_plus_0.25_mm",
  84. "0.4 mm": "ultimaker2_plus_0.4_mm",
  85. "0.6 mm": "ultimaker2_plus_0.6_mm",
  86. "0.8 mm": "ultimaker2_plus_0.8_mm"
  87. },
  88. "ultimaker2_extended_plus": {
  89. "0.25 mm": "ultimaker2_plus_0.25_mm",
  90. "0.4 mm": "ultimaker2_plus_0.4_mm",
  91. "0.6 mm": "ultimaker2_plus_0.6_mm",
  92. "0.8 mm": "ultimaker2_plus_0.8_mm"
  93. }
  94. }
  95. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's.
  96. #
  97. # It converts the machine instances and profiles.
  98. class VersionUpgrade21to22(VersionUpgrade):
  99. ## Gets the version number from a config file.
  100. #
  101. # In all config files that concern this version upgrade, the version
  102. # number is stored in general/version, so get the data from that key.
  103. #
  104. # \param serialised The contents of a config file.
  105. # \return \type{int} The version number of that config file.
  106. def getCfgVersion(self, serialised):
  107. parser = configparser.ConfigParser(interpolation = None)
  108. parser.read_string(serialised)
  109. return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  110. ## Gets a set of the machines which now have per-material quality profiles.
  111. #
  112. # \return A set of machine identifiers.
  113. @staticmethod
  114. def machinesWithMachineQuality():
  115. return _machines_with_machine_quality
  116. ## Converts machine instances from format version 1 to version 2.
  117. #
  118. # \param serialised The serialised machine instance in version 1.
  119. # \param filename The supposed file name of the machine instance, without
  120. # extension.
  121. # \return A tuple containing the new filename and the serialised machine
  122. # instance in version 2, or None if the input was not of the correct
  123. # format.
  124. def upgradeMachineInstance(self, serialised, filename):
  125. machine_instance = MachineInstance.importFrom(serialised, filename)
  126. if not machine_instance: #Invalid file format.
  127. return filename, None
  128. return machine_instance.export()
  129. ## Converts preferences from format version 2 to version 3.
  130. #
  131. # \param serialised The serialised preferences file in version 2.
  132. # \param filename THe supposed file name of the preferences file, without
  133. # extension.
  134. # \return A tuple containing the new filename and the serialised
  135. # preferences in version 3, or None if the input was not of the correct
  136. # format.
  137. def upgradePreferences(self, serialised, filename):
  138. preferences = Preferences.importFrom(serialised, filename)
  139. if not preferences: #Invalid file format.
  140. return filename, None
  141. return preferences.export()
  142. ## Converts profiles from format version 1 to version 2.
  143. #
  144. # \param serialised The serialised profile in version 1.
  145. # \param filename The supposed file name of the profile, without
  146. # extension.
  147. # \return A tuple containing the new filename and the serialised profile
  148. # in version 2, or None if the input was not of the correct format.
  149. def upgradeProfile(self, serialised, filename):
  150. profile = Profile.importFrom(serialised, filename)
  151. if not profile: # Invalid file format.
  152. return filename, None
  153. return profile.export()
  154. ## Translates a printer name that might have changed since the last
  155. # version.
  156. #
  157. # \param printer A printer name in Cura 2.1.
  158. # \return The name of the corresponding printer in Cura 2.2.
  159. @staticmethod
  160. def translatePrinter(printer):
  161. if printer in _printer_translations:
  162. return _printer_translations[printer]
  163. return printer #Doesn't need to be translated.
  164. ## Translates a built-in profile name that might have changed since the
  165. # last version.
  166. #
  167. # \param profile A profile name in the old version.
  168. # \return The corresponding profile name in the new version.
  169. @staticmethod
  170. def translateProfile(profile):
  171. if profile in _profile_translations:
  172. return _profile_translations[profile]
  173. return profile #Doesn't need to be translated.
  174. ## Updates settings for the change from Cura 2.1 to 2.2.
  175. #
  176. # The keys and values of settings are changed to what they should be in
  177. # the new version. Each setting is changed in-place in the provided
  178. # dictionary. This changes the input parameter.
  179. #
  180. # \param settings A dictionary of settings (as key-value pairs) to update.
  181. # \return The same dictionary.
  182. @staticmethod
  183. def translateSettings(settings):
  184. for key, value in settings.items():
  185. if key == "fill_perimeter_gaps": #Setting is removed.
  186. del settings[key]
  187. elif key == "retraction_combing": #Combing was made into an enum instead of a boolean.
  188. settings[key] = "off" if (value == "False") else "all"
  189. elif key in _setting_name_translations:
  190. del settings[key]
  191. settings[_setting_name_translations[key]] = value
  192. return settings
  193. ## Translates a setting name for the change from Cura 2.1 to 2.2.
  194. #
  195. # \param setting The name of a setting in Cura 2.1.
  196. # \return The name of the corresponding setting in Cura 2.2.
  197. @staticmethod
  198. def translateSettingName(setting):
  199. if setting in _setting_name_translations:
  200. return _setting_name_translations[setting]
  201. return setting #Doesn't need to be translated.
  202. ## Translates a variant name for the change from Cura 2.1 to 2.2
  203. #
  204. # \param variant The name of a variant in Cura 2.1.
  205. # \param machine The name of the machine this variant is part of in Cura
  206. # 2.2's naming.
  207. # \return The name of the corresponding variant in Cura 2.2.
  208. @staticmethod
  209. def translateVariant(variant, machine):
  210. if machine in _variant_translations and variant in _variant_translations[machine]:
  211. return _variant_translations[machine][variant]
  212. return variant
  213. ## Translates a variant name for the change from Cura 2.1 to 2.2 in
  214. # material profiles.
  215. #
  216. # \param variant The name of the variant in Cura 2.1.
  217. # \param machine The name of the machine this variant is part of in Cura
  218. # 2.2's naming.
  219. # \return The name of the corresponding variant for in material profiles
  220. # in Cura 2.2.
  221. @staticmethod
  222. def translateVariantForMaterials(variant, machine):
  223. if machine in _variant_translations_materials and variant in _variant_translations_materials[machine]:
  224. return _variant_translations_materials[machine][variant]
  225. return variant