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