From 7cc62db81dea84e367586a925d5cff10937df2b8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 May 2016 14:06:07 +0200 Subject: [PATCH 1/5] Increment XRayView API number This plug-in still works, so this can be incremented without trouble. Contributes to issue CURA-1278. --- plugins/XRayView/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/XRayView/__init__.py b/plugins/XRayView/__init__.py index 277dc69b92..34e4761863 100644 --- a/plugins/XRayView/__init__.py +++ b/plugins/XRayView/__init__.py @@ -13,7 +13,7 @@ def getMetaData(): "author": "Ultimaker", "version": "1.0", "description": catalog.i18nc("@info:whatsthis", "Provides the X-Ray view."), - "api": 2 + "api": 3 }, "view": { "name": catalog.i18nc("@item:inlistbox", "X-Ray"), From 85ce8a719ed0bbafae04cafe83af3a81fb8fbcf3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 May 2016 16:16:25 +0200 Subject: [PATCH 2/5] Merge local with origin Contributes to issue CURA-1278. --- cura/CuraApplication.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index f328e83174..b95f6058b4 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -224,6 +224,7 @@ class CuraApplication(QtApplication): ## Handle loading of all plugin types (and the backend explicitly) # \sa PluginRegistery def _loadPlugins(self): + self._plugin_registry.addType("profile_reader", self._addProfileReader) self._plugin_registry.addPluginLocation(os.path.join(QtApplication.getInstallPrefix(), "lib", "cura")) if not hasattr(sys, "frozen"): self._plugin_registry.addPluginLocation(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "plugins")) @@ -711,3 +712,6 @@ class CuraApplication(QtApplication): job = ReadMeshJob(os.path.abspath(file)) job.finished.connect(self._onFileLoaded) job.start() + + def _addProfileReader(self, profile_reader): + pass \ No newline at end of file From 5a28eca2039bce9b6e8102c9330c3087ece9484a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 May 2016 16:16:55 +0200 Subject: [PATCH 3/5] Add profile reader plug-in type This type of plug-in will load a file as an instance container of the user profile type. Contributes to issue CURA-1278. --- cura/ProfileReader.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cura/ProfileReader.py diff --git a/cura/ProfileReader.py b/cura/ProfileReader.py new file mode 100644 index 0000000000..36bb2c7177 --- /dev/null +++ b/cura/ProfileReader.py @@ -0,0 +1,17 @@ +# Copyright (c) 2016 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +from UM.PluginObject import PluginObject + +## A type of plug-ins that reads profiles from a file. +# +# The profile is then stored as instance container of the type user profile. +class ProfileReader(PluginObject): + def __init__(self): + super().__init__() + + ## Read profile data from a file and return a filled profile. + # + # \return \type{Profile} The profile that was obtained from the file. + def read(self, file_name): + raise NotImplementedError("Profile reader plug-in was not correctly implemented. The read function was not implemented.") \ No newline at end of file From 117973ee25ddd7e4f3a63fd425118d8be8734538 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 May 2016 16:20:58 +0200 Subject: [PATCH 4/5] Add todo message for adding profile readers This should be done when we have a working profile manager again. Contributes to issue CURA-1278. --- cura/CuraApplication.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index b95f6058b4..c46833f6e0 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -714,4 +714,5 @@ class CuraApplication(QtApplication): job.start() def _addProfileReader(self, profile_reader): + # TODO: Add the profile reader to the list of plug-ins that can be used when importing profiles. pass \ No newline at end of file From 754932f83ad10c9ac045c240e3c838548040884d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 20 May 2016 16:22:00 +0200 Subject: [PATCH 5/5] Move LegacyProfileReader to new setting structure Untested as the profile manager is not functional at the moment. Contributes to issue CURA-1278. --- .../LegacyProfileReader/LegacyProfileReader.py | 16 +++++++++------- plugins/LegacyProfileReader/__init__.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 3daf360ee6..19154c9c5a 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -9,8 +9,9 @@ import os.path #For concatenating the path to the plugin and the relative path t from UM.Application import Application #To get the machine manager to create the new profile in. from UM.Logger import Logger #Logging errors. from UM.PluginRegistry import PluginRegistry #For getting the path to this plugin's directory. -from UM.Settings.Profile import Profile -from UM.Settings.ProfileReader import ProfileReader +from UM.Settings.DefinitionContainer import DefinitionContainer #For getting the current machine's defaults. +from UM.Settings.InstanceContainer import InstanceContainer #The new profile to make. +from cura.ProfileReader import ProfileReader #The plug-in type to implement. ## A plugin that reads profile data from legacy Cura versions. # @@ -66,7 +67,7 @@ class LegacyProfileReader(ProfileReader): if file_name.split(".")[-1] != "ini": return None Logger.log("i", "Importing legacy profile from file " + file_name + ".") - profile = Profile(machine_manager = Application.getInstance().getMachineManager(), read_only = False) #Create an empty profile. + profile = InstanceContainer("Imported Legacy Profile") #Create an empty profile. parser = configparser.ConfigParser(interpolation = None) try: @@ -103,23 +104,24 @@ class LegacyProfileReader(ProfileReader): if "target_version" not in dict_of_doom: Logger.log("e", "Dictionary of Doom has no target version. Is it the correct JSON file?") return None - if Profile.ProfileVersion != dict_of_doom["target_version"]: - Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the profile version (version %s)!", dict_of_doom["target_version"], str(Profile.ProfileVersion)) + if InstanceContainer.Version != dict_of_doom["target_version"]: + Logger.log("e", "Dictionary of Doom of legacy profile reader (version %s) is not in sync with the current instance container version (version %s)!", dict_of_doom["target_version"], str(InstanceContainer.Version)) return None if "translation" not in dict_of_doom: Logger.log("e", "Dictionary of Doom has no translation. Is it the correct JSON file?") return None + current_printer = Application.getInstance().getGlobalContainerStack().findContainer({ }, DefinitionContainer) for new_setting in dict_of_doom["translation"]: #Evaluate all new settings that would get a value from the translations. old_setting_expression = dict_of_doom["translation"][new_setting] compiled = compile(old_setting_expression, new_setting, "eval") try: new_value = eval(compiled, {"math": math}, legacy_settings) #Pass the legacy settings as local variables to allow access to in the evaluation. value_using_defaults = eval(compiled, {"math": math}, defaults) #Evaluate again using only the default values to try to see if they are default. - except Exception as e: #Probably some setting name that was missing or something else that went wrong in the ini file. + except Exception: #Probably some setting name that was missing or something else that went wrong in the ini file. Logger.log("w", "Setting " + new_setting + " could not be set because the evaluation failed. Something is probably missing from the imported legacy profile.") continue - if new_value != value_using_defaults and profile.getSettingValue(new_setting) != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura. + if new_value != value_using_defaults and current_printer.findDefinitions(key = new_setting).default_value != new_value: #Not equal to the default in the new Cura OR the default in the legacy Cura. profile.setSettingValue(new_setting, new_value) #Store the setting in the profile! if len(profile.getChangedSettings()) == 0: diff --git a/plugins/LegacyProfileReader/__init__.py b/plugins/LegacyProfileReader/__init__.py index e671f02571..f8b1f5c156 100644 --- a/plugins/LegacyProfileReader/__init__.py +++ b/plugins/LegacyProfileReader/__init__.py @@ -13,7 +13,7 @@ def getMetaData(): "author": "Ultimaker", "version": "1.0", "description": catalog.i18nc("@info:whatsthis", "Provides support for importing profiles from legacy Cura versions."), - "api": 2 + "api": 3 }, "profile_reader": [ {