mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
CURA-5128 WIP compressed g-code reader
This commit is contained in:
parent
6443db5853
commit
457b3543d7
3 changed files with 62 additions and 0 deletions
33
plugins/GCodeGzReader/GCodeGzReader.py
Normal file
33
plugins/GCodeGzReader/GCodeGzReader.py
Normal file
|
@ -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
|
21
plugins/GCodeGzReader/__init__.py
Normal file
21
plugins/GCodeGzReader/__init__.py
Normal file
|
@ -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() }
|
8
plugins/GCodeGzReader/plugin.json
Normal file
8
plugins/GCodeGzReader/plugin.json
Normal file
|
@ -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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue