Search in sources :

Example 6 with GcodeParser

use of com.willwinder.universalgcodesender.gcode.GcodeParser in project Universal-G-Code-Sender by winder.

the class CommandProcessorLoaderTest method testInvalidProcessors.

@Test
public void testInvalidProcessors() throws Exception {
    System.out.println("InvalidProcessor");
    GcodeParser gcp = new GcodeParser();
    JsonObject args = new JsonObject();
    JsonObject object = new JsonObject();
    object.addProperty("name", "DoesNotExist");
    object.add("args", args);
    JsonArray array = new JsonArray();
    array.add(object);
    boolean threwException = false;
    try {
        List<CommandProcessor> result = CommandProcessorLoader.initializeWithProcessors(array.toString());
    } catch (IllegalArgumentException e) {
        threwException = true;
    }
    assertTrue(threwException);
}
Also used : JsonArray(com.google.gson.JsonArray) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test)

Example 7 with GcodeParser

use of com.willwinder.universalgcodesender.gcode.GcodeParser in project Universal-G-Code-Sender by winder.

the class GUIBackendPreprocessorTest method testGcodeStreamPreprocessAndExportToFile.

@Test
public void testGcodeStreamPreprocessAndExportToFile() throws Exception {
    System.out.println("gcodeStreamPreprocessAndExportToFile");
    GUIBackend backend = new GUIBackend();
    GcodeParser gcp = new GcodeParser();
    // Double all the commands that go in.
    gcp.addCommandProcessor(commandDoubler);
    // Create GcodeStream input file by putting it through the preprocessor.
    List<String> lines = Arrays.asList("line one", "line two");
    Files.write(outputFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
    backend.preprocessAndExportToFile(gcp, outputFile.toFile(), inputFile.toFile());
    // Pass a gcodestream into
    backend.preprocessAndExportToFile(gcp, inputFile.toFile(), outputFile.toFile());
    List<String> expectedResults = Arrays.asList("line one", "line one", "line one", "line one", "line two", "line two", "line two", "line two");
    try (GcodeStreamReader reader = new GcodeStreamReader(outputFile.toFile())) {
        Assert.assertEquals(expectedResults.size(), reader.getNumRows());
        for (String expected : expectedResults) {
            Assert.assertEquals(expected, reader.getNextCommand().getCommandString());
        }
    }
}
Also used : GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) Test(org.junit.Test)

Example 8 with GcodeParser

use of com.willwinder.universalgcodesender.gcode.GcodeParser in project Universal-G-Code-Sender by winder.

the class AutoLevelerTopComponent method applyToGcodeActionPerformed.

// GEN-LAST:event_dataViewerActionPerformed
private void applyToGcodeActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_applyToGcodeActionPerformed
    GcodeParser gcp = new GcodeParser();
    Settings.AutoLevelSettings autoLevelSettings = this.settings.getAutoLevelSettings();
    // Step 0: Get rid of comments.
    gcp.addCommandProcessor(new CommentProcessor());
    // Step 1: The arc processor and line processors NO LONGER need to be split!
    // Step 2: Must convert arcs to line segments.
    gcp.addCommandProcessor(new ArcExpander(true, autoLevelSettings.autoLevelArcSliceLength));
    // Step 3: Line splitter. No line should be longer than some fraction of "resolution"
    gcp.addCommandProcessor(new LineSplitter(getValue(stepResolution) / 10));
    // Step 4: Adjust Z heights codes based on mesh offsets.
    gcp.addCommandProcessor(new MeshLeveler(getValue(this.zSurface), scanner.getProbePositionGrid(), scanner.getUnits()));
    try {
        backend.applyGcodeParser(gcp);
    } catch (Exception ex) {
        GUIHelpers.displayErrorDialog(ex.getMessage());
        Exceptions.printStackTrace(ex);
    }
}
Also used : LineSplitter(com.willwinder.universalgcodesender.gcode.processors.LineSplitter) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) MeshLeveler(com.willwinder.universalgcodesender.gcode.processors.MeshLeveler) ArcExpander(com.willwinder.universalgcodesender.gcode.processors.ArcExpander) AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) AutoLevelSettings(com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings) Settings(com.willwinder.universalgcodesender.utils.Settings) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)

Example 9 with GcodeParser

use of com.willwinder.universalgcodesender.gcode.GcodeParser in project Universal-G-Code-Sender by winder.

the class GcodeTilerTopComponent method generateOneTile.

private void generateOneTile(double offsetX, double offsetY, PrintWriter output) {
    String gcodeFile = backend.getGcodeFile().getAbsolutePath();
    UnitUtils.Units u = selectedUnit(this.units.getSelectedIndex());
    GcodeParser parser = new GcodeParser();
    parser.addCommandProcessor(new Translator(new Position(offsetX, offsetY, 0.0, u)));
    parser.addCommandProcessor(new M30Processor());
    output.println(GcodeUtils.unitCommand(u) + "G90");
    output.println("G0X" + offsetX + "Y" + offsetY);
    try {
        File file = new File(gcodeFile);
        try {
            try (GcodeStreamReader gsr = new GcodeStreamReader(file)) {
                while (gsr.getNumRowsRemaining() > 0) {
                    GcodeCommand next = gsr.getNextCommand();
                    applyTranslation(next.getCommandString(), parser, output);
                }
            }
        } catch (GcodeStreamReader.NotGcodeStreamFile e) {
            try (FileInputStream fstream = new FileInputStream(file);
                DataInputStream dis = new DataInputStream(fstream);
                BufferedReader fileStream = new BufferedReader(new InputStreamReader(dis))) {
                String line;
                while ((line = fileStream.readLine()) != null) {
                    applyTranslation(line, parser, output);
                }
            }
        }
    } catch (GcodeParserException | IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Position(com.willwinder.universalgcodesender.model.Position) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) UnitUtils(com.willwinder.universalgcodesender.model.UnitUtils) Translator(com.willwinder.universalgcodesender.gcode.processors.Translator) BufferedReader(java.io.BufferedReader) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) GcodeParserException(com.willwinder.universalgcodesender.gcode.util.GcodeParserException) File(java.io.File)

Aggregations

GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)9 Test (org.junit.Test)4 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)3 Position (com.willwinder.universalgcodesender.model.Position)3 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 GcodeMeta (com.willwinder.universalgcodesender.gcode.GcodeParser.GcodeMeta)2 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)2 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)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 WhitespaceProcessor (com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor)1 GcodeParserException (com.willwinder.universalgcodesender.gcode.util.GcodeParserException)1 UnitUtils (com.willwinder.universalgcodesender.model.UnitUtils)1 Settings (com.willwinder.universalgcodesender.utils.Settings)1 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)1 BufferedReader (java.io.BufferedReader)1