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