VersionUpgrade34to35.py 9.3 KB

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