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:
authorGhostkeeper <ghost_keeper+github@hotmail.com>2015-12-15 13:44:29 +0300
committerGhostkeeper <ghost_keeper+github@hotmail.com>2015-12-17 15:35:16 +0300
commit63d007c02ca52cb31ef8fa702694920ceb106fb9 (patch)
tree62c91bcc91212c222072381cbde0c41bcc370a9a /plugins/GCodeProfileReader
parentedbbc962811fe11669dac13ff78c2d52c6cdd41f (diff)
Rename GCodeReader to GCodeProfileReader
The new name is more appropriate since it reads only the profiles from the g-code. In the future there might be some other plug-in that reads the actual g-code as for instance a mesh. Contributes to issue CURA-34.
Diffstat (limited to 'plugins/GCodeProfileReader')
-rw-r--r--plugins/GCodeProfileReader/GCodeProfileReader.py46
-rw-r--r--plugins/GCodeProfileReader/__init__.py25
2 files changed, 71 insertions, 0 deletions
diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py
new file mode 100644
index 0000000000..fd6a7152eb
--- /dev/null
+++ b/plugins/GCodeProfileReader/GCodeProfileReader.py
@@ -0,0 +1,46 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from UM.Application import Application #To get the current profile that should be updated with the settings from the g-code.
+from UM.Settings.ProfileReader import ProfileReader
+import re #Regular expressions for parsing escape characters in the settings.
+
+## A class that reads profile data from g-code files.
+#
+# It reads the profile data from g-code files and stores the profile as a new
+# profile, and then immediately activates that profile.
+# This class currently does not process the rest of the g-code in any way.
+class GCodeProfileReader(ProfileReader):
+ ## Initialises the g-code reader as a mesh reader.
+ def __init__(self):
+ super().__init__()
+
+ ## Reads a g-code file, loading the profile from it.
+ def read(self, file_name):
+ version = 1 #IF YOU CHANGE THIS FUNCTION IN A WAY THAT BREAKS REVERSE COMPATIBILITY, INCREMENT THIS VERSION NUMBER!
+ prefix = ";SETTING_" + str(version) + " "
+
+ #Loading all settings from the file. They are all at the end, but Python has no reverse seek any more since Python3. TODO: Consider moving settings to the start?
+ serialised = "" #Will be filled with the serialised profile.
+ try:
+ with open(file_name) as f:
+ for line in f:
+ if line.startswith(prefix):
+ serialised += line[len(prefix):-1] #Remove the prefix and the newline from the line, and add it to the rest.
+ except IOError as e:
+ Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
+
+ #Unescape the serialised profile.
+ escape_characters = { #Which special characters (keys) are replaced by what escape character (values).
+ #Note: The keys are regex strings. Values are not.
+ "\\\\": "\\", #The escape character.
+ "\\n": "\n", #Newlines. They break off the comment.
+ "\\r": "\r" #Carriage return. Windows users may need this for visualisation in their editors.
+ }
+ escape_characters = dict((re.escape(key), value) for key, value in escape_characters.items())
+ pattern = re.compile("|".join(escape_characters.keys()))
+ serialised = pattern.sub(lambda m: escape_characters[re.escape(m.group(0))], serialised) #Perform the replacement with a regular expression.
+
+ #Apply the changes to the current profile.
+ profile = Application.getInstance().getMachineManager().getActiveProfile()
+ profile.unserialise(serialised) \ No newline at end of file
diff --git a/plugins/GCodeProfileReader/__init__.py b/plugins/GCodeProfileReader/__init__.py
new file mode 100644
index 0000000000..a5ebb074c8
--- /dev/null
+++ b/plugins/GCodeProfileReader/__init__.py
@@ -0,0 +1,25 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from . import GCodeProfileReader
+
+from UM.i18n import i18nCatalog
+catalog = i18nCatalog("cura")
+
+def getMetaData():
+ return {
+ "plugin": {
+ "name": catalog.i18nc("@label", "GCode Profile Reader"),
+ "author": "Ultimaker",
+ "version": "1.0",
+ "description": catalog.i18nc("@info:whatsthis", "Provides support for importing profiles from g-code files."),
+ "api": 2
+ },
+ "profile_reader": {
+ "extension": "gcode",
+ "description": catalog.i18nc("@item:inlistbox", "G-code File")
+ }
+ }
+
+def register(app):
+ return { "profile_reader": GCodeProfileReader.GCodeProfileReader() }