Search in sources :

Example 11 with TruthTable

use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.

the class ReorderInputs method reorder.

/**
 * Creates a new table matching the actual state of the items
 *
 * @return the new table
 * @throws ExpressionException ExpressionException
 */
public TruthTable reorder() throws ExpressionException {
    ArrayList<Variable> newVars = new ArrayList<>();
    ArrayList<Variable> deletedVars = new ArrayList<>();
    deletedVars.addAll(table.getVars());
    for (String name : names) {
        Variable found = null;
        for (Variable v : deletedVars) if (v.getIdentifier().equals(name)) {
            found = v;
            break;
        }
        if (found != null) {
            newVars.add(found);
            deletedVars.remove(found);
        }
    }
    if (newVars.size() < 2)
        throw new ExpressionException(Lang.get("err_tableBecomesToSmall"));
    TruthTable newTable = new TruthTable(newVars);
    for (int j = 0; j < table.getResultCount(); j++) newTable.addResult(table.getResultName(j));
    ContextFiller fc = new ContextFiller(newTable.getVars());
    for (Variable v : deletedVars) fc.set(v, false);
    for (int row = 0; row < newTable.getRows(); row++) {
        fc.setContextTo(row);
        for (int t = 0; t < newTable.getResultCount(); t++) newTable.setByContext(t, fc, table.getByContext(t, fc));
    }
    return newTable;
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable) ArrayList(java.util.ArrayList) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Example 12 with TruthTable

use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.

the class TableDialog method createSetMenu.

private JMenu createSetMenu() {
    JMenu setMenu = new JMenu(Lang.get("menu_table_set"));
    setMenu.add(new ToolTipAction(Lang.get("menu_table_setXTo0")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            TruthTable t = model.getTable();
            t.setXto(false);
            setModel(new TruthTableTableModel(t));
        }
    }.setToolTip(Lang.get("menu_table_setXTo0_tt")).createJMenuItem());
    setMenu.add(new ToolTipAction(Lang.get("menu_table_setXTo1")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            TruthTable t = model.getTable();
            t.setXto(true);
            setModel(new TruthTableTableModel(t));
        }
    }.setToolTip(Lang.get("menu_table_setXTo1_tt")).createJMenuItem());
    setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllToX")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            setAllValuesTo(2);
        }
    }.setToolTip(Lang.get("menu_table_setAllToX_tt")).createJMenuItem());
    setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllTo0")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            setAllValuesTo(0);
        }
    }.setToolTip(Lang.get("menu_table_setAllTo0_tt")).createJMenuItem());
    setMenu.add(new ToolTipAction(Lang.get("menu_table_setAllTo1")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            setAllValuesTo(1);
        }
    }.setToolTip(Lang.get("menu_table_setAllTo1_tt")).createJMenuItem());
    return setMenu;
}
Also used : ToolTipAction(de.neemann.gui.ToolTipAction) ActionEvent(java.awt.event.ActionEvent) TruthTable(de.neemann.digital.analyse.TruthTable) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Example 13 with TruthTable

use of de.neemann.digital.analyse.TruthTable in project Digital by hneemann.

the class TableReorderManager method checkReorder.

private void checkReorder(TruthTableTableModel model) {
    ArrayList<Variable> varList = model.getTable().getVars();
    ArrayList<String> vars = new ArrayList<>();
    ArrayList<String> results = new ArrayList<>();
    boolean wasChange = false;
    for (int i = 0; i < model.getColumnCount(); i++) {
        String name = table.getTableHeader().getColumnModel().getColumn(i).getHeaderValue().toString();
        if (!name.equals(table.getModel().getColumnName(i)))
            wasChange = true;
        BoolTable r = model.getTable().getResult(name);
        if (r != null && varList.contains(new Variable(name)))
            return;
        if (r != null)
            results.add(name);
        else
            vars.add(name);
    }
    if (wasChange) {
        if (isVarChange(varList, vars)) {
            try {
                TruthTable tt = new ReorderInputs(model.getTable(), vars).reorder();
                tableDialog.setModel(new TruthTableTableModel(tt));
            } catch (ExpressionException e) {
                // can't happen because no columns are removed
                e.printStackTrace();
            }
        } else if (isResultChange(model.getTable(), results)) {
            try {
                TruthTable tt = new ReorderOutputs(model.getTable(), results).reorder();
                tableDialog.setModel(new TruthTableTableModel(tt));
            } catch (ExpressionException e) {
                // can't happen because no columns are removed
                e.printStackTrace();
            }
        } else
            tableDialog.setModel(new TruthTableTableModel(model.getTable()));
    }
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) ArrayList(java.util.ArrayList) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException) BoolTable(de.neemann.digital.analyse.quinemc.BoolTable) TruthTable(de.neemann.digital.analyse.TruthTable) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Aggregations

TruthTable (de.neemann.digital.analyse.TruthTable)13 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)5 TruthTableTableModel (de.neemann.digital.analyse.TruthTableTableModel)4 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)3 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)3 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)3 Variable (de.neemann.digital.analyse.expression.Variable)3 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)3 AnalyseException (de.neemann.digital.analyse.AnalyseException)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 ArrayList (java.util.ArrayList)2 Expression (de.neemann.digital.analyse.expression.Expression)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 FormatToTableLatex (de.neemann.digital.analyse.expression.format.FormatToTableLatex)1 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)1 ExpressionModifier (de.neemann.digital.analyse.expression.modify.ExpressionModifier)1 NAnd (de.neemann.digital.analyse.expression.modify.NAnd)1 NOr (de.neemann.digital.analyse.expression.modify.NOr)1 TwoInputs (de.neemann.digital.analyse.expression.modify.TwoInputs)1 TruthTableFormatterLaTeX (de.neemann.digital.analyse.format.TruthTableFormatterLaTeX)1