Browse Source

Update version upgrade system for new quality-changes profiles

The quality profile now sometimes gets updated to a quality profile, and sometimes to a quality-changes profile, depending on whether the profile is built-in or not.

Contributes to issue CURA-2006.
Ghostkeeper 8 years ago
parent
commit
d046cd764a

+ 29 - 4
plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py

@@ -77,10 +77,34 @@ class MachineInstance:
         active_material = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateMaterial(self._active_material_name)
         variant = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._variant_name, type_name)
         variant_materials = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariantForMaterials(self._variant_name, type_name)
-        active_profile = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
+
+        #Convert to quality profile if we have one of the built-in profiles, otherwise convert to a quality-changes profile.
+        if has_machine_qualities:
+            material_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateMaterialForProfiles(self._active_material_name)
+            variant_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariantForProfiles(self._variant_name)
+            if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles(): #This is a built-in profile name. Convert to quality.
+                quality_name = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
+            else:
+                quality_name = "normal" #We have a quality-changes profile. Base it on normal, since we have no information to indicate which one it should be based on.
+            if self._active_material_name == "PLA" and self._type_name == "ultimaker2plus": #UM2+ uses a different naming scheme for PLA profiles.
+                active_quality = material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
+            else:
+                printer_name_in_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinterForProfile(self._type_name)
+                active_quality = printer_name_in_quality + "_" + material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
+
+            if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles():
+                active_quality_changes = "empty_quality_changes"
+            else: #No built-in profile. Translate this profile to quality-changes.
+                active_quality_changes = material_name_in_quality + "_" + variant_name_in_quality + "_" + quality_name
+        else:
+            if self._active_profile_name in VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.builtInProfiles():
+                active_quality = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name)
+                active_quality_changes = "empty_quality_changes"
+            else:
+                active_quality = "normal"
+                active_quality_changes = self._active_profile_name
+
         if has_machine_qualities: #This machine now has machine-quality profiles.
-            if active_material == "pla"
-            active_profile += "_" + active_material + "_" + variant
             active_material += "_" + variant_materials #That means that the profile was split into multiple.
             current_settings = "empty" #The profile didn't know the definition ID when it was upgraded, so it will have been invalid. Sorry, your current settings are lost now.
         else:
@@ -88,7 +112,8 @@ class MachineInstance:
 
         containers = [
             current_settings,
-            active_profile,
+            active_quality_changes,
+            active_quality,
             active_material,
             variant,
             type_name

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

@@ -43,11 +43,27 @@ _material_translations = {
     "TPU": "generic_tpu",
 }
 
+##  How to translate material names for in the profile names.
+_material_translations_profiles = {
+    "PLA": "pla",
+    "ABS": "abs",
+    "CPE": "cpe",
+    "CPE+": "cpep",
+    "Nylon": "nylon",
+    "PC": "pc",
+    "TPU": "tpu",
+}
+
 ##  How to translate printer names from the old version to the new.
 _printer_translations = {
     "ultimaker2plus": "ultimaker2_plus"
 }
 
+_printer_translations_profiles = {
+    "ultimaker2plus": "um2p", #Does NOT get included in PLA profiles!
+    "ultimaker2_extended_plus": "um2ep" #Has no profiles for CPE+, Nylon, PC and TPU!
+}
+
 ##  How to translate profile names from the old version to the new.
 _profile_translations = {
     "Low Quality": "low",
@@ -92,6 +108,14 @@ _variant_translations = {
     }
 }
 
+##  How to translate variant names for in the profile names.
+_variant_translations_profiles = {
+    "0.25 mm": "0.25",
+    "0.4 mm": "0.4",
+    "0.6 mm": "0.6",
+    "0.8 mm": "0.8"
+}
+
 ##  Cura 2.2's material profiles use a different naming scheme for variants.
 #
 #   Getting pretty stressed out by this sort of thing...
@@ -126,6 +150,14 @@ class VersionUpgrade21to22(VersionUpgrade):
         parser.read_string(serialised)
         return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
 
+    ##  Gets the set of built-in profile names in Cura 2.1.
+    #
+    #   This is required to test if profiles should be converted to a quality
+    #   profile or a quality-changes profile.
+    @staticmethod
+    def builtInProfiles():
+        return _profile_translations.keys()
+
     ##  Gets a set of the machines which now have per-material quality profiles.
     #
     #   \return A set of machine identifiers.
@@ -150,7 +182,7 @@ class VersionUpgrade21to22(VersionUpgrade):
     ##  Converts preferences from format version 2 to version 3.
     #
     #   \param serialised The serialised preferences file in version 2.
-    #   \param filename THe supposed file name of the preferences file, without
+    #   \param filename The supposed file name of the preferences file, without
     #   extension.
     #   \return A tuple containing the new filename and the serialised
     #   preferences in version 3, or None if the input was not of the correct
@@ -174,6 +206,28 @@ class VersionUpgrade21to22(VersionUpgrade):
             return filename, None
         return profile.export()
 
+    ##  Translates a material name for the change from Cura 2.1 to 2.2.
+    #
+    #   \param material A material name in Cura 2.1.
+    #   \return The name of the corresponding material in Cura 2.2.
+    @staticmethod
+    def translateMaterial(material):
+        if material in _material_translations:
+            return _material_translations[material]
+        return material
+
+    ##  Translates a material name for the change from Cura 2.1 to 2.2 in
+    #   quality profile names.
+    #
+    #   \param material A material name in Cura 2.1.
+    #   \return The name of the corresponding material in the quality profiles
+    #   in Cura 2.2.
+    @staticmethod
+    def translateMaterialForProfiles(material):
+        if material in _material_translations_profiles:
+            return _material_translations_profiles[material]
+        return material
+
     ##  Translates a printer name that might have changed since the last
     #   version.
     #
@@ -185,6 +239,17 @@ class VersionUpgrade21to22(VersionUpgrade):
             return _printer_translations[printer]
         return printer #Doesn't need to be translated.
 
+    ##  Translates a printer name for the change from Cura 2.1 to 2.2 in quality
+    #   profile names.
+    #
+    #   \param printer A printer name in 2.1.
+    #   \return The name of the corresponding printer in Cura 2.2.
+    @staticmethod
+    def translatePrinterForProfile(printer):
+        if printer in _printer_translations_profiles:
+            return _printer_translations_profiles[printer]
+        return printer
+
     ##  Translates a built-in profile name that might have changed since the
     #   last version.
     #
@@ -250,4 +315,16 @@ class VersionUpgrade21to22(VersionUpgrade):
     def translateVariantForMaterials(variant, machine):
         if machine in _variant_translations_materials and variant in _variant_translations_materials[machine]:
             return _variant_translations_materials[machine][variant]
+        return variant
+
+    ##  Translates a variant name for the change from Cura 2.1 to 2.2 in quality
+    #   profiles.
+    #
+    #   \param variant The name of the variant in Cura 2.1.
+    #   \return The name of the corresponding variant for in quality profiles in
+    #   Cura 2.2.
+    @staticmethod
+    def translateVariantForProfiles(variant):
+        if variant in _variant_translations_profiles:
+            return _variant_translations_profiles[variant]
         return variant