Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostas Karmas <konskarm@gmail.com>2021-05-10 18:40:05 +0300
committerKostas Karmas <konskarm@gmail.com>2021-05-10 18:40:05 +0300
commitcaaf5ccd149d6bac6cb6cea2de5c2a17f64f5c43 (patch)
treec1cae021dbc8a18b34fa116a913a3c50c6caaed0 /plugins/VersionUpgrade/VersionUpgrade49to410
parent2645dc880eb4617fc52ecc50515fe6b30d71f335 (diff)
Add version upgrader from 4.9 to 4.10 for twtrees
Makes sure to upgrade the old twotrees_bluer into the new two_trees_bluer definition. CURA-8212
Diffstat (limited to 'plugins/VersionUpgrade/VersionUpgrade49to410')
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py158
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade49to410/__init__.py55
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade49to410/plugin.json8
3 files changed, 221 insertions, 0 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py b/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py
new file mode 100644
index 0000000000..00ab8c2342
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py
@@ -0,0 +1,158 @@
+# Copyright (c) 2019 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+import configparser
+import io
+import os.path # To get the file ID.
+from typing import Dict, List, Tuple
+
+from UM.VersionUpgrade import VersionUpgrade
+
+
+class VersionUpgrade49to410(VersionUpgrade):
+ """
+ Upgrades configurations from the state they were in at version 4.9 to the state they should be in at version 4.10.
+ """
+
+ _renamed_profiles = {
+ # Definitions.
+ "twotrees_bluer" : "two_trees_bluer",
+
+ # Upgrade for people who had the original TwoTrees Bluer profiles from 4.9 and earlier.
+ "twotrees_bluer_extruder_0": "two_trees_base_extruder_0",
+ "twotrees_bluer_extruder_1": "two_trees_base_extruder_0"
+ }
+
+ _quality_changes_to_two_trees_base = {
+ "twotrees_bluer_extruder_0",
+ "twotrees_bluer_extruder_1",
+ "twotrees_bluer"
+ }
+
+ # Default variant to select for legacy TwoTrees printers, now that we have variants.
+ _default_variants = {
+ "twotrees_bluer_extruder_0" : "two_trees_bluer_0.4",
+ "twotrees_bluer_extruder_1" : "two_trees_bluer_0.4"
+ }
+
+ _two_trees_bluer_quality_type_conversion = {
+ "high" : "ultra",
+ "normal" : "super",
+ "fast" : "standard",
+ "draft" : "standard",
+ "extra_fast" : "low",
+ "coarse" : "draft",
+ "extra_coarse": "draft"
+ }
+
+ _two_trees_quality_per_material = {
+ # Since legacy Creality printers didn't have different variants, we always pick the 0.4mm variant.
+ "generic_abs_175" : {
+ "high" : "two_trees_0.4_ABS_super",
+ "normal" : "two_trees_0.4_ABS_super",
+ "fast" : "two_trees_0.4_ABS_super",
+ "draft" : "two_trees_0.4_ABS_standard",
+ "extra_fast" : "two_trees_0.4_ABS_low",
+ "coarse" : "two_trees_0.4_ABS_low",
+ "extra_coarse": "two_trees_0.4_ABS_low"
+ },
+ "generic_petg_175": {
+ "high" : "two_trees_0.4_PETG_super",
+ "normal" : "two_trees_0.4_PETG_super",
+ "fast" : "two_trees_0.4_PETG_super",
+ "draft" : "two_trees_0.4_PETG_standard",
+ "extra_fast" : "two_trees_0.4_PETG_low",
+ "coarse" : "two_trees_0.4_PETG_low",
+ "extra_coarse": "two_trees_0.4_PETG_low"
+ },
+ "generic_pla_175" : {
+ "high" : "two_trees_0.4_PLA_super",
+ "normal" : "two_trees_0.4_PLA_super",
+ "fast" : "two_trees_0.4_PLA_super",
+ "draft" : "two_trees_0.4_PLA_standard",
+ "extra_fast" : "two_trees_0.4_PLA_low",
+ "coarse" : "two_trees_0.4_PLA_low",
+ "extra_coarse": "two_trees_0.4_PLA_low"
+ },
+ "generic_tpu_175" : {
+ "high" : "two_trees_0.4_TPU_super",
+ "normal" : "two_trees_0.4_TPU_super",
+ "fast" : "two_trees_0.4_TPU_super",
+ "draft" : "two_trees_0.4_TPU_standard",
+ "extra_fast" : "two_trees_0.4_TPU_standard",
+ "coarse" : "two_trees_0.4_TPU_standard",
+ "extra_coarse": "two_trees_0.4_TPU_standard"
+ },
+ "empty_material" : { # For the global stack.
+ "high" : "two_trees_global_super",
+ "normal" : "two_trees_global_super",
+ "fast" : "two_trees_global_super",
+ "draft" : "two_trees_global_standard",
+ "extra_fast" : "two_trees_global_low",
+ "coarse" : "two_trees_global_low",
+ "extra_coarse": "two_trees_global_low"
+ }
+ }
+
+ def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
+ """Upgrades instance containers to have the new version number.
+
+ This renames the renamed settings in the containers.
+ """
+ parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
+ parser.read_string(serialized)
+ print(filename)
+
+ # Update setting version number.
+ parser["metadata"]["setting_version"] = "17"
+
+ # Certain instance containers (such as definition changes) reference to a certain definition container
+ # Since a number of those changed name, we also need to update those.
+ old_definition = parser["general"]["definition"]
+ if old_definition in self._renamed_profiles:
+ parser["general"]["definition"] = self._renamed_profiles[old_definition]
+
+ # For quality-changes profiles made for TwoTrees Bluer printers, change the definition to the two_trees_base and make sure that the quality is something we have a profile for.
+ if parser["metadata"].get("type", "") == "quality_changes":
+ for possible_printer in self._quality_changes_to_two_trees_base:
+ if os.path.basename(filename).startswith(possible_printer + "_"):
+ parser["general"]["definition"] = "two_trees_base"
+ parser["metadata"]["quality_type"] = self._two_trees_bluer_quality_type_conversion.get(parser["metadata"]["quality_type"], "standard")
+ break
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()]
+
+ def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
+ """Upgrades stacks to have the new version number."""
+
+ parser = configparser.ConfigParser(interpolation = None)
+ parser.read_string(serialized)
+
+ # Update setting version number.
+ parser["metadata"]["setting_version"] = "17"
+
+ # Change renamed profiles.
+ if "containers" in parser:
+ # For legacy TwoTrees printers, change the variant to 0.4.
+ definition_id = parser["containers"]["7"]
+ material_id = parser["containers"]["4"]
+ old_quality_id = parser["containers"]["3"]
+ if parser["metadata"].get("type", "machine") == "extruder_train":
+ if parser["containers"]["5"] == "empty_variant":
+ if definition_id in self._default_variants:
+ parser["containers"]["5"] = self._default_variants[definition_id]
+
+ # Also change the quality to go along with it.
+ if material_id in self._two_trees_quality_per_material and old_quality_id in self._two_trees_quality_per_material[material_id]:
+ parser["containers"]["3"] = self._two_trees_quality_per_material[material_id][old_quality_id]
+ stack_copy = {} # type: Dict[str, str] # Make a copy so that we don't modify the dict we're iterating over.
+ stack_copy.update(parser["containers"])
+ for position, profile_id in stack_copy.items():
+ if profile_id in self._renamed_profiles:
+ parser["containers"][position] = self._renamed_profiles[profile_id]
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()]
diff --git a/plugins/VersionUpgrade/VersionUpgrade49to410/__init__.py b/plugins/VersionUpgrade/VersionUpgrade49to410/__init__.py
new file mode 100644
index 0000000000..0d5128473f
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade49to410/__init__.py
@@ -0,0 +1,55 @@
+# Copyright (c) 2020 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from typing import Any, Dict, TYPE_CHECKING
+
+from . import VersionUpgrade49to410
+
+if TYPE_CHECKING:
+ from UM.Application import Application
+
+upgrade = VersionUpgrade49to410.VersionUpgrade49to410()
+
+
+def getMetaData() -> Dict[str, Any]:
+ return {
+ "version_upgrade": {
+ # From To Upgrade function
+ ("machine_stack", 5000016): ("machine_stack", 5000017, upgrade.upgradeStack),
+ ("extruder_train", 5000016): ("extruder_train", 5000017, upgrade.upgradeStack),
+ ("definition_changes", 4000016): ("definition_changes", 4000017, upgrade.upgradeInstanceContainer),
+ ("quality_changes", 4000016): ("quality_changes", 4000017, upgrade.upgradeInstanceContainer),
+ ("quality", 4000016): ("quality", 4000017, upgrade.upgradeInstanceContainer),
+ ("user", 4000016): ("user", 4000017, upgrade.upgradeInstanceContainer),
+ },
+ "sources": {
+ "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"}
+ },
+ "quality": {
+ "get_version": upgrade.getCfgVersion,
+ "location": {"./quality"}
+ },
+ "user": {
+ "get_version": upgrade.getCfgVersion,
+ "location": {"./user"}
+ }
+ }
+ }
+
+
+def register(app: "Application") -> Dict[str, Any]:
+ return {"version_upgrade": upgrade}
diff --git a/plugins/VersionUpgrade/VersionUpgrade49to410/plugin.json b/plugins/VersionUpgrade/VersionUpgrade49to410/plugin.json
new file mode 100644
index 0000000000..bd657afeb6
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade49to410/plugin.json
@@ -0,0 +1,8 @@
+{
+ "name": "Version Upgrade 4.9 to 4.10",
+ "author": "Ultimaker B.V.",
+ "version": "1.0.0",
+ "description": "Upgrades configurations from Cura 4.9 to Cura 4.10.",
+ "api": "7.5.0",
+ "i18n-catalog": "cura"
+}