VersionUpgrade21to22.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin.
  4. from . import MachineInstance # To upgrade machine instances.
  5. from . import Profile # To upgrade profiles.
  6. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's.
  7. #
  8. # It converts the machine instances and profiles.
  9. class VersionUpgrade21to22(VersionUpgrade):
  10. ## Converts machine instances from format version 1 to version 2.
  11. #
  12. # \param serialised The serialised machine instance in version 1.
  13. # \return The serialised machine instance in version 2, or None if the
  14. # input was not of the correct format.
  15. def upgradeMachineInstance(self, serialised):
  16. machine_instance = MachineInstance.importFrom(serialised)
  17. if not machine_instance: #Invalid file format.
  18. return None
  19. return machine_instance.exportTo()
  20. ## Converts profiles from format version 1 to version 2.
  21. #
  22. # \param serialised The serialised profile in version 1.
  23. # \return The serialised profile in version 2, or None if the input was
  24. # not of the correct format.
  25. def upgradeProfile(self, serialised):
  26. profile = Profile.importFrom(serialised)
  27. if not profile: # Invalid file format.
  28. return None
  29. return profile.exportTo()
  30. ## Translates settings for the change from Cura 2.1 to 2.2.
  31. #
  32. # Each setting is changed in-place in the provided dictionary. This
  33. # changes the input parameter.
  34. #
  35. # \param settings A dictionary of settings (as key-value pairs) to update.
  36. # \return The same dictionary.
  37. @staticmethod
  38. def translateSettings(settings):
  39. for key, value in settings.items():
  40. if key == "speed_support_lines": # Setting key was changed for 2.2.
  41. del settings[key]
  42. settings["speed_support_infill"] = value
  43. if key == "retraction_combing": # Combing was made into an enum instead of a boolean.
  44. settings[key] = "off" if (value == "False") else "all"
  45. return settings
  46. ## Translates setting names for the change from Cura 2.1 to 2.2.
  47. #
  48. # The setting names are changed in-place in the provided list. This changes
  49. # the input parameter.
  50. #
  51. # \param settings A list of setting names to update.
  52. # \return The same list.
  53. @staticmethod
  54. def translateSettingNames(settings):
  55. for i in range(0, len(settings)):
  56. if settings[i] == "speed_support_lines":
  57. settings[i] = "speed_support_infill"
  58. return settings