Browse Source

Fix saving g-code to file

The settings that are serialised at the end of the g-code are now the serialised global container stack. That's fairly useless since the serialised version of a container stack just lists the IDs of the containers in the stack, not the settings themselves. One of these containers is likely a current_profile container and that's all the information you'll get from that serialisation.

Contributes to issue CURA-1278.
Ghostkeeper 8 years ago
parent
commit
59b8d5c169
2 changed files with 13 additions and 12 deletions
  1. 12 11
      plugins/GCodeWriter/GCodeWriter.py
  2. 1 1
      plugins/GCodeWriter/__init__.py

+ 12 - 11
plugins/GCodeWriter/GCodeWriter.py

@@ -32,7 +32,7 @@ class GCodeWriter(MeshWriter):
 
     def write(self, stream, node, mode = MeshWriter.OutputMode.TextMode):
         if mode != MeshWriter.OutputMode.TextMode:
-            Logger.log("e", "GCode Writer does not support non-text mode")
+            Logger.log("e", "GCode Writer does not support non-text mode.")
             return False
 
         scene = Application.getInstance().getController().getScene()
@@ -40,26 +40,27 @@ class GCodeWriter(MeshWriter):
         if gcode_list:
             for gcode in gcode_list:
                 stream.write(gcode)
-            # Serialise the profile and put them at the end of the file.
-            profile = self._serialiseProfile(Application.getInstance().getMachineManager().getWorkingProfile())
-            stream.write(profile)
+            # Serialise the current container stack and put it at the end of the file.
+            settings = self._serialiseSettings(Application.getInstance().getGlobalContainerStack())
+            stream.write(settings)
             return True
 
         return False
 
-    ##  Serialises the profile to prepare it for saving in the g-code.
+    ##  Serialises a container stack to prepare it for writing at the end of the
+    #   g-code.
     #
-    #   The profile are serialised, and special characters (including newline)
+    #   The settings are serialised, and special characters (including newline)
     #   are escaped.
     #
-    #   \param profile The profile to serialise.
-    #   \return A serialised string of the profile.
-    def _serialiseProfile(self, profile):
+    #   \param settings A container stack to serialise.
+    #   \return A serialised string of the settings.
+    def _serialiseSettings(self, settings):
         prefix = ";SETTING_" + str(GCodeWriter.version) + " "  # The prefix to put before each line.
         prefix_length = len(prefix)
 
-        # Serialise a deepcopy to remove the defaults from the profile
-        serialised = copy.deepcopy(profile).serialise()
+        #TODO: This just serialises the container stack, which only indicates the IDs of the containers in that stack, not the settings themselves, making this about 9001x as useless as the fax functionality in Adobe Acrobat.
+        serialised = settings.serialize()
 
         # Escape characters that have a special meaning in g-code comments.
         pattern = re.compile("|".join(GCodeWriter.escape_characters.keys()))

+ 1 - 1
plugins/GCodeWriter/__init__.py

@@ -13,7 +13,7 @@ def getMetaData():
             "author": "Ultimaker",
             "version": "1.0",
             "description": catalog.i18nc("@info:whatsthis", "Writes GCode to a file."),
-            "api": 2
+            "api": 3
         },
 
         "mesh_writer": {