Search in sources :

Example 6 with ModelCreator

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

the class CircuitBuilderTest method testBuilderSequential.

public void testBuilderSequential() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).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, 0);
    te.checkC(0, 1);
    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)

Example 7 with ModelCreator

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

the class CircuitBuilderTest method testBuilderSequentialJK_JequalsK.

public void testBuilderSequentialJK_JequalsK() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(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, 0);
    te.checkC(0, 1);
    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)

Example 8 with ModelCreator

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

the class TestExamples method check.

/**
 * Loads the model and initializes and test it if test cases are present
 *
 * @param dig the model file
 */
public static void check(File dig) throws Exception {
    boolean shouldFail = dig.getName().endsWith("Error.dig");
    ToBreakRunner br;
    try {
        br = new ToBreakRunner(dig);
    } catch (Exception e) {
        if (shouldFail) {
            return;
        } else
            throw e;
    }
    try {
        boolean isLib = dig.getPath().replace('\\', '/').contains("/lib/");
        assertTrue("wrong locked mode", isLib == br.getCircuit().getAttributes().get(Keys.LOCKED_MODE));
        try {
            for (VisualElement el : br.getCircuit().getElements()) if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
                String label = el.getElementAttributes().getCleanLabel();
                TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
                Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
                try {
                    TestExecutor tr = new TestExecutor(td).create(model);
                    if (label.contains("Failing"))
                        assertFalse(dig.getName() + ":" + label, tr.allPassed());
                    else
                        assertTrue(dig.getName() + ":" + label, tr.allPassed());
                    testCasesInFiles++;
                } finally {
                    model.close();
                }
            }
        } catch (Exception e) {
            if (shouldFail) {
                return;
            } else
                throw e;
        }
        assertFalse("File should fail but doesn't!", shouldFail);
    } finally {
        br.close();
    }
}
Also used : TestExecutor(de.neemann.digital.testing.TestExecutor) Model(de.neemann.digital.core.Model) VisualElement(de.neemann.digital.draw.elements.VisualElement) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription)

Example 9 with ModelCreator

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

the class TestResultTest method getModel.

private Model getModel(String func) throws IOException, ParseException, BuilderException, PinException, NodeException, ElementNotFoundException {
    ArrayList<Expression> exp = new Parser(func).parse();
    ElementLibrary library = new ElementLibrary();
    CircuitBuilder cb = new CircuitBuilder(new ShapeFactory(library));
    cb.addCombinatorial("Y", exp.get(0));
    Circuit circ = cb.createCircuit();
    Model model = new ModelCreator(circ, library).createModel(false);
    model.init();
    return model;
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Expression(de.neemann.digital.analyse.expression.Expression) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) ModelCreator(de.neemann.digital.draw.model.ModelCreator) Parser(de.neemann.digital.analyse.parser.Parser) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder)

Example 10 with ModelCreator

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

the class Main method createStartMenu.

/**
 * Creates the start menu
 *
 * @param menuBar the menu bar
 * @param toolBar the tool bar
 */
