Search in sources :

Example 1 with ModelCreator

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

the class Main method orderMeasurements.

private void orderMeasurements() {
    try {
        Model m = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
        try {
            ensureModelIsStopped();
            ArrayList<String> names = new ArrayList<>();
            for (Signal s : m.getSignals()) names.add(s.getName());
            new OrderMerger<String, String>(circuitComponent.getCircuit().getMeasurementOrdering()).order(names);
            ElementOrderer.ListOrder<String> o = new ElementOrderer.ListOrder<>(names);
            if (new ElementOrderer<>(Main.this, Lang.get("menu_orderMeasurements"), o).addOkButton().showDialog()) {
                circuitComponent.modify(new ModifyMeasurementOrdering(names));
            }
        } finally {
            m.close();
        }
    } catch (NodeException | PinException | ElementNotFoundException | RuntimeException e) {
        showErrorWithoutARunningModel(Lang.get("msg_errorCreatingModel"), e);
    }
}
Also used : ArrayList(java.util.ArrayList) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) ModelCreator(de.neemann.digital.draw.model.ModelCreator) ModifyMeasurementOrdering(de.neemann.digital.gui.components.modification.ModifyMeasurementOrdering) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel)

Example 2 with ModelCreator

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

the class ValueTableDialog method addTestResult.

/**
 * Add test results
 *
 * @param tsl     list of test sets
 * @param circuit the circuit
 * @param library the library to use
 * @return this for chained calls
 * @throws NodeException            NodeException
 * @throws TestingDataException     DataException
 * @throws PinException             PinException
 * @throws ElementNotFoundException ElementNotFoundException
 */
public ValueTableDialog addTestResult(ArrayList<TestSet> tsl, Circuit circuit, ElementLibrary library) throws PinException, NodeException, ElementNotFoundException, TestingDataException {
    Collections.sort(tsl);
    int i = 0;
    int errorTabIndex = -1;
    for (TestSet ts : tsl) {
        Model model = new ModelCreator(circuit, library).createModel(false);
        try {
            TestExecutor testExecutor = new TestExecutor(ts.data).create(model);
            if (testExecutor.getException() != null)
                SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorWhileExecutingTests_N0", ts.name)).addCause(testExecutor.getException()).setComponent(this));
            String tabName;
            Icon tabIcon;
            if (testExecutor.allPassed()) {
                tabName = Lang.get("msg_test_N_Passed", ts.name);
                tabIcon = ICON_PASSED;
            } else {
                tabName = Lang.get("msg_test_N_Failed", ts.name);
                tabIcon = ICON_FAILED;
                errorTabIndex = i;
            }
            if (testExecutor.toManyResults())
                tabName += " " + Lang.get("msg_test_missingLines");
            tp.addTab(tabName, tabIcon, new JScrollPane(createTable(testExecutor.getResult())));
            if (testExecutor.toManyResults())
                tp.setToolTipTextAt(i, new LineBreaker().toHTML().breakLines(Lang.get("msg_test_missingLines_tt")));
            resultTableData.add(testExecutor.getResult());
            i++;
        } finally {
            model.close();
        }
    }
    if (errorTabIndex >= 0)
        tp.setSelectedIndex(errorTabIndex);
    pack();
    setLocationRelativeTo(owner);
    return this;
}
Also used : ValueTableModel(de.neemann.digital.data.ValueTableModel) Model(de.neemann.digital.core.Model) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 3 with ModelCreator

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

the class TestAnd method testAnd.

/**
 * Reads a file and sets up a model from it.
 * After that the model - a simple AND gate - is tested to be a working AND gate.
 *
 * @throws Exception
 */
public void testAnd() throws Exception {
    File filename = new File(Resources.getRoot(), "dig/and.dig");
    Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
    ModelCreator md = new ModelCreator(circuit, library);
    Model model = md.createModel(false);
    List<Node> nodes = model.getNodes();
    assertEquals(1, nodes.size());
    // get inputs and outputs
    List<ModelEntry> inputs = md.getEntries("In");
    assertEquals(2, inputs.size());
    List<ModelEntry> outputs = md.getEntries("Out");
    assertEquals(1, outputs.size());
    // check the inputs state: the input itself has an output
    assertEquals(0, inputs.get(0).getIoState().inputCount());
    assertEquals(1, inputs.get(0).getIoState().outputCount());
    assertEquals(0, inputs.get(1).getIoState().inputCount());
    assertEquals(1, inputs.get(1).getIoState().outputCount());
    // check the output state: the output itself has an input
    assertEquals(1, outputs.get(0).getIoState().inputCount());
    assertEquals(0, outputs.get(0).getIoState().outputCount());
    // setup the test executer
    TestExecuter te = new TestExecuter(model).setInputs(inputs).setOutputs(outputs);
    te.check(0, 0, 0);
    te.check(0, 1, 0);
    te.check(1, 0, 0);
    te.check(1, 1, 1);
}
Also used : ModelEntry(de.neemann.digital.draw.model.ModelEntry) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 4 with ModelCreator

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

the class BuilderExpressionCreatorTest method create.

private Model create(ExpressionListenerStore els, ExpressionModifier modifier) throws ExpressionException, FormatterException, ElementNotFoundException, PinException, NodeException {
    CircuitBuilder circuitBuilder = new CircuitBuilder(shapeFactory, false);
    new BuilderExpressionCreator(circuitBuilder, modifier).create(els);
    return new ModelCreator(circuitBuilder.createCircuit(), libary).createModel(false);
}
Also used : ModelCreator(de.neemann.digital.draw.model.ModelCreator) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder)

Example 5 with ModelCreator

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

the class CircuitBuilderTest method testBuilderCombinatorial.

public void testBuilderCombinatorial() throws Exception {
    Variable a = new Variable("a");
    Variable b = new Variable("b");
    // xor
    Expression y = and(or(a, b), not(and(a, b)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addCombinatorial("y", y).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0, 0);
    te.check(0, 1, 1);
    te.check(1, 0, 1);
    te.check(1, 1, 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