Search in sources :

Example 1 with CommandProcessor

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

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

the class GcodeParser method preprocessCommand.

/**
 * Applies all command processors to a given command and returns the
 * resulting GCode. Does not change the parser state.
 *
 * TODO: Rather than have a separate 'preprocessCommand' which needs to be
 * followed up with calls to addCommand, it would be great to have addCommand
 * also do the preprocessing. This is challenging because they have different
 * return types.
 *
 * This is also needed for some very particular processing in GUIBackend which
 * gathers comments as a separate step outside the GcodeParser.
 *
 * TODO 2: Move this processing logic into another class, or GcodeParserUtils along with testState.
 */
@Override
public List<String> preprocessCommand(String command, final GcodeState initialState) throws GcodeParserException {
    List<String> ret = new ArrayList<>();
    ret.add(command);
    GcodeState tempState = null;
    for (CommandProcessor p : processors) {
        // Reset point segments after each pass. The final pass is what we will return.
        tempState = initialState.copy();
        // Don't re-process the results with the same preprocessor.
        for (int i = ret.size(); i > 0; i--) {
            // The arc expander changes the lastGcodeCommand which causes the following to fail:
            // G2 Y-0.7 J-14.7
            // Y28.7 J14.7 (this line treated as a G1)
            tempState.currentMotionMode = initialState.currentMotionMode;
            List<String> intermediate = p.processCommand(ret.remove(0), tempState);
            // process results to update the state and collect PointSegments
            for (String c : intermediate) {
                tempState = testState(c, tempState);
            }
            ret.addAll(intermediate);
        }
    }
    return ret;
}
Also used : CommandProcessor(com.willwinder.universalgcodesender.gcode.processors.CommandProcessor)

Example 3 with CommandProcessor

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

the class CommandProcessorLoader method initializeWithProcessors.

public static List<CommandProcessor> initializeWithProcessors(List<ProcessorConfig> config) {
    List<CommandProcessor> list = new ArrayList<>();
    for (ProcessorConfig pc : config) {
        CommandProcessor p = null;
        // Check if the processor is enabled.
        if (pc.optional && !pc.enabled) {
            continue;
        }
        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":
                double duration = pc.args.get("duration").getAsDouble();
                p = new M3Dweller(duration);
                break;
            default:
                throw new IllegalArgumentException("Unknown processor: " + pc.name);
        }
        list.add(p);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) DecimalProcessor(com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor) PatternRemover(com.willwinder.universalgcodesender.gcode.processors.PatternRemover) ProcessorConfig(com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig) 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)

Aggregations

CommandProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandProcessor)3 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)2 CommandLengthProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor)2 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)2 DecimalProcessor (com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor)2 FeedOverrideProcessor (com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor)2 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)2 M3Dweller (com.willwinder.universalgcodesender.gcode.processors.M3Dweller)2 PatternRemover (com.willwinder.universalgcodesender.gcode.processors.PatternRemover)2 WhitespaceProcessor (com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor)2 ProcessorConfig (com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)1 ArrayList (java.util.ArrayList)1