diff options
author | Ghostkeeper <rubend@tutanota.com> | 2018-03-16 17:55:49 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2018-03-16 18:06:35 +0300 |
commit | c1ea1320f08cf8a4c1a4e961675e4f449ebc4e38 (patch) | |
tree | c7bb2b5bc11d6487a61bd090a9cd755346589643 /plugins/GCodeGzWriter | |
parent | 5a5766f11a83b189831336587133f4aa972abcdf (diff) |
Implement GCodeGzWriter
This plug-in outputs g-code to a gzipped archive. It is used for sending prints to the Ultimaker 3 family faster.
Contributes to issue CURA-5097.
Diffstat (limited to 'plugins/GCodeGzWriter')
-rw-r--r-- | plugins/GCodeGzWriter/GCodeGzWriter.py | 41 | ||||
-rw-r--r-- | plugins/GCodeGzWriter/__init__.py | 22 | ||||
-rw-r--r-- | plugins/GCodeGzWriter/plugin.json | 8 |
3 files changed, 71 insertions, 0 deletions
diff --git a/plugins/GCodeGzWriter/GCodeGzWriter.py b/plugins/GCodeGzWriter/GCodeGzWriter.py new file mode 100644 index 0000000000..4ced6d03ba --- /dev/null +++ b/plugins/GCodeGzWriter/GCodeGzWriter.py @@ -0,0 +1,41 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +import gzip +from io import StringIO, BufferedIOBase #To write the g-code to a temporary buffer, and for typing. +from typing import List + +from UM.Logger import Logger +from UM.Mesh.MeshWriter import MeshWriter #The class we're extending/implementing. +from UM.PluginRegistry import PluginRegistry +from UM.Scene.SceneNode import SceneNode #For typing. + +## A file writer that writes gzipped g-code. +# +# If you're zipping g-code, you might as well use gzip! +class GCodeGzWriter(MeshWriter): + ## Writes the gzipped g-code to a stream. + # + # Note that even though the function accepts a collection of nodes, the + # entire scene is always written to the file since it is not possible to + # separate the g-code for just specific nodes. + # + # \param stream The stream to write the gzipped g-code to. + # \param nodes This is ignored. + # \param mode Additional information on what type of stream to use. This + # must always be binary mode. + # \return Whether the write was successful. + def write(self, stream: BufferedIOBase, nodes: List[SceneNode], mode = MeshWriter.OutputMode.BinaryMode) -> bool: + if mode != MeshWriter.OutputMode.BinaryMode: + Logger.log("e", "GCodeGzWriter does not support text mode.") + return False + + #Get the g-code from the g-code writer. + gcode_textio = StringIO() #We have to convert the g-code into bytes. + success = PluginRegistry.getInstance().getPluginObject("GCodeWriter").write(gcode_textio, None) + if not success: #Writing the g-code failed. Then I can also not write the gzipped g-code. + return False + + result = gzip.compress(gcode_textio.getvalue()) + stream.write(result) + return True diff --git a/plugins/GCodeGzWriter/__init__.py b/plugins/GCodeGzWriter/__init__.py new file mode 100644 index 0000000000..c001467b3d --- /dev/null +++ b/plugins/GCodeGzWriter/__init__.py @@ -0,0 +1,22 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from . import GCodeGzWriter + +from UM.i18n import i18nCatalog +catalog = i18nCatalog("cura") + +def getMetaData(): + return { + "mesh_writer": { + "output": [{ + "extension": "gcode.gz", + "description": catalog.i18nc("@item:inlistbox", "Compressed G-code File"), + "mime_type": "application/gzip", + "mode": GCodeGzWriter.GCodeGzWriter.OutputMode.BinaryMode + }] + } + } + +def register(app): + return { "mesh_writer": GCodeGzWriter.GCodeGzWriter() } diff --git a/plugins/GCodeGzWriter/plugin.json b/plugins/GCodeGzWriter/plugin.json new file mode 100644 index 0000000000..9774e9a25c --- /dev/null +++ b/plugins/GCodeGzWriter/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "Compressed G-code Writer", + "author": "Ultimaker B.V.", + "version": "1.0.0", + "description": "Writes g-code to a compressed archive.", + "api": 4, + "i18n-catalog": "cura" +} |