diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 5e90e27f17..4b9d7b8be5 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -58,6 +58,7 @@ class MachineInstance: # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def exportVersion2(self): + import VersionUpgrade21to22 #Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) #Build a config file in the form of version 2. config.add_section("general") @@ -73,12 +74,9 @@ class MachineInstance: if self._active_material_name: config.set("general", "material", self._active_material_name) + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) config.add_section("machine_settings") for key, value in self._machine_setting_overrides.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("machine_settings", key, str(value)) output = io.StringIO() diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index a70293f8b9..8a461dad6a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -73,6 +73,7 @@ class Profile: # \return A serialised form of this profile, serialised in version 2 of # the file format. def exportVersion2(self): + import VersionUpgrade21to22 #Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) config.add_section("general") @@ -92,24 +93,19 @@ class Profile: config.set("general", "material", self._material_name) if self._settings: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) config.add_section("settings") for key, value in self._settings.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("settings", key, str(value)) if self._changed_settings_defaults: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults) config.add_section("defaults") for key, value in self._changed_settings_defaults.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("defaults", key, str(value)) if self._disabled_settings_defaults: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) config.add_section("disabled_defaults") disabled_defaults_string = str(self._disabled_settings_defaults[0]) #Must be at least 1 item, otherwise we wouldn't enter this if statement. for item in self._disabled_settings_defaults[1:]: diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 385001a3e6..cc248d3d51 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -30,4 +30,35 @@ class VersionUpgrade21to22(VersionUpgrade): profile = Profile.importVersion1(serialised) if not profile: #Invalid file format. return None - return profile.exportVersion2() \ No newline at end of file + return profile.exportVersion2() + + ## Translates settings for the change from Cura 2.1 to 2.2. + # + # Each setting is changed in-place in the provided dictionary. This changes + # the input parameter. + # + # \param settings A dictionary of settings (as key-value pairs) to update. + # \return The same dictionary. + @staticmethod + def translateSettings(settings): + for key, value in settings.items(): + if key == "speed_support_lines": #Setting key was changed for 2.2. + del settings[key] + settings["speed_support_infill"] = value + if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + settings[key] = "off" if (value == "False") else "all" + return settings + + ## Translates setting names for the change from Cura 2.1 to 2.2. + # + # The setting names are changed in-place in the provided list. This changes + # the input parameter. + # + # \param settings A list of setting names to update. + # \return The same list. + @staticmethod + def translateSettingNames(settings): + for i in range(0, len(settings)): + if settings[i] == "speed_support_lines": + settings[i] = "speed_support_infill" + return settings \ No newline at end of file