Search in sources :

Example 51 with GcodeCommand

use of com.willwinder.universalgcodesender.types.GcodeCommand in project Universal-G-Code-Sender by winder.

the class GcodeParserUtils method processAndExportGcodeStream.

/**
 * Attempts to read the input file in GcodeStream format.
 * @return whether or not we succeed processing the file.
 */
private static boolean processAndExportGcodeStream(GcodeParser gcp, BufferedReader input, File output) throws IOException, GcodeParserException {
    // Preprocess a GcodeStream file.
    try {
        GcodeStreamReader gsr = new GcodeStreamReader(input);
        try (GcodeStreamWriter gsw = new GcodeStreamWriter(output)) {
            int i = 0;
            while (gsr.getNumRowsRemaining() > 0) {
                i++;
                GcodeCommand gc = gsr.getNextCommand();
                write(gcp, gsw, gc.getOriginalCommandString(), gc.getCommandString(), gc.getComment(), i);
            }
            // Done processing GcodeStream file.
            return true;
        }
    } catch (GcodeStreamReader.NotGcodeStreamFile ex) {
    // File exists, but isn't a stream reader. So go ahead and try parsing it as a raw gcode file.
    }
    return false;
}
Also used : GcodeStreamWriter(com.willwinder.universalgcodesender.utils.GcodeStreamWriter) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand)

Aggregations

GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)51 Test (org.junit.Test)26 GcodeStreamTest (com.willwinder.universalgcodesender.utils.GcodeStreamTest)19 IOException (java.io.IOException)11 Connection (com.willwinder.universalgcodesender.connection.Connection)4 Position (com.willwinder.universalgcodesender.model.Position)4 ControllerListener (com.willwinder.universalgcodesender.listeners.ControllerListener)3 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)2 EasyMock.anyString (org.easymock.EasyMock.anyString)2 UnexpectedCommand (com.willwinder.universalgcodesender.AbstractController.UnexpectedCommand)1 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)1 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)1 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)1 LineSplitter (com.willwinder.universalgcodesender.gcode.processors.LineSplitter)1 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)1 MeshLeveler (com.willwinder.universalgcodesender.gcode.processors.MeshLeveler)1 Translator (com.willwinder.universalgcodesender.gcode.processors.Translator)1