Search in sources :

Example 1 with ExpressionException

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

the class TableDialog method createFileMenu.

private JMenu createFileMenu() {
    JMenu fileMenu = new JMenu(Lang.get("menu_file"));
    fileMenu.add(new ToolTipAction(Lang.get("menu_open")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new MyFileChooser();
            if (TableDialog.this.filename != null)
                fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
            if (fc.showOpenDialog(TableDialog.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    File file = fc.getSelectedFile();
                    TruthTable truthTable = TruthTable.readFromFile(file);
                    setModel(new TruthTableTableModel(truthTable));
                    TableDialog.this.filename = file;
                } catch (IOException e1) {
                    new ErrorMessage().addCause(e1).show(TableDialog.this);
                }
            }
        }
    });
    fileMenu.add(new ToolTipAction(Lang.get("menu_save")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new MyFileChooser();
            if (TableDialog.this.filename != null)
                fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "tru"));
            new SaveAsHelper(TableDialog.this, fc, "tru").checkOverwrite(file -> {
                model.getTable().save(file);
                TableDialog.this.filename = file;
            });
        }
    });
    fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportTableLaTeX")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                ExpressionListener expressionListener = new LaTeXExpressionListener(model);
                if (createJK.isSelected())
                    expressionListener = new ExpressionListenerJK(expressionListener);
                lastGeneratedExpressions.replayTo(expressionListener);
            } catch (ExpressionException | FormatterException e1) {
                new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e1).show(TableDialog.this);
            }
        }
    });
    fileMenu.add(new ToolTipAction(Lang.get("menu_table_exportHex")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            int res = JOptionPane.OK_OPTION;
            if (model.getTable().getVars().size() > 20)
                res = JOptionPane.showConfirmDialog(TableDialog.this, Lang.get("msg_tableHasManyRowsConfirm"));
            if (res == JOptionPane.OK_OPTION) {
                JFileChooser fc = new MyFileChooser();
                if (TableDialog.this.filename != null)
                    fc.setSelectedFile(SaveAsHelper.checkSuffix(TableDialog.this.filename, "hex"));
                new SaveAsHelper(TableDialog.this, fc, "hex").checkOverwrite(file -> model.getTable().saveHex(file));
            }
        }
    }.setToolTip(Lang.get("menu_table_exportHex_tt")).createJMenuItem());
    createJK = new JCheckBoxMenuItem(Lang.get("menu_table_JK"));
    createJK.addActionListener(e -> calculateExpressions());
    fileMenu.add(createJK);
    return fileMenu;
}
Also used : Gal22v10JEDECExporter(de.neemann.digital.builder.Gal22v10.Gal22v10JEDECExporter) AttributeDialog(de.neemann.digital.gui.components.AttributeDialog) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ExpressionToFileExporter(de.neemann.digital.builder.ExpressionToFileExporter) CuplExporter(de.neemann.digital.builder.Gal16v8.CuplExporter) JTableHeader(javax.swing.table.JTableHeader) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) KarnaughMapDialog(de.neemann.digital.gui.components.karnaugh.KarnaughMapDialog) TruthTableFormatterLaTeX(de.neemann.digital.analyse.format.TruthTableFormatterLaTeX) ExpressionModifier(de.neemann.digital.analyse.expression.modify.ExpressionModifier) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel) MouseAdapter(java.awt.event.MouseAdapter) MyFileChooser(de.neemann.gui.MyFileChooser) Main(de.neemann.digital.gui.Main) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) TableModelEvent(javax.swing.event.TableModelEvent) GenerateCUPL(de.neemann.digital.gui.components.table.hardware.GenerateCUPL) Lang(de.neemann.digital.lang.Lang) Key(de.neemann.digital.core.element.Key) NAnd(de.neemann.digital.analyse.expression.modify.NAnd) Circuit(de.neemann.digital.draw.elements.Circuit) ToolTipAction(de.neemann.gui.ToolTipAction) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) List(java.util.List) Gal16v8JEDECExporter(de.neemann.digital.builder.Gal16v8.Gal16v8JEDECExporter) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException) NOr(de.neemann.digital.analyse.expression.modify.NOr) Screen(de.neemann.gui.Screen) Gal22v10CuplExporter(de.neemann.digital.builder.Gal22v10.Gal22v10CuplExporter) TwoInputs(de.neemann.digital.analyse.expression.modify.TwoInputs) HashMap(java.util.HashMap) TableModelListener(javax.swing.event.TableModelListener) ArrayList(java.util.ArrayList) Expression(de.neemann.digital.analyse.expression.Expression) FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) StringTokenizer(java.util.StringTokenizer) FormatToTableLatex(de.neemann.digital.analyse.expression.format.FormatToTableLatex) ErrorMessage(de.neemann.gui.ErrorMessage) HardwareDescriptionGenerator(de.neemann.digital.gui.components.table.hardware.HardwareDescriptionGenerator) Keys(de.neemann.digital.core.element.Keys) TruthTable(de.neemann.digital.analyse.TruthTable) ElementOrderer(de.neemann.digital.gui.components.ElementOrderer) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) Preferences(java.util.prefs.Preferences) ATFDevice(de.neemann.digital.builder.ATF150x.ATFDevice) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder) java.awt(java.awt) AnalyseException(de.neemann.digital.analyse.AnalyseException) Variable(de.neemann.digital.analyse.expression.Variable) SaveAsHelper(de.neemann.digital.gui.SaveAsHelper) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) GenerateFile(de.neemann.digital.gui.components.table.hardware.GenerateFile) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) javax.swing(javax.swing) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) SaveAsHelper(de.neemann.digital.gui.SaveAsHelper) ToolTipAction(de.neemann.gui.ToolTipAction) MyFileChooser(de.neemann.gui.MyFileChooser) TruthTable(de.neemann.digital.analyse.TruthTable) ErrorMessage(de.neemann.gui.ErrorMessage) File(java.io.File) GenerateFile(de.neemann.digital.gui.components.table.hardware.GenerateFile) TruthTableTableModel(de.neemann.digital.analyse.TruthTableTableModel)

