VersionUpgrade34to35.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. ## Upgrades Preferences to have the new version number.
  61. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  62. parser = configparser.ConfigParser(interpolation = None)
  63. parser.read_string(serialized)
  64. # Need to show the data collection agreement again because the data Cura collects has been changed.
  65. if parser.has_option("info", "asked_send_slice_info"):
  66. parser.set("info", "asked_send_slice_info", "False")
  67. if parser.has_option("info", "send_slice_info"):
  68. parser.set("info", "send_slice_info", "True")
  69. # Update version number.
  70. parser["general"]["version"] = "6"
  71. if "metadata" not in parser:
  72. parser["metadata"] = {}
  73. parser["metadata"]["setting_version"] = "5"
  74. result = io.StringIO()
  75. parser.write(result)
  76. return [filename], [result.getvalue()]
  77. ## Upgrades stacks to have the new version number.
  78. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  79. parser = configparser.ConfigParser(interpolation = None)
  80. parser.read_string(serialized)
  81. # Update version number.
  82. parser["general"]["version"] = "4"
  83. parser["metadata"]["setting_version"] = "5"
  84. #Update the name of the quality profile.
  85. if parser["containers"]["3"] in _RENAMED_MATERIAL_PROFILES:
  86. parser["containers"]["3"] = _RENAMED_MATERIAL_PROFILES[parser["containers"]["3"]]
  87. result = io.StringIO()
  88. parser.write(result)
  89. return [filename], [result.getvalue()]
  90. ## Upgrades instance containers to have the new version
  91. # number.
  92. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  93. parser = configparser.ConfigParser(interpolation = None)
  94. parser.read_string(serialized)
  95. # Update version number.
  96. parser["general"]["version"] = "4"
  97. parser["metadata"]["setting_version"] = "5"
  98. self._resetConcentric3DInfillPattern(parser)
  99. if "values" in parser:
  100. for deleted_setting in deleted_settings:
  101. if deleted_setting not in parser["values"]:
  102. continue
  103. del parser["values"][deleted_setting]
  104. for setting_key in changed_settings:
  105. if setting_key not in parser["values"]:
  106. continue
  107. if parser["values"][setting_key] == changed_settings[setting_key]:
  108. parser["values"][setting_key] = updated_settings[setting_key]
  109. result = io.StringIO()
  110. parser.write(result)
  111. return [filename], [result.getvalue()]
  112. def _resetConcentric3DInfillPattern(self, parser: configparser.ConfigParser) -> None:
  113. if "values" not in parser:
  114. return
  115. # Reset the patterns which are concentric 3d
  116. for key in ("infill_pattern",
  117. "support_pattern",
  118. "support_interface_pattern",
  119. "support_roof_pattern",
  120. "support_bottom_pattern",
  121. ):
  122. if key not in parser["values"]:
  123. continue
  124. if parser["values"][key] == "concentric_3d":
  125. del parser["values"][key]