Extrapolate settings translations

It is now in one place. Or rather, two: There is another function to translate only setting names.

Contributes to issue CURA-844.
This commit is contained in:
Ghostkeeper 2016-04-20 12:58:17 +02:00 committed by Ghostkeeper
parent f7be4831b8
commit cce642a3e1
3 changed files with 38 additions and 13 deletions

View file

@ -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()

View file

@ -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:]:

View file

@ -31,3 +31,34 @@ class VersionUpgrade21to22(VersionUpgrade):
if not profile: #Invalid file format.
return None
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