Search in sources :

Example 1 with ProcessorConfig

use of com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig in project Universal-G-Code-Sender by winder.

the class CommandProcessorLoader method getConfigFrom.

/**
 * Add any ICommandProcessors specified in a JSON string. Processors are
 * initialized using the application settings if they are enabled.
 *
 * JSON Format:
 * [
 *     {
 *         "name":"ArcExpander",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         "name": "CommandLenghtProcessor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         "name": "CommentProcessor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         "name": "DecimalProcessor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         "name": "FeedOverrideProcessor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         "name": "M30Processor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         name: "WhitespaceProcessor",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     },{
 *         name: "M3Dweller",
 *         "enabled": <enabled>,
 *         "optional": <optional>,
 *         "args": {}
 *     }
 *  ]
 */
private static List<ProcessorConfig> getConfigFrom(String jsonConfig) {
    List<ProcessorConfig> list = new ArrayList<>();
    JsonArray json = new JsonParser().parse(jsonConfig).getAsJsonArray();
    for (JsonElement entry : json) {
        JsonObject object = entry.getAsJsonObject();
        boolean optional = true;
        boolean enabled = true;
        JsonObject args = null;
        if (object.has("optional") && !object.get("optional").isJsonNull()) {
            optional = object.get("optional").getAsBoolean();
        }
        if (object.has("enabled") && !object.get("enabled").isJsonNull()) {
            enabled = object.get("enabled").getAsBoolean();
        }
        if (object.has("args") && !object.get("args").isJsonNull()) {
            args = object.get("args").getAsJsonObject();
        }
        String name = object.get("name").getAsString();
        list.add(new ProcessorConfig(name, enabled, optional, args));
    }
    return list;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ProcessorConfig(com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig) JsonParser(com.google.gson.JsonParser)

Example 2 with ProcessorConfig

use of com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig in project Universal-G-Code-Sender by winder.

the class ControllerProcessorSettingsPanel method save.

@Override
public void save() {
    // In case there are in-progress changes.
    TableCellEditor editor = customRemoverTable.getCellEditor();
    if (editor != null) {
        editor.stopCellEditing();
    }
    ConfigTuple ct = configFiles.get(controllerConfigs.getSelectedItem());
    ct.loader.getProcessorConfigs().Custom.clear();
    // Roll up the pattern processors.
    DefaultTableModel model = (DefaultTableModel) this.customRemoverTable.getModel();
    for (int i = 0; i < customRemoverTable.getRowCount(); i++) {
        JsonObject args = new JsonObject();
        String pattern = model.getValueAt(i, 1).toString();
        if (!StringUtils.isEmpty(pattern)) {
            args.addProperty("pattern", pattern);
            ProcessorConfig pc = new ProcessorConfig("PatternRemover", (Boolean) model.getValueAt(i, 0), true, args);
            ct.loader.getProcessorConfigs().Custom.add(pc);
        }
    }
    try {
        FirmwareUtils.save(ct.file, ct.loader);
    } catch (IOException ex) {
        GUIHelpers.displayErrorDialog("Problem saving controller config: " + ex.getMessage());
        logger.log(Level.SEVERE, null, ex);
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) JsonObject(com.google.gson.JsonObject) TableCellEditor(javax.swing.table.TableCellEditor) IOException(java.io.IOException) ConfigTuple(com.willwinder.universalgcodesender.utils.FirmwareUtils.ConfigTuple) ProcessorConfig(com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)

Example 3 with ProcessorConfig

use of com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig in project Universal-G-Code-Sender by winder.

the class ControllerProcessorSettingsPanel method updateComponentsInternal.

/**
 *  ------------------------------
 *  |  [      controller      ]  |
 *  | [ ] front processor 1      |
 *  | [ ] front processor 2      |
 *  | [ ] end processor 1        |
 *  | [ ] end processor 2        |
 *
 *  | [+]                   [-]  |
 *  |  ________________________  |
 *  | | Enabled | Pattern      | |
 *  | |  [y]    | T\d+         | |
 *  | |  [n]    | M30          | |
 *  |  ------------------------  |
 *  |____________________________|
 */
@Override
protected void updateComponentsInternal(Settings s) {
    this.removeAll();
    initCustomRemoverTable(customRemoverTable);
    setLayout(new MigLayout("wrap 1, inset 5, fillx", "fill"));
    super.addIgnoreChanges(controllerConfigs);
    ConfigTuple ct = configFiles.get(controllerConfigs.getSelectedItem());
    ProcessorConfigGroups pcg = ct.loader.getProcessorConfigs();
    System.out.println(ct.file);
    for (ProcessorConfig pc : pcg.Front) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }
    for (ProcessorConfig pc : pcg.End) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new MigLayout("wrap 3", "grow, fill", ""));
    add(buttonPanel, add);
    add(buttonPanel, new JLabel());
    add(buttonPanel, remove);
    addIgnoreChanges(buttonPanel);
    DefaultTableModel model = (DefaultTableModel) this.customRemoverTable.getModel();
    for (ProcessorConfig pc : pcg.Custom) {
        Boolean enabled = pc.enabled;
        String pattern = "";
        if (pc.args != null && !pc.args.get("pattern").isJsonNull()) {
            pattern = pc.args.get("pattern").getAsString();
        }
        model.addRow(new Object[] { enabled, pattern });
    }
    addIgnoreChanges(new JScrollPane(customRemoverTable), "height 100");
    SwingUtilities.updateComponentTreeUI(this);
}
Also used : ProcessorConfigCheckbox(com.willwinder.universalgcodesender.uielements.components.ProcessorConfigCheckbox) MigLayout(net.miginfocom.swing.MigLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) ProcessorConfigGroups(com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfigGroups) ConfigTuple(com.willwinder.universalgcodesender.utils.FirmwareUtils.ConfigTuple) ProcessorConfig(com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)

Example 4 with ProcessorConfig

use of com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig 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

ProcessorConfig (com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfig)4 JsonObject (com.google.gson.JsonObject)2 ConfigTuple (com.willwinder.universalgcodesender.utils.FirmwareUtils.ConfigTuple)2 ArrayList (java.util.ArrayList)2 DefaultTableModel (javax.swing.table.DefaultTableModel)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 ArcExpander (com.willwinder.universalgcodesender.gcode.processors.ArcExpander)1 CommandLengthProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandLengthProcessor)1 CommandProcessor (com.willwinder.universalgcodesender.gcode.processors.CommandProcessor)1 CommentProcessor (com.willwinder.universalgcodesender.gcode.processors.CommentProcessor)1 DecimalProcessor (com.willwinder.universalgcodesender.gcode.processors.DecimalProcessor)1 FeedOverrideProcessor (com.willwinder.universalgcodesender.gcode.processors.FeedOverrideProcessor)1 M30Processor (com.willwinder.universalgcodesender.gcode.processors.M30Processor)1 M3Dweller (com.willwinder.universalgcodesender.gcode.processors.M3Dweller)1 PatternRemover (com.willwinder.universalgcodesender.gcode.processors.PatternRemover)1 WhitespaceProcessor (com.willwinder.universalgcodesender.gcode.processors.WhitespaceProcessor)1 ProcessorConfigCheckbox (com.willwinder.universalgcodesender.uielements.components.ProcessorConfigCheckbox)1 ProcessorConfigGroups (com.willwinder.universalgcodesender.utils.ControllerSettings.ProcessorConfigGroups)1