Search in sources :

Example 1 with LineSplitter

use of com.willwinder.universalgcodesender.gcode.processors.LineSplitter 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 2 with LineSplitter

use of com.willwinder.universalgcodesender.gcode.processors.LineSplitter 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)

Aggregations

ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)2 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)2 LineSplitter (com.willwinder.universalgcodesender.gcode.processors.LineSplitter)2 MeshLeveler (com.willwinder.universalgcodesender.gcode.processors.MeshLeveler)2 GcodeParser (com.willwinder.universalgcodesender.gcode.GcodeParser)1 Position (com.willwinder.universalgcodesender.model.Position)1 GcodeCommand (com.willwinder.universalgcodesender.types.GcodeCommand)1 GcodeStreamReader (com.willwinder.universalgcodesender.utils.GcodeStreamReader)1 Settings (com.willwinder.universalgcodesender.utils.Settings)1 AutoLevelSettings (com.willwinder.universalgcodesender.utils.Settings.AutoLevelSettings)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1