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:
authorJack Ha <jackha@gmail.com>2018-03-21 15:57:51 +0300
committerJack Ha <jackha@gmail.com>2018-03-21 15:57:51 +0300
commit457b3543d78fba3ef11f6a9b4dd957592710eedd (patch)
tree64cfc75252dc2f55fe5505b2f03ef58c01095e06 /plugins/GCodeGzReader
parent6443db5853b97319766654135e3d085065c85f6d (diff)
CURA-5128 WIP compressed g-code reader
Diffstat (limited to 'plugins/GCodeGzReader')
-rw-r--r--plugins/GCodeGzReader/GCodeGzReader.py33
-rw-r--r--plugins/GCodeGzReader/__init__.py21
-rw-r--r--plugins/GCodeGzReader/plugin.json8
3 files changed, 62 insertions, 0 deletions
diff --git a/plugins/GCodeGzReader/GCodeGzReader.py b/plugins/GCodeGzReader/GCodeGzReader.py
new file mode 100644
index 0000000000..df1b8439cd
--- /dev/null
+++ b/plugins/GCodeGzReader/GCodeGzReader.py
@@ -0,0 +1,33 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+import gzip
+import tempfile
+
+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.MeshReader import MeshReader #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 GCodeGzReader(MeshReader):
+
+ def __init__(self):
+ super(GCodeGzReader, self).__init__()
+ self._supported_extensions = [".gcode.gz", ".gz"]
+
+ def read(self, file_name):
+ with open(file_name, "rb") as file:
+ file_data = file.read()
+ uncompressed_gcode = gzip.decompress(file_data)
+ with tempfile.NamedTemporaryFile() as temp_file:
+ temp_file.write(uncompressed_gcode)
+ PluginRegistry.getInstance().getPluginObject("GCodeReader").preRead(temp_file.name)
+ result = PluginRegistry.getInstance().getPluginObject("GCodeReader").read(temp_file.name)
+
+ return result
diff --git a/plugins/GCodeGzReader/__init__.py b/plugins/GCodeGzReader/__init__.py
new file mode 100644
index 0000000000..67424a7d45
--- /dev/null
+++ b/plugins/GCodeGzReader/__init__.py
@@ -0,0 +1,21 @@
+# Copyright (c) 2016 Aleph Objects, Inc.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from . import GCodeGzReader
+
+from UM.i18n import i18nCatalog
+i18n_catalog = i18nCatalog("cura")
+
+def getMetaData():
+ return {
+ "mesh_reader": [
+ {
+ "extension": "gcode.gz",
+ "description": i18n_catalog.i18nc("@item:inlistbox", "Compressed G-code File")
+ }
+ ]
+ }
+
+def register(app):
+ app.addNonSliceableExtension(".gcode.gz")
+ return { "mesh_reader": GCodeGzReader.GCodeGzReader() }
diff --git a/plugins/GCodeGzReader/plugin.json b/plugins/GCodeGzReader/plugin.json
new file mode 100644
index 0000000000..e9f14724e0
--- /dev/null
+++ b/plugins/GCodeGzReader/plugin.json
@@ -0,0 +1,8 @@
+{
+ "name": "Compressed G-code Reader",
+ "author": "Ultimaker B.V.",
+ "version": "1.0.0",
+ "description": "Reads g-code from a compressed archive.",
+ "api": 4,
+ "i18n-catalog": "cura"
+}