Browse Source

Move translateVariant to VersionUpgrade21to22

Also make it a dictionary look-up, like the rest, instead of a series of if-statements.

Contributes to issue CURA-844.
Ghostkeeper 8 years ago
parent
commit
93041191c2

+ 1 - 24
plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py

@@ -70,30 +70,7 @@ class MachineInstance:
         type_name = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._type_name)
         active_profile = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
         active_material = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_material_name)
-        if type_name == "ultimaker2_plus":
-            if self._variant_name == "0.25 mm":
-                variant = "ultimaker2_plus_0.25"
-            elif self._variant_name == "0.4 mm":
-                variant = "ultimaker2_plus_0.4"
-            elif self._variant_name == "0.6 mm":
-                variant = "ultimaker2_plus_0.6"
-            elif self._variant_name == "0.8 mm":
-                variant = "ultimaker2_plus_0.8"
-            else:
-                variant = self._variant_name
-        elif type_name == "ultimaker2_extended_plus":
-            if self._variant_name == "0.25 mm":
-                variant = "ultimaker2_extended_plus_0.25"
-            elif self._variant_name == "0.4 mm":
-                variant = "ultimaker2_extended_plus_0.4"
-            elif self._variant_name == "0.6 mm":
-                variant = "ultimaker2_extended_plus_0.6"
-            elif self._variant_name == "0.8 mm":
-                variant = "ultimaker2_extended_plus_0.8"
-            else:
-                variant = self._variant_name
-        else:
-            variant = self._variant_name
+        variant = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._variant_name, type_name)
 
         containers = [
             self._name,

+ 30 - 1
plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py

@@ -26,6 +26,23 @@ _setting_name_translation = {
     "speed_support_lines": "speed_support_infill"
 }
 
+##  How to translate variants of specific machines from the old version to the
+#   new.
+_variant_translation = {
+    "ultimaker2_plus": {
+        "0.25 mm": "ultimaker2_plus_0.25",
+        "0.4 mm": "ultimaker2_plus_0.4",
+        "0.6 mm": "ultimaker2_plus_0.6",
+        "0.8 mm": "ultimaker2_plus_0.8"
+    },
+    "ultimaker2_extended_plus": {
+        "0.25 mm": "ultimaker2_extended_plus_0.25",
+        "0.4 mm": "ultimaker2_extended_plus_0.4",
+        "0.6 mm": "ultimaker2_extended_plus_0.6",
+        "0.8 mm": "ultimaker2_extended_plus_0.8"
+    }
+}
+
 ##  Converts configuration from Cura 2.1's file formats to Cura 2.2's.
 #
 #   It converts the machine instances and profiles.
@@ -123,4 +140,16 @@ class VersionUpgrade21to22(VersionUpgrade):
     def translateSettingName(setting):
         if setting in _setting_name_translation:
             return _setting_name_translation[setting]
-        return setting #Doesn't need to be translated.
+        return setting #Doesn't need to be translated.
+
+    ##  Translates a variant name for the change from Cura 2.1 to 2.2
+    #
+    #   \param variant The name of a variant in Cura 2.1.
+    #   \param machine The name of the machine this variant is part of in Cura
+    #   2.2's naming.
+    #   \return The name of the corresponding variant in Cura 2.2.
+    @staticmethod
+    def translateVariant(variant, machine):
+        if machine in _variant_translation and variant in _variant_translation[machine]:
+            return _variant_translation[machine][variant]
+        return variant