Search in sources :

Example 11 with ModelCreator

use of de.neemann.digital.draw.model.ModelCreator in project Digital by hneemann.

the class Main method createAnalyseMenu.

/**
 * Creates the analyse menu
 *
 * @param menuBar the menu bar
 */
private void createAnalyseMenu(JMenuBar menuBar) {
    JMenu analyse = new JMenu(Lang.get("menu_analyse"));
    menuBar.add(analyse);
    analyse.add(new ToolTipAction(Lang.get("menu_analyse")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
                try {
                    if (model.isInvalidSignal())
                        new ErrorMessage(Lang.get("msg_invalidSignalsAnalysed")).show(Main.this);
                    else
                        new TableDialog(Main.this, new ModelAnalyser(model).analyse(), library, shapeFactory, getBaseFileName()).setVisible(true);
                    ensureModelIsStopped();
                } finally {
                    model.close();
                }
            } catch (PinException | NodeException | AnalyseException | ElementNotFoundException | BacktrackException | RuntimeException e1) {
                showErrorWithoutARunningModel(Lang.get("msg_analyseErr"), e1);
            }
        }
    }.setToolTip(Lang.get("menu_analyse_tt")).setAccelerator("F9").createJMenuItem());
    analyse.add(new ToolTipAction(Lang.get("menu_synthesise")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            TruthTable tt = new TruthTable(3).addResult();
            new TableDialog(Main.this, tt, library, shapeFactory, getBaseFileName()).setVisible(true);
            ensureModelIsStopped();
        }
    }.setToolTip(Lang.get("menu_synthesise_tt")).createJMenuItem());
    analyse.add(new ToolTipAction(Lang.get("menu_expression")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            new ExpressionDialog(Main.this, library, shapeFactory, getBaseFileName()).setVisible(true);
        }
    }.setToolTip(Lang.get("menu_expression_tt")).createJMenuItem());
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) AnalyseException(de.neemann.digital.analyse.AnalyseException) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TableDialog(de.neemann.digital.gui.components.table.TableDialog) ValueTableDialog(de.neemann.digital.gui.components.testing.ValueTableDialog) TruthTable(de.neemann.digital.analyse.TruthTable) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) ExpressionDialog(de.neemann.digital.gui.components.expression.ExpressionDialog)

Example 12 with ModelCreator

use of de.neemann.digital.draw.model.ModelCreator in project Digital by hneemann.

the class Main method createAndStartModel.

private boolean createAndStartModel(boolean globalRunClock, ModelEvent updateEvent, ModelModifier modelModifier) {
    try {
        circuitComponent.removeHighLighted();
        long time = System.currentTimeMillis();
        modelCreator = new ModelCreator(circuitComponent.getCircuit(), library);
        if (model != null) {
            modelSync.access(() -> model.close());
            circuitComponent.getCircuit().clearState();
            model = null;
        }
        model = modelCreator.createModel(true);
        time = System.currentTimeMillis() - time;
        LOGGER.debug("model creation: " + time + " ms");
        model.setWindowPosManager(windowPosManager);
        statusLabel.setText(Lang.get("msg_N_nodes", model.size()));
        realTimeClockRunning = false;
        modelSync = null;
        if (globalRunClock) {
            int threadRunnerCount = 0;
            for (Clock c : model.getClocks()) if (c.getFrequency() > 0) {
                if (modelSync == null)
                    modelSync = new LockSync();
                final RealTimeClock realTimeClock = new RealTimeClock(model, c, timerExecutor, this, modelSync, this);
                model.addObserver(realTimeClock);
                if (realTimeClock.isThreadRunner())
                    threadRunnerCount++;
                realTimeClockRunning = true;
            }
            if (threadRunnerCount > 1)
                throw new RuntimeException(Lang.get("err_moreThanOneFastClock"));
        }
        if (modelSync == null)
            modelSync = NoSync.INST;
        circuitComponent.setModeAndReset(true, modelSync);
        if (realTimeClockRunning) {
            // if clock is running, enable automatic update of gui
            GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
            modelCreator.connectToGui(gmo);
            model.addObserver(gmo);
        } else
            // all repainting is initiated by user actions!
            modelCreator.connectToGui(null);
        doStep.setEnabled(false);
        runToBreakAction.setEnabled(!realTimeClockRunning && model.isFastRunModel());
        ElementAttributes settings = circuitComponent.getCircuit().getAttributes();
        if (settings.get(Keys.SHOW_DATA_TABLE) || windowPosManager.isVisible("probe"))
            showMeasurementDialog(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH) || windowPosManager.isVisible("dataSet"))
            showMeasurementGraph(updateEvent);
        if (settings.get(Keys.SHOW_DATA_GRAPH_MICRO))
            showMeasurementGraph(ModelEvent.MICROSTEP);
        if (modelModifier != null)
            modelModifier.preInit(model);
        model.init();
        return true;
    } catch (NodeException | PinException | RuntimeException | ElementNotFoundException e) {
        if (model != null)
            showErrorAndStopModel(Lang.get("msg_errorCreatingModel"), e);
        else
            showErrorWithoutARunningModel(Lang.get("msg_errorCreatingModel"), e);
    }
    return false;
}
Also used : RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) ModelCreator(de.neemann.digital.draw.model.ModelCreator) LockSync(de.neemann.digital.gui.sync.LockSync)

Example 13 with ModelCreator

use of de.neemann.digital.draw.model.ModelCreator in project Digital by hneemann.

the class TestExecuter method createFromFile.

public static TestExecuter createFromFile(String name, ElementLibrary library) throws IOException, NodeException, PinException, ElementNotFoundException {
    File filename = new File(Resources.getRoot(), name);
    Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(library));
    ModelCreator mb = new ModelCreator(circuit, library);
    return new TestExecuter(mb.createModel(false), true).setUp(mb);
}
Also used : ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 14 with ModelCreator

use of de.neemann.digital.draw.model.ModelCreator in project Digital by hneemann.

the class CircuitBuilderTest method testBuilderSequentialJK.

public void testBuilderSequentialJK() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(not(y0), not(y1));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0);
    te.checkC(1, 1);
    te.checkC(0, 0);
    te.checkC(1, 1);
    te.checkC(0, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Aggregations

ModelCreator (de.neemann.digital.draw.model.ModelCreator)14 Circuit (de.neemann.digital.draw.elements.Circuit)7 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)7 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)6 TestExecuter (de.neemann.digital.TestExecuter)5 Expression (de.neemann.digital.analyse.expression.Expression)5 Variable (de.neemann.digital.analyse.expression.Variable)4 Model (de.neemann.digital.core.Model)4 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)4 LibraryTreeModel (de.neemann.digital.gui.components.tree.LibraryTreeModel)3 AnalyseException (de.neemann.digital.analyse.AnalyseException)2 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)2 File (java.io.File)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1 TruthTable (de.neemann.digital.analyse.TruthTable)1 Parser (de.neemann.digital.analyse.parser.Parser)1 Node (de.neemann.digital.core.Node)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Clock (de.neemann.digital.core.wiring.Clock)1 ValueTableModel (de.neemann.digital.data.ValueTableModel)1