VersionUpgrade43to44.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import configparser
  2. from typing import Tuple, List
  3. import io
  4. from UM.VersionUpgrade import VersionUpgrade
  5. from UM.Util import parseBool # To parse whether the Alternate Skin Rotations function is activated.
  6. _renamed_container_id_map = {
  7. "ultimaker2_0.25": "ultimaker2_olsson_0.25",
  8. "ultimaker2_0.4": "ultimaker2_olsson_0.4",
  9. "ultimaker2_0.6": "ultimaker2_olsson_0.6",
  10. "ultimaker2_0.8": "ultimaker2_olsson_0.8",
  11. "ultimaker2_extended_0.25": "ultimaker2_extended_olsson_0.25",
  12. "ultimaker2_extended_0.4": "ultimaker2_extended_olsson_0.4",
  13. "ultimaker2_extended_0.6": "ultimaker2_extended_olsson_0.6",
  14. "ultimaker2_extended_0.8": "ultimaker2_extended_olsson_0.8",
  15. # HMS434 "extra coarse", "super coarse", and "ultra coarse" are removed.
  16. "hms434_global_Extra_Coarse_Quality": "hms434_global_Normal_Quality",
  17. "hms434_global_Super_Coarse_Quality": "hms434_global_Normal_Quality",
  18. "hms434_global_Ultra_Coarse_Quality": "hms434_global_Normal_Quality",
  19. # HMS434 "0.25", "0.6", "1.2", and "1.5" nozzles are removed.
  20. "hms434_0.25tpnozzle": "hms434_0.4tpnozzle",
  21. "hms434_0.6tpnozzle": "hms434_0.4tpnozzle",
  22. "hms434_1.2tpnozzle": "hms434_0.4tpnozzle",
  23. "hms434_1.5tpnozzle": "hms434_0.4tpnozzle",
  24. }
  25. class VersionUpgrade43to44(VersionUpgrade):
  26. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  27. """Upgrades Preferences to have the new version number.
  28. This renames the renamed settings in the list of visible settings.
  29. """
  30. parser = configparser.ConfigParser(interpolation = None)
  31. parser.read_string(serialized)
  32. # Update version number.
  33. parser["metadata"]["setting_version"] = "10"
  34. result = io.StringIO()
  35. parser.write(result)
  36. return [filename], [result.getvalue()]
  37. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  38. """Upgrades instance containers to have the new version number.
  39. This renames the renamed settings in the containers.
  40. """
  41. parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
  42. parser.read_string(serialized)
  43. # Update version number.
  44. parser["metadata"]["setting_version"] = "10"
  45. # Intent profiles were added, so the quality changes should match with no intent (so "default")
  46. if parser["metadata"].get("type", "") == "quality_changes":
  47. parser["metadata"]["intent_category"] = "default"
  48. if "values" in parser:
  49. # Alternate skin rotation should be translated to top/bottom line directions.
  50. if "skin_alternate_rotation" in parser["values"] and parseBool(parser["values"]["skin_alternate_rotation"]):
  51. parser["values"]["skin_angles"] = "[45, 135, 0, 90]"
  52. # Unit of adaptive layers topography size changed.
  53. if "adaptive_layer_height_threshold" in parser["values"]:
  54. val = parser["values"]["adaptive_layer_height_threshold"]
  55. if val.startswith("="):
  56. val = val[1:]
  57. val = "=({val}) / 1000".format(val = val) # Convert microns to millimetres. Works even if the profile contained a formula.
  58. parser["values"]["adaptive_layer_height_threshold"] = val
  59. result = io.StringIO()
  60. parser.write(result)
  61. return [filename], [result.getvalue()]
  62. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  63. """Upgrades stacks to have the new version number."""
  64. parser = configparser.ConfigParser(interpolation = None)
  65. parser.read_string(serialized)
  66. # Update version number.
  67. if "metadata" not in parser:
  68. parser["metadata"] = {}
  69. parser["metadata"]["setting_version"] = "10"
  70. if "containers" in parser:
  71. # With the ContainerTree refactor, UM2 with Olsson block got moved to a separate definition.
  72. if "6" in parser["containers"]:
  73. if parser["containers"]["6"] == "ultimaker2":
  74. if "metadata" in parser and "has_variants" in parser["metadata"] and parser["metadata"]["has_variants"] == "True": # This is an Olsson block upgraded UM2!
  75. parser["containers"]["6"] = "ultimaker2_olsson"
  76. del parser["metadata"]["has_variants"]
  77. elif parser["containers"]["6"] == "ultimaker2_extended":
  78. if "metadata" in parser and "has_variants" in parser["metadata"] and parser["metadata"]["has_variants"] == "True": # This is an Olsson block upgraded UM2E!
  79. parser["containers"]["6"] = "ultimaker2_extended_olsson"
  80. del parser["metadata"]["has_variants"]
  81. # We should only have 6 levels when we start.
  82. if "7" in parser["containers"]:
  83. return ([], [])
  84. # We added the intent container in Cura 4.4. This means that all other containers move one step down.
  85. parser["containers"]["7"] = parser["containers"]["6"]
  86. parser["containers"]["6"] = parser["containers"]["5"]
  87. parser["containers"]["5"] = parser["containers"]["4"]
  88. parser["containers"]["4"] = parser["containers"]["3"]
  89. parser["containers"]["3"] = parser["containers"]["2"]
  90. parser["containers"]["2"] = "empty_intent"
  91. # Update renamed containers
  92. for key, value in parser["containers"].items():
  93. if value in _renamed_container_id_map:
  94. parser["containers"][key] = _renamed_container_id_map[value]
  95. result = io.StringIO()
  96. parser.write(result)
  97. return [filename], [result.getvalue()]