From 6a1942c254cc241da90712744522571ee71f1c05 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Thu, 23 Jun 2016 19:40:00 +0200 Subject: [PATCH 1/4] GCodeWriter: Exporting the data as done on regualar exports --- plugins/GCodeWriter/GCodeWriter.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index d304f0d046..c80d8e610a 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -23,7 +23,7 @@ class GCodeWriter(MeshWriter): # It can only read settings with the same version as the version it was # written with. If the file format is changed in a way that breaks reverse # compatibility, increment this version number! - version = 1 + version = 2 ## Dictionary that defines how characters are escaped when embedded in # g-code. @@ -68,23 +68,21 @@ class GCodeWriter(MeshWriter): prefix = ";SETTING_" + str(GCodeWriter.version) + " " # The prefix to put before each line. prefix_length = len(prefix) - all_settings = InstanceContainer("G-code-imported-profile") #Create a new 'profile' with ALL settings so that the slice can be precisely reproduced. - all_settings.setDefinition(settings.getBottom()) - for key in settings.getAllKeys(): - all_settings.setProperty(key, "value", settings.getProperty(key, "value")) #Just copy everything over to the setting instance. - serialised = all_settings.serialize() + global_stack = Application.getInstance().getGlobalContainerStack() + container_with_settings = global_stack.getContainers()[1] + serialized = container_with_settings.serialize() # Escape characters that have a special meaning in g-code comments. pattern = re.compile("|".join(GCodeWriter.escape_characters.keys())) # Perform the replacement with a regular expression. - serialised = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialised) + serialized = pattern.sub(lambda m: GCodeWriter.escape_characters[re.escape(m.group(0))], serialized) # Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix. result = "" # Lines have 80 characters, so the payload of each line is 80 - prefix. - for pos in range(0, len(serialised), 80 - prefix_length): - result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n" - serialised = result + for pos in range(0, len(serialized), 80 - prefix_length): + result += prefix + serialized[pos : pos + 80 - prefix_length] + "\n" + serialized = result - return serialised \ No newline at end of file + return serialized \ No newline at end of file From 1fdf835c19bf8687c7ff1998d306a1301b13c768 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Thu, 23 Jun 2016 19:40:52 +0200 Subject: [PATCH 2/4] GCodeProfileReader: Increasing the setting version --- plugins/GCodeProfileReader/GCodeProfileReader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index 5dcea88aed..5915395005 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -22,7 +22,7 @@ class GCodeProfileReader(ProfileReader): # It can only read settings with the same version as the version it was # written with. If the file format is changed in a way that breaks reverse # compatibility, increment this version number! - version = 1 + version = 2 ## Dictionary that defines how characters are escaped when embedded in # g-code. From d49ba8011775957eebc63f17aed808216629da1b Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 24 Jun 2016 16:00:38 +0200 Subject: [PATCH 3/4] GCodeWriter: Getting always the correct container with the currently used profile. --- plugins/GCodeWriter/GCodeWriter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index c80d8e610a..4eb1f89134 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -69,8 +69,8 @@ class GCodeWriter(MeshWriter): prefix_length = len(prefix) global_stack = Application.getInstance().getGlobalContainerStack() - container_with_settings = global_stack.getContainers()[1] - serialized = container_with_settings.serialize() + container_with_profile = global_stack.findContainer({"type": "quality"}) + serialized = container_with_profile.serialize() # Escape characters that have a special meaning in g-code comments. pattern = re.compile("|".join(GCodeWriter.escape_characters.keys())) From 93cdce7b3360b2b285ca32f8b7cf7ba7522381a9 Mon Sep 17 00:00:00 2001 From: Thomas Karl Pietrowski Date: Fri, 24 Jun 2016 16:01:47 +0200 Subject: [PATCH 4/4] GCodeProfileReader: Fixing read of profiles from GCode --- plugins/GCodeProfileReader/GCodeProfileReader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index 5915395005..1ce1473582 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -75,15 +75,16 @@ class GCodeProfileReader(ProfileReader): # Create an empty profile - the id will be changed later profile = InstanceContainer("") - profile.addMetaDataEntry("type", "quality") try: profile.deserialize(serialized) except Exception as e: # Not a valid g-code file. Logger.log("e", "Unable to serialise the profile: %s", str(e)) return None + profile.addMetaDataEntry("type", "quality") + #Creating a unique name using the filename of the GCode - new_name = catalog.i18nc("@label", "Custom profile (%s)") %(os.path.splitext(os.path.basename(file_name))[0]) + new_name = catalog.i18nc("@label", "G-Code-imported profile") profile.setName(new_name) profile._id = new_name