Search in sources :

Example 6 with CommentProcessor

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

the class GcodeViewParse method getParser.

/**
 * Create a gcode parser with required configuration.
 */
private static GcodeParser getParser(double arcSegmentLength) {
    GcodeParser gp = new GcodeParser();
    gp.addCommandProcessor(new CommentProcessor());
    gp.addCommandProcessor(new WhitespaceProcessor());
    // gp.addCommandProcessor(new ArcExpander(true, arcSegmentLength, 4));
    return gp;
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) GcodeParser(com.willwinder.universalgcodesender.gcode.GcodeParser) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)

Example 7 with CommentProcessor

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

the class GcodeParserTest method testPreprocessCommandException.

@Test
public void testPreprocessCommandException() throws Exception {
    System.out.println("preprocessCommandException?!");
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    // Don't process decimals to make this test easier to create.
    instance.addCommandProcessor(new DecimalProcessor(0));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    // Shouldn't throw if exactly 50 characters long.
    final String command = "G01X0.88888888888888888888888888888888888888888888";
    instance.preprocessCommand(command, instance.getCurrentState());
    // Should throw an exception when it is 51 characters long.
    Assertions.assertThatThrownBy(() -> instance.preprocessCommand(command + "8", instance.getCurrentState())).isInstanceOf(GcodeParserException.class);
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 8 with CommentProcessor

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

the class GcodeParserTest method nonGcodeIgnoresImplicitGcode.

@Test
public void nonGcodeIgnoresImplicitGcode() throws Exception {
    GcodeParser gcp = new GcodeParser();
    gcp.addCommandProcessor(new CommentProcessor());
    GcodeState initialState = new GcodeState();
    initialState.currentPoint = new Position(0, 0, 1, MM);
    initialState.currentMotionMode = Code.G0;
    List<String> result = gcp.preprocessCommand("M05", initialState);
    assertEquals(1, result.size());
    assertEquals("M05", result.get(0));
}
Also used : Position(com.willwinder.universalgcodesender.model.Position) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 9 with CommentProcessor

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

the class GcodeParserTest method autoLevelerProcessorSet.

@Test
public void autoLevelerProcessorSet() throws Exception {
    System.out.println("autoLevelerProcessorSet");
    GcodeParser gcp = new GcodeParser();
    gcp.addCommandProcessor(new CommentProcessor());
    gcp.addCommandProcessor(new ArcExpander(true, 0.1));
    gcp.addCommandProcessor(new LineSplitter(1));
    Position[][] grid = { { new Position(-5, -5, 0, MM), new Position(-5, 35, 0, MM) }, { new Position(35, -5, 0, MM), new Position(35, 35, 0, MM) } };
    gcp.addCommandProcessor(new MeshLeveler(0, grid, Units.MM));
    Path output = Files.createTempFile("autoleveler_processor_set_test.nc", "");
    // Copy resource to temp file since my parser methods need it that way.
    URL file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc");
    File tempFile = File.createTempFile("temp", "file");
    IOUtils.copy(file.openStream(), FileUtils.openOutputStream(tempFile));
    GcodeParserUtils.processAndExport(gcp, tempFile, output.toFile());
    GcodeStreamReader reader = new GcodeStreamReader(output.toFile());
    file = this.getClass().getClassLoader().getResource("./gcode/circle_test.nc.processed");
    Files.lines(Paths.get(file.toURI())).forEach((t) -> {
        try {
            GcodeCommand c = reader.getNextCommand();
            if (c == null) {
                Assert.fail("Reached end of gcode reader before end of expected commands.");
            }
            Assert.assertEquals(c.getCommandString(), t);
        } catch (IOException ex) {
            Assert.fail("Unexpected exception.");
        }
    });
    assertEquals(1027, reader.getNumRows());
    output.toFile().delete();
}
Also used : Path(java.nio.file.Path) Position(com.willwinder.universalgcodesender.model.Position) LineSplitter(com.willwinder.universalgcodesender.gcode.processors.LineSplitter) GcodeCommand(com.willwinder.universalgcodesender.types.GcodeCommand) IOException(java.io.IOException) URL(java.net.URL) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) MeshLeveler(com.willwinder.universalgcodesender.gcode.processors.MeshLeveler) GcodeStreamReader(com.willwinder.universalgcodesender.utils.GcodeStreamReader) ArcExpander(com.willwinder.universalgcodesender.gcode.processors.ArcExpander) File(java.io.File) Test(org.junit.Test)

Example 10 with CommentProcessor

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

the class GcodeParserTest method testPreprocessCommandGood.

/**
 * Test of preprocessCommand method, of class GcodeParser.
 */
@Test
public void testPreprocessCommandGood() throws Exception {
    System.out.println("preprocessCommandGood");
    // Tests:
    // '(comment)' is removed
    // '; Comment!' is removed
    // 'M30' is removed
    // Decimal truncated to 0.88889
    // Remove spaces
    String command = "(comment) G01 X0.888888888888888888 M30; Comment!";
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new DecimalProcessor(5));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    List<String> result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals("G01X0.88889", result.get(0));
}
Also used : WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Aggregations

CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)13 Test (org.junit.Test)9 WhitespaceProcessor (com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor)6 CommandLengthProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor)5 DecimalProcessor (com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor)5 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)5 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)4 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)3 FeedOverrideProcessor (com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor)3 CommandProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandProcessor)2 LineSplitter (com.willwinder.universalgcodesender.gcode.processors.LineSplitter)2 M3Dweller (com.willwinder.universalgcodesender.gcode.processors.M3Dweller)2 MeshLeveler (com.willwinder.universalgcodesender.gcode.processors.MeshLeveler)2 PatternRemover (com.willwinder.universalgcodesender.gcode.processors.PatternRemover)2 Position (com.willwinder.universalgcodesender.model.Position)2 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)2 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1 ProcessorConfig (com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)1 Settings (com.willwinder.universalgcodesender.utils.Settings)1 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)1