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