Read the gcode data from the UFP file

Open the file, extract the gcode, get the data and use the GCodeReader to parse the results.

Contributes to CURA-5155.
This commit is contained in:
Diego Prado Gesto 2019-03-08 22:48:31 +01:00
parent 3a9219be0c
commit 2b0109fbaa

View file

@ -1,9 +1,15 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from typing import cast
from Charon.VirtualFile import VirtualFile
from UM.Mesh.MeshReader import MeshReader from UM.Mesh.MeshReader import MeshReader
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
from UM.PluginRegistry import PluginRegistry
from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Scene.CuraSceneNode import CuraSceneNode
from plugins.GCodeReader.GCodeReader import GCodeReader
class UFPReader(MeshReader): class UFPReader(MeshReader):
@ -21,4 +27,15 @@ class UFPReader(MeshReader):
self._supported_extensions = [".ufp"] self._supported_extensions = [".ufp"]
def _read(self, file_name: str) -> CuraSceneNode: def _read(self, file_name: str) -> CuraSceneNode:
print("Reading", file_name) # Open the file
archive = VirtualFile()
archive.open(file_name)
# Get the gcode data from the file
gcode_data = archive.getData("/3D/model.gcode")
# Convert the bytes stream to string
gcode_stream = gcode_data["/3D/model.gcode"].decode("utf-8")
# Open the GCodeReader to parse the data
gcode_reader = cast(GCodeReader, PluginRegistry.getInstance().getPluginObject("GCodeReader"))
gcode_reader.preReadFromStream(gcode_stream)
return gcode_reader.readFromStream(gcode_stream)