VersionUpgrade34to35.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser
  4. import io
  5. from UM.VersionUpgrade import VersionUpgrade
  6. deleted_settings = {"prime_tower_wall_thickness", "dual_pre_wipe", "prime_tower_purge_volume"}
  7. changed_settings = {'retraction_combing': 'noskin'}
  8. updated_settings = {'retraction_combing': 'infill'}
  9. _RENAMED_MATERIAL_PROFILES = {
  10. "dsm_arnitel2045_175_cartesio_0.25_mm": "dsm_arnitel2045_175_cartesio_0.25mm_thermoplastic_extruder",
  11. "dsm_arnitel2045_175_cartesio_0.4_mm": "dsm_arnitel2045_175_cartesio_0.4mm_thermoplastic_extruder",
  12. "dsm_arnitel2045_175_cartesio_0.8_mm": "dsm_arnitel2045_175_cartesio_0.8mm_thermoplastic_extruder",
  13. "dsm_novamid1070_175_cartesio_0.25_mm": "dsm_novamid1070_175_cartesio_0.25mm_thermoplastic_extruder",
  14. "dsm_novamid1070_175_cartesio_0.4_mm": "dsm_novamid1070_175_cartesio_0.4mm_thermoplastic_extruder",
  15. "dsm_novamid1070_175_cartesio_0.8_mm": "dsm_novamid1070_175_cartesio_0.8mm_thermoplastic_extruder",
  16. "generic_abs_175_cartesio_0.25_mm": "generic_abs_175_cartesio_0.25mm_thermoplastic_extruder",
  17. "generic_abs_175_cartesio_0.4_mm": "generic_abs_175_cartesio_0.4mm_thermoplastic_extruder",
  18. "generic_abs_175_cartesio_0.8_mm": "generic_abs_175_cartesio_0.8mm_thermoplastic_extruder",
  19. "generic_hips_175_cartesio_0.25_mm": "generic_hips_175_cartesio_0.25mm_thermoplastic_extruder",
  20. "generic_hips_175_cartesio_0.4_mm": "generic_hips_175_cartesio_0.4mm_thermoplastic_extruder",
  21. "generic_hips_175_cartesio_0.8_mm": "generic_hips_175_cartesio_0.8mm_thermoplastic_extruder",
  22. "generic_nylon_175_cartesio_0.25_mm": "generic_nylon_175_cartesio_0.25mm_thermoplastic_extruder",
  23. "generic_nylon_175_cartesio_0.4_mm": "generic_nylon_175_cartesio_0.4mm_thermoplastic_extruder",
  24. "generic_nylon_175_cartesio_0.8_mm": "generic_nylon_175_cartesio_0.8mm_thermoplastic_extruder",
  25. "generic_pc_cartesio_0.25_mm": "generic_pc_cartesio_0.25mm_thermoplastic_extruder",
  26. "generic_pc_cartesio_0.4_mm": "generic_pc_cartesio_0.4mm_thermoplastic_extruder",
  27. "generic_pc_cartesio_0.8_mm": "generic_pc_cartesio_0.8mm_thermoplastic_extruder",
  28. "generic_pc_175_cartesio_0.25_mm": "generic_pc_175_cartesio_0.25mm_thermoplastic_extruder",
  29. "generic_pc_175_cartesio_0.4_mm": "generic_pc_175_cartesio_0.4mm_thermoplastic_extruder",
  30. "generic_pc_175_cartesio_0.8_mm": "generic_pc_175_cartesio_0.8mm_thermoplastic_extruder",
  31. "generic_petg_175_cartesio_0.25_mm": "generic_petg_175_cartesio_0.25mm_thermoplastic_extruder",
  32. "generic_petg_175_cartesio_0.4_mm": "generic_petg_175_cartesio_0.4mm_thermoplastic_extruder",
  33. "generic_petg_175_cartesio_0.8_mm": "generic_petg_175_cartesio_0.8mm_thermoplastic_extruder",
  34. "generic_pla_175_cartesio_0.25_mm": "generic_pla_175_cartesio_0.25mm_thermoplastic_extruder",
  35. "generic_pla_175_cartesio_0.4_mm": "generic_pla_175_cartesio_0.4mm_thermoplastic_extruder",
  36. "generic_pla_175_cartesio_0.8_mm": "generic_pla_175_cartesio_0.8mm_thermoplastic_extruder",
  37. "generic_pva_cartesio_0.25_mm": "generic_pva_cartesio_0.25mm_thermoplastic_extruder",
  38. "generic_pva_cartesio_0.4_mm": "generic_pva_cartesio_0.4mm_thermoplastic_extruder",
  39. "generic_pva_cartesio_0.8_mm": "generic_pva_cartesio_0.8mm_thermoplastic_extruder",
  40. "generic_pva_175_cartesio_0.25_mm": "generic_pva_175_cartesio_0.25mm_thermoplastic_extruder",
  41. "generic_pva_175_cartesio_0.4_mm": "generic_pva_175_cartesio_0.4mm_thermoplastic_extruder",
  42. "generic_pva_175_cartesio_0.8_mm": "generic_pva_175_cartesio_0.8mm_thermoplastic_extruder",
  43. "ultimaker_pc_black_cartesio_0.25_mm": "ultimaker_pc_black_cartesio_0.25mm_thermoplastic_extruder",
  44. "ultimaker_pc_black_cartesio_0.4_mm": "ultimaker_pc_black_cartesio_0.4mm_thermoplastic_extruder",
  45. "ultimaker_pc_black_cartesio_0.8_mm": "ultimaker_pc_black_cartesio_0.8mm_thermoplastic_extruder",
  46. "ultimaker_pc_transparent_cartesio_0.25_mm": "ultimaker_pc_transparent_cartesio_0.25mm_thermoplastic_extruder",
  47. "ultimaker_pc_transparent_cartesio_0.4_mm": "ultimaker_pc_transparent_cartesio_0.4mm_thermoplastic_extruder",
  48. "ultimaker_pc_transparent_cartesio_0.8_mm": "ultimaker_pc_transparent_cartesio_0.8mm_thermoplastic_extruder",
  49. "ultimaker_pc_white_cartesio_0.25_mm": "ultimaker_pc_white_cartesio_0.25mm_thermoplastic_extruder",
  50. "ultimaker_pc_white_cartesio_0.4_mm": "ultimaker_pc_white_cartesio_0.4mm_thermoplastic_extruder",
  51. "ultimaker_pc_white_cartesio_0.8_mm": "ultimaker_pc_white_cartesio_0.8mm_thermoplastic_extruder",
  52. "ultimaker_pva_cartesio_0.25_mm": "ultimaker_pva_cartesio_0.25mm_thermoplastic_extruder",
  53. "ultimaker_pva_cartesio_0.4_mm": "ultimaker_pva_cartesio_0.4mm_thermoplastic_extruder",
  54. "ultimaker_pva_cartesio_0.8_mm": "ultimaker_pva_cartesio_0.8mm_thermoplastic_extruder"
  55. }
  56. ## Upgrades configurations from the state they were in at version 3.4 to the
  57. # state they should be in at version 3.5.
  58. class VersionUpgrade34to35(VersionUpgrade):
  59. ## Gets the version number from a CFG file in Uranium's 3.3 format.
  60. #
  61. # Since the format may change, this is implemented for the 3.3 format only
  62. # and needs to be included in the version upgrade system rather than
  63. # globally in Uranium.
  64. #
  65. # \param serialised The serialised form of a CFG file.
  66. # \return The version number stored in the CFG file.
  67. # \raises ValueError The format of the version number in the file is
  68. # incorrect.
  69. # \raises KeyError The format of the file is incorrect.
  70. def getCfgVersion(self, serialised):
  71. parser = configparser.ConfigParser(interpolation = None)
  72. parser.read_string(serialised)
  73. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  74. setting_version = int(parser.get("metadata", "setting_version", fallback = 0))
  75. return format_version * 1000000 + setting_version
  76. ## Upgrades Preferences to have the new version number.
  77. def upgradePreferences(self, serialized, filename):
  78. parser = configparser.ConfigParser(interpolation = None)
  79. parser.read_string(serialized)
  80. # Need to show the data collection agreement again because the data Cura collects has been changed.
  81. if parser.has_option("info", "asked_send_slice_info"):
  82. parser.set("info", "asked_send_slice_info", "False")
  83. if parser.has_option("info", "send_slice_info"):
  84. parser.set("info", "send_slice_info", "True")
  85. # Update version number.
  86. parser["general"]["version"] = "6"
  87. if "metadata" not in parser:
  88. parser["metadata"] = {}
  89. parser["metadata"]["setting_version"] = "5"
  90. result = io.StringIO()
  91. parser.write(result)
  92. return [filename], [result.getvalue()]
  93. ## Upgrades stacks to have the new version number.
  94. def upgradeStack(self, serialized, filename):
  95. parser = configparser.ConfigParser(interpolation = None)
  96. parser.read_string(serialized)
  97. # Update version number.
  98. parser["general"]["version"] = "4"
  99. parser["metadata"]["setting_version"] = "5"
  100. #Update the name of the quality profile.
  101. if parser["containers"]["3"] in _RENAMED_MATERIAL_PROFILES:
  102. parser["containers"]["3"] = _RENAMED_MATERIAL_PROFILES[parser["containers"]["3"]]
  103. result = io.StringIO()
  104. parser.write(result)
  105. return [filename], [result.getvalue()]
  106. ## Upgrades instance containers to have the new version
  107. # number.
  108. def upgradeInstanceContainer(self, serialized, filename):
  109. parser = configparser.ConfigParser(interpolation = None)
  110. parser.read_string(serialized)
  111. # Update version number.
  112. parser["general"]["version"] = "4"
  113. parser["metadata"]["setting_version"] = "5"
  114. self._resetConcentric3DInfillPattern(parser)
  115. if "values" in parser:
  116. for deleted_setting in deleted_settings:
  117. if deleted_setting not in parser["values"]:
  118. continue
  119. del parser["values"][deleted_setting]
  120. for setting_key in changed_settings:
  121. if setting_key not in parser["values"]:
  122. continue
  123. if parser["values"][setting_key] == changed_settings[setting_key]:
  124. parser["values"][setting_key] = updated_settings[setting_key]
  125. result = io.StringIO()
  126. parser.write(result)
  127. return [filename], [result.getvalue()]
  128. def _resetConcentric3DInfillPattern(self, parser):
  129. if "values" not in parser:
  130. return
  131. # Reset the patterns which are concentric 3d
  132. for key in ("infill_pattern",
  133. "support_pattern",
  134. "support_interface_pattern",
  135. "support_roof_pattern",
  136. "support_bottom_pattern",
  137. ):
  138. if key not in parser["values"]:
  139. continue
  140. if parser["values"][key] == "concentric_3d":
  141. del parser["values"][key]