Example 2 with ExpressionException

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

the class ExpressionCreator method create.

/**
 * Creates the expressions
 *
 * @param listener the listener to report the found expressions to
 * @throws ExpressionException ExpressionException
 * @throws FormatterException  FormatterException
 * @throws AnalyseException    AnalyseException
 */
public void create(ExpressionListener listener) throws ExpressionException, FormatterException, AnalyseException {
    final List<Variable> vars = Collections.unmodifiableList(theTable.getVars());
    long time = System.currentTimeMillis();
    if (theTable.getResultCount() > 100) {
        ExecutorService ex = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        ThreadSaveExpressionListener threadListener = new ThreadSaveExpressionListener(listener);
        for (int table = 0; table < theTable.getResultCount(); table++) {
            final int t = table;
            ex.submit(() -> {
                try {
                    simplify(listener, vars, theTable.getResultName(t), theTable.getResult(t));
                } catch (ExpressionException | FormatterException | AnalyseException e) {
                    e.printStackTrace();
                }
            });
        }
        ex.shutdown();
        try {
            ex.awaitTermination(100, TimeUnit.HOURS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        threadListener.close();
    } else {
        for (int table = 0; table < theTable.getResultCount(); table++) simplify(listener, vars, theTable.getResultName(table), theTable.getResult(table));
        listener.close();
    }
    time = System.currentTimeMillis() - time;
    LOGGER.debug("time: " + time / 1000.0 + " sec");
}
Also used : FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) Variable(de.neemann.digital.analyse.expression.Variable) ExecutorService(java.util.concurrent.ExecutorService) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Example 3 with ExpressionException

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

the class BruteForceGetAllTest method testFullRegression.

/**
 * up to 3 variables we can calculate all tables possible!
 *
 * @throws ExpressionException
 */
public void testFullRegression() throws ExpressionException, FormatterException {
    new FullVariantDontCareCreator() {

        @Override
        public void handleTable(int n, byte[] tab) throws ExpressionException {
            performTestCalculation(n, tab);
        }
    }.create();
    new FullVariantDontCareCreator(4, 241) {

        @Override
        public void handleTable(int n, byte[] tab) throws ExpressionException {
            performTestCalculation(n, tab);
        }
    }.create();
}
Also used : FullVariantDontCareCreator(de.neemann.digital.analyse.quinemc.FullVariantDontCareCreator) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException)

Example 4 with ExpressionException

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

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

the class TableDialog method createCircuit.

private void createCircuit(boolean useJKff, ExpressionModifier... modifier) {
    try {
        CircuitBuilder circuitBuilder = new CircuitBuilder(shapeFactory, useJKff, model.getTable().getVars()).setModelAnalyzerInfo(model.getTable().getModelAnalyzerInfo());
        new BuilderExpressionCreator(circuitBuilder, modifier).setUseJKOptimizer(useJKff).create(lastGeneratedExpressions);
        Circuit circuit = circuitBuilder.createCircuit();
        new Main.MainBuilder().setParent(TableDialog.this).setLibrary(library).setCircuit(circuit).setBaseFileName(filename).openLater();
    } catch (ExpressionException | FormatterException | RuntimeException e) {
        new ErrorMessage(Lang.get("msg_errorDuringCalculation")).addCause(e).show(this);
    }
}
Also used : FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) Circuit(de.neemann.digital.draw.elements.Circuit) ErrorMessage(de.neemann.gui.ErrorMessage) Main(de.neemann.digital.gui.Main) ExpressionException(de.neemann.digital.analyse.expression.ExpressionException) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder)

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