private void createStartMenu(JMenuBar menuBar, JToolBar toolBar) {
    doStep = new ToolTipAction(Lang.get("menu_step"), ICON_STEP) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                model.doMicroStep(false);
                circuitComponent.removeHighLighted();
                modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
                circuitComponent.repaintNeeded();
                doStep.setEnabled(model.needsUpdate());
            } catch (Exception e1) {
                showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e1);
            }
        }
    }.setToolTip(Lang.get("menu_step_tt"));
    ToolTipAction runModelAction = runModelState.createToolTipAction(Lang.get("menu_run"), ICON_RUN).setToolTip(Lang.get("menu_run_tt"));
    ToolTipAction runModelMicroAction = runModelMicroState.createToolTipAction(Lang.get("menu_micro"), ICON_MICRO).setToolTip(Lang.get("menu_micro_tt"));
    runToBreakAction = new ToolTipAction(Lang.get("menu_fast"), ICON_FAST) {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                int i = model.runToBreak();
                circuitComponent.repaintNeeded();
                statusLabel.setText(Lang.get("stat_clocks", i));
            } catch (NodeException | RuntimeException e1) {
                showErrorAndStopModel(Lang.get("msg_fastRunError"), e1);
            }
        }
    }.setToolTip(Lang.get("menu_fast_tt")).setEnabledChain(false).setAccelerator("F7");
    ToolTipAction stoppedStateAction = stoppedState.createToolTipAction(Lang.get("menu_element"), ICON_STOP).setToolTip(Lang.get("menu_element_tt")).setEnabledChain(false);
    ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) {

        @Override
        public void actionPerformed(ActionEvent e) {
            startTests();
        }
    }.setToolTip(Lang.get("menu_runTests_tt")).setAccelerator("F8");
    ToolTipAction speedTest = new ToolTipAction(Lang.get("menu_speedTest")) {

        private NumberFormat format = new DecimalFormat("0.0");

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
                try {
                    model.setWindowPosManager(windowPosManager);
                    SpeedTest speedTest = new SpeedTest(model);
                    String frequency = format.format(speedTest.calculate() / 1000);
                    circuitComponent.getCircuit().clearState();
                    SwingUtilities.invokeLater(() -> {
                        windowPosManager.closeAll();
                        JOptionPane.showMessageDialog(Main.this, Lang.get("msg_frequency_N", frequency));
                    });
                } finally {
                    model.close();
                }
            } catch (Exception e1) {
                showErrorWithoutARunningModel(Lang.get("msg_speedTestError"), e1);
            }
        }
    }.setToolTip(Lang.get("menu_speedTest_tt"));
    showMeasurementDialog = new ToolTipAction(Lang.get("menu_showDataTable")) {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (model != null) {
                ModelEvent event = ModelEvent.STEP;
                if (stateManager.isActive(runModelMicroState))
                    event = ModelEvent.MICROSTEP;
                showMeasurementDialog(event);
            }
        }
    }.setToolTip(Lang.get("menu_showDataTable_tt")).setEnabledChain(false);
    showMeasurementGraph = new ToolTipAction(Lang.get("menu_showDataGraph")) {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (model != null) {
                ModelEvent event = ModelEvent.STEP;
                if (stateManager.isActive(runModelMicroState))
                    event = ModelEvent.MICROSTEP;
                showMeasurementGraph(event);
            }
        }
    }.setToolTip(Lang.get("menu_showDataGraph_tt")).setEnabledChain(false);
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(' '), KEY_START_STOP_ACTION);
    circuitComponent.getActionMap().put(KEY_START_STOP_ACTION, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (model == null)
                runModelAction.actionPerformed(actionEvent);
            else
                stoppedStateAction.actionPerformed(actionEvent);
        }
    });
    JMenu run = new JMenu(Lang.get("menu_sim"));
    menuBar.add(run);
    run.add(showMeasurementDialog.createJMenuItem());
    run.add(showMeasurementGraph.createJMenuItem());
    run.addSeparator();
    run.add(runModelAction.createJMenuItem());
    run.add(runModelMicroAction.createJMenuItem());
    run.add(doStep.createJMenuItem());
    run.add(runToBreakAction.createJMenuItem());
    run.add(stoppedStateAction.createJMenuItem());
    run.add(runTests.createJMenuItem());
    run.addSeparator();
    run.add(speedTest.createJMenuItem());
    doStep.setEnabled(false);
    toolBar.add(runModelState.setIndicator(runModelAction.createJButtonNoText()));
    toolBar.add(runToBreakAction.createJButtonNoText());
    toolBar.add(stoppedStateAction.createJButtonNoText());
    toolBar.addSeparator();
    toolBar.add(runModelMicroState.setIndicator(runModelMicroAction.createJButtonNoText()));
    toolBar.add(doStep.createJButtonNoText());
    toolBar.addSeparator();
    toolBar.add(runTests.createJButtonNoText());
}
Also used : DecimalFormat(java.text.DecimalFormat) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TestingDataException(de.neemann.digital.testing.TestingDataException) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) AnalyseException(de.neemann.digital.analyse.AnalyseException) RemoteException(de.neemann.digital.gui.remote.RemoteException) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) NumberFormat(java.text.NumberFormat)

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