Search in sources :

Example 1 with CommentProcessor

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

the class CommandProcessorLoader method getHelpForConfig.

/**
 * Helper to instantiate a processor by name and call the getHelp method.
 * @param pc
 * @return
 */
public static String getHelpForConfig(ProcessorConfig pc) {
    CommandProcessor p;
    try {
        switch(pc.name) {
            case "ArcExpander":
                double length = pc.args.get("segmentLengthMM").getAsDouble();
                p = new ArcExpander(true, length);
                break;
            case "CommandLengthProcessor":
                int commandLength = pc.args.get("commandLength").getAsInt();
                p = new CommandLengthProcessor(commandLength);
                break;
            case "CommentProcessor":
                p = new CommentProcessor();
                break;
            case "DecimalProcessor":
                int decimals = pc.args.get("decimals").getAsInt();
                p = new DecimalProcessor(decimals);
                break;
            case "FeedOverrideProcessor":
                double override = pc.args.get("speedOverridePercent").getAsDouble();
                p = new FeedOverrideProcessor(override);
                break;
            case "M30Processor":
                p = new M30Processor();
                break;
            case "PatternRemover":
                String pattern = pc.args.get("pattern").getAsString();
                p = new PatternRemover(pattern);
                break;
            case "WhitespaceProcessor":
                p = new WhitespaceProcessor();
                break;
            case "M3Dweller":
                int duration = pc.args.get("duration").getAsInt();
                p = new M3Dweller(duration);
                break;
            default:
                throw new IllegalArgumentException("Unknown processor: " + pc.name);
        }
        return p.getHelp();
    } catch (Exception e) {
        return Localization.getString("settings.processors.loadError") + ": " + Localization.getString(pc.name);
    }
}
Also used : DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) PatternRemover(com.willwinder.universalgcodesender.gcode.processors.PatternRemover) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) M3Dweller(com.willwinder.universalgcodesender.gcode.processors.M3Dweller) WhitespaceProcessor(com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor) CommandLengthProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor) CommandProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandProcessor) ArcExpander(com.willwinder.universalgcodesender.gcode.processors.ArcExpander) FeedOverrideProcessor(com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor)

Example 2 with CommentProcessor

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

the class GcodeParserTest method testAddCommandProcessor.

/**
 * Test of addCommandProcessor method, of class GcodeParser.
 */
@Test
public void testAddCommandProcessor() {
    System.out.println("addCommandProcessor");
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    assertEquals(1, instance.numCommandProcessors());
}
Also used : CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 3 with CommentProcessor

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

the class GcodeParserTest method doubleParenCommentTest.

@Test
public void doubleParenCommentTest() throws Exception {
    GcodeParser gcp = new GcodeParser();
    gcp.addCommandProcessor(new CommentProcessor());
    String command = "(comment (with subcomment) still in the comment) G01 X10";
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    List<String> result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals(" G01 X10", result.get(0));
}
Also used : CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 4 with CommentProcessor

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

the class GcodeParserTest method testPreprocessCommandFeedOverride.

@Test
public void testPreprocessCommandFeedOverride() throws Exception {
    System.out.println("preprocessCommandFeedOverride");
    // Tests:
    // '(comment)' is removed
    // '; Comment!' is removed
    // 'M30' is removed
    // Decimal truncated to 0.88889
    // Remove spaces
    String command = "(comment) G01 X0.888888888888888888 M30 F100; Comment!";
    GcodeParser instance = new GcodeParser();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new FeedOverrideProcessor(0.));
    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.88889F100", result.get(0));
    instance.resetCommandProcessors();
    instance.addCommandProcessor(new CommentProcessor());
    instance.addCommandProcessor(new FeedOverrideProcessor(200.));
    instance.addCommandProcessor(new DecimalProcessor(5));
    instance.addCommandProcessor(new M30Processor());
    instance.addCommandProcessor(new WhitespaceProcessor());
    instance.addCommandProcessor(new CommandLengthProcessor(50));
    result = instance.preprocessCommand(command, instance.getCurrentState());
    assertEquals(1, result.size());
    assertEquals("G01X0.88889F200.0", 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) FeedOverrideProcessor(com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor) M30Processor(com.willwinder.universalgcodesender.gcode.processors.M30Processor) CommentProcessor(com.willwinder.universalgcodesender.gcode.processors.CommentProcessor) Test(org.junit.Test)

Example 5 with CommentProcessor

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

the class GUIBackendPreprocessorTest method testRegularPreprocessAndExportToFile.

/**
 * Test of preprocessAndExportToFile method, of class GUIBackend.
 */
@Test
public void testRegularPreprocessAndExportToFile() throws Exception {
    System.out.println("regularPreprocessAndExportToFile");
    GUIBackend backend = new GUIBackend();
    GcodeParser gcp = new GcodeParser();
    // Double all the commands that go in.
    gcp.addCommandProcessor(commandDoubler);
    gcp.addCommandProcessor(new CommentProcessor());
    // Create input file, comment-only line shouldn't be processed twice.
    List<String> lines = Arrays.asList("line one", "; comment", "line two");
    Files.write(inputFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
    backend.preprocessAndExportToFile(gcp, inputFile.toFile(), outputFile.toFile());
    List<String> expectedResults = Arrays.asList("line one", "line one", "", "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) 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