mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
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:
parent
3a9219be0c
commit
2b0109fbaa
1 changed files with 18 additions and 1 deletions
|
@ -1,9 +1,15 @@
|
|||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# 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.MimeTypeDatabase import MimeType, MimeTypeDatabase
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from cura.Scene.CuraSceneNode import CuraSceneNode
|
||||
from plugins.GCodeReader.GCodeReader import GCodeReader
|
||||
|
||||
|
||||
class UFPReader(MeshReader):
|
||||
|
@ -21,4 +27,15 @@ class UFPReader(MeshReader):
|
|||
self._supported_extensions = [".ufp"]
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue