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);
}
}
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()));
}
}
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);
}
Aggregations