Search in sources :

Example 6 with ExpressionException

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

the class TableDialog method calculateExpressions.

private void calculateExpressions() {
    try {
        ExpressionListener expressionListener = new HTMLExpressionListener();
        if (createJK.isSelected())
            expressionListener = new ExpressionListenerJK(expressionListener);
        lastGeneratedExpressions = new ExpressionListenerStore(expressionListener);
        new ExpressionCreator(model.getTable()).create(lastGeneratedExpressions);
        kvMap.setResult(model.getTable(), lastGeneratedExpressions.getResults());
    } catch (ExpressionException | FormatterException | AnalyseException e1) {
        lastGeneratedExpressions = null;
        new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(this);
    }
}
Also used : FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) AnalyseException(de.neemann.digital.analyse.AnalyseException) ErrorMessage(de.neemann.gui.ErrorMessage) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Example 7 with ExpressionException

use of de.neemann.digital.analyse.expression.ExpressionException 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)

Example 8 with ExpressionException

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

the class BuilderExpressionCreator method create.

/**
 * Fills the builder
 *
 * @param expressions the expressions to use
 * @throws ExpressionException ExpressionException
 * @throws FormatterException  FormatterException
 */
public void create(ExpressionListenerStore expressions) throws ExpressionException, FormatterException {
    if (expressions == null)
        throw new ExpressionException(Lang.get("err_noExpressionsAvailable"));
    ExpressionListener el = new ExpressionListener() {

        @Override
        public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
            if (!contained.contains(name)) {
                contained.add(name);
                try {
                    if (name.endsWith("n+1")) {
                        name = name.substring(0, name.length() - 2);
                        builder.addSequential(name, ExpressionModifier.modifyExpression(expression, modifier));
                    } else
                        builder.addCombinatorial(name, ExpressionModifier.modifyExpression(expression, modifier));
                } catch (BuilderException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        @Override
        public void close() {
        }
    };
    if (useJKOptimizer)
        el = new ExpressionListenerOptimizeJK(el);
    expressions.replayTo(el);
}
Also used : BuilderException(de.neemann.digital.builder.BuilderException) Expression(de.neemann.digital.analyse.expression.Expression) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Aggregations

ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)8 Variable (de.neemann.digital.analyse.expression.Variable)4 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)4 TruthTable (de.neemann.digital.analyse.TruthTable)3 ErrorMessage (de.neemann.gui.ErrorMessage)3 AnalyseException (de.neemann.digital.analyse.AnalyseException)2 TruthTableTableModel (de.neemann.digital.analyse.TruthTableTableModel)2 Expression (de.neemann.digital.analyse.expression.Expression)2 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)2 Circuit (de.neemann.digital.draw.elements.Circuit)2 Main (de.neemann.digital.gui.Main)2 ArrayList (java.util.ArrayList)2 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 FormatToTableLatex (de.neemann.digital.analyse.expression.format.FormatToTableLatex)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