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;
}
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);
}
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));
}
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();
}
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));
}
Aggregations