Browse Source

Update setting_version to 5 and add 34 -> 40 upgrade

CURA-5450

Also update setting_version for all qualities and variants.
Lipu Fei 6 years ago
parent
commit
b81635ac8e

+ 1 - 1
cura/CuraApplication.py

@@ -123,7 +123,7 @@ class CuraApplication(QtApplication):
     # SettingVersion represents the set of settings available in the machine/extruder definitions.
     # SettingVersion represents the set of settings available in the machine/extruder definitions.
     # You need to make sure that this version number needs to be increased if there is any non-backwards-compatible
     # You need to make sure that this version number needs to be increased if there is any non-backwards-compatible
     # changes of the settings.
     # changes of the settings.
-    SettingVersion = 4
+    SettingVersion = 5
 
 
     Created = False
     Created = False
 
 

+ 91 - 0
plugins/VersionUpgrade/VersionUpgrade34to40/VersionUpgrade34to40.py

@@ -0,0 +1,91 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+import configparser
+import io
+
+from UM.VersionUpgrade import VersionUpgrade
+
+
+##  Upgrades configurations from the state they were in at version 3.3 to the
+#   state they should be in at version 3.4.
+class VersionUpgrade34to40(VersionUpgrade):
+
+    ##  Gets the version number from a CFG file in Uranium's 3.3 format.
+    #
+    #   Since the format may change, this is implemented for the 3.3 format only
+    #   and needs to be included in the version upgrade system rather than
+    #   globally in Uranium.
+    #
+    #   \param serialised The serialised form of a CFG file.
+    #   \return The version number stored in the CFG file.
+    #   \raises ValueError The format of the version number in the file is
+    #   incorrect.
+    #   \raises KeyError The format of the file is incorrect.
+    def getCfgVersion(self, serialised):
+        parser = configparser.ConfigParser(interpolation = None)
+        parser.read_string(serialised)
+        format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
+        setting_version = int(parser.get("metadata", "setting_version", fallback = 0))
+        return format_version * 1000000 + setting_version
+
+    ##  Upgrades Preferences to have the new version number.
+    def upgradePreferences(self, serialized, filename):
+        parser = configparser.ConfigParser(interpolation = None)
+        parser.read_string(serialized)
+
+        # Update version number.
+        parser["general"]["version"] = "4"
+        if "metadata" not in parser:
+            parser["metadata"] = {}
+        parser["metadata"]["setting_version"] = "5"
+
+        result = io.StringIO()
+        parser.write(result)
+        return [filename], [result.getvalue()]
+
+    ##  Upgrades stacks to have the new version number.
+    def upgradeStack(self, serialized, filename):
+        parser = configparser.ConfigParser(interpolation = None)
+        parser.read_string(serialized)
+
+        # Update version number.
+        parser["general"]["version"] = "4"
+        parser["metadata"]["setting_version"] = "5"
+
+        result = io.StringIO()
+        parser.write(result)
+        return [filename], [result.getvalue()]
+
+    ##  Upgrades instance containers to have the new version
+    #   number.
+    def upgradeInstanceContainer(self, serialized, filename):
+        parser = configparser.ConfigParser(interpolation = None)
+        parser.read_string(serialized)
+
+        # Update version number.
+        parser["general"]["version"] = "4"
+        parser["metadata"]["setting_version"] = "5"
+
+        self._resetConcentric3DInfillPattern(parser)
+
+        result = io.StringIO()
+        parser.write(result)
+        return [filename], [result.getvalue()]
+
+    def _resetConcentric3DInfillPattern(self, parser):
+        if "values" not in parser:
+            return
+
+        # Reset the patterns which are concentric 3d
+        for key in ("infill_pattern",
+                    "support_pattern",
+                    "support_interface_pattern",
+                    "support_roof_pattern",
+                    "support_bottom_pattern",
+                    ):
+            if key not in parser["values"]:
+                continue
+            if parser["values"][key] == "concentric_3d":
+                del parser["values"][key]
+

+ 52 - 0
plugins/VersionUpgrade/VersionUpgrade34to40/__init__.py

@@ -0,0 +1,52 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from . import VersionUpgrade34to40
+
+upgrade = VersionUpgrade34to40.VersionUpgrade34to40()
+
+
+def getMetaData():
+    return {
+        "version_upgrade": {
+            # From                           To                              Upgrade function
+            ("preferences", 6000004):        ("preferences", 6000005,        upgrade.upgradePreferences),
+
+            ("definition_changes", 4000004): ("definition_changes", 4000005, upgrade.upgradeInstanceContainer),
+            ("quality_changes", 4000004):    ("quality_changes", 4000005,    upgrade.upgradeInstanceContainer),
+            ("user", 4000004):               ("user", 4000005,               upgrade.upgradeInstanceContainer),
+
+            ("machine_stack", 4000005):      ("machine_stack", 4000005,      upgrade.upgradeStack),
+            ("extruder_train", 4000005):     ("extruder_train", 4000005,     upgrade.upgradeStack),
+        },
+        "sources": {
+            "preferences": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"."}
+            },
+            "machine_stack": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"./machine_instances"}
+            },
+            "extruder_train": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"./extruders"}
+            },
+            "definition_changes": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"./definition_changes"}
+            },
+            "quality_changes": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"./quality_changes"}
+            },
+            "user": {
+                "get_version": upgrade.getCfgVersion,
+                "location": {"./user"}
+            }
+        }
+    }
+
+
+def register(app):
+    return { "version_upgrade": upgrade }

+ 8 - 0
plugins/VersionUpgrade/VersionUpgrade34to40/plugin.json

@@ -0,0 +1,8 @@
+ {
+    "name": "Version Upgrade 3.4 to 4.0",
+    "author": "Ultimaker B.V.",
+    "version": "1.0.0",
+    "description": "Upgrades configurations from Cura 3.4 to Cura 4.0.",
+    "api": 4,
+    "i18n-catalog": "cura"
+}

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_fast.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri3
 definition = abax_pri3
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = normal
 quality_type = normal
 weight = -1
 weight = -1

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_high.inst.cfg

@@ -4,7 +4,7 @@ name = Extra Fine
 definition = abax_pri3
 definition = abax_pri3
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = high
 quality_type = high
 weight = 1
 weight = 1

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_normal.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri3
 definition = abax_pri3
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = normal
 quality_type = normal
 weight = 0
 weight = 0

+ 1 - 1
resources/quality/abax_pri5/apri5_pla_fast.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri5
 definition = abax_pri5
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = normal
 quality_type = normal
 weight = -1
 weight = -1

+ 1 - 1
resources/quality/abax_pri5/apri5_pla_high.inst.cfg

@@ -4,7 +4,7 @@ name = Extra Fine
 definition = abax_pri5
 definition = abax_pri5
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = high
 quality_type = high
 weight = 1
 weight = 1

+ 1 - 1
resources/quality/abax_pri5/apri5_pla_normal.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri5
 definition = abax_pri5
 
 
 [metadata]
 [metadata]
-setting_version = 4
+setting_version = 5
 type = quality
 type = quality
 quality_type = normal
 quality_type = normal
 weight = 0
 weight = 0

Some files were not shown because too many files changed in this diff