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