use of de.neemann.digital.core.Model in project Digital by hneemann.
the class InputShape method applyStateMonitor.
@Override
public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {
this.ioState = ioState;
ioState.getOutput(0).addObserverToValue(guiObserver);
return new Interactor() {
@Override
public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, Sync modelSync) {
ObservableValue value = ioState.getOutput(0);
if (value.getBits() == 1) {
modelSync.access(() -> {
if (isHighZ) {
if (value.isHighZ())
value.setValue(0);
else if (value.getValue() == 0)
value.setValue(1);
else
value.setToHighZ();
} else
value.setValue(1 - value.getValue());
});
return true;
} else {
if (dialog == null || !dialog.isVisible()) {
Model model = ((In) element).getModel();
dialog = new SingleValueDialog(model.getWindowPosManager().getMainFrame(), pos, label, value, isHighZ, cc, model, modelSync);
dialog.setVisible(true);
} else
dialog.requestFocus();
return false;
}
}
};
}
use of de.neemann.digital.core.Model in project Digital by hneemann.
the class ModelCreator method createModel.
/**
* Creates the model.
*
* @param attachWires if true the wires are attached to the values
* @return the model
* @throws PinException PinException
* @throws NodeException NodeException
*/
public Model createModel(boolean attachWires) throws PinException, NodeException {
Model m = new Model();
for (Net n : netList) n.interconnect(m, attachWires);
for (ModelEntry e : entries) e.applyInputs();
for (ModelEntry e : entries) e.getElement().registerNodes(m);
for (ModelEntry e : entries) {
e.getElement().init(m);
e.getVisualElement().getShape().registerModel(this, m, e);
}
ROMManger romManager = circuit.getAttributes().get(Keys.ROMMANAGER);
romManager.applyTo(m);
return m;
}
use of de.neemann.digital.core.Model in project Digital by hneemann.
the class CycleDetectorTest method testCyclesOk.
public void testCyclesOk() throws Exception {
for (String name : nameTableCombinatorial) {
try {
Model model = new ToBreakRunner("../../main/dig/combinatorial/" + name, false).getModel();
new ModelAnalyser(model).analyse();
} catch (CycleDetector.CycleException e) {
fail("cycle detected in " + name);
}
}
}
use of de.neemann.digital.core.Model in project Digital by hneemann.
the class ModelAnalyserTest method testAnalyzer.
public void testAnalyzer() throws Exception {
Model model = new ToBreakRunner("dig/analyze/analyzeTest.dig").getModel();
TruthTable tt = new ModelAnalyser(model).analyse();
assertEquals(4, tt.getRows());
assertEquals(3, tt.getCols());
// circuit is XOr:
assertEquals(0, tt.getValue(0, 2));
assertEquals(1, tt.getValue(1, 2));
assertEquals(1, tt.getValue(2, 2));
assertEquals(0, tt.getValue(3, 2));
assertEquals("A\tB\tY\t\n" + "0\t0\t0\t\n" + "0\t1\t1\t\n" + "1\t0\t1\t\n" + "1\t1\t0\t\n", tt.toString());
}
use of de.neemann.digital.core.Model in project Digital by hneemann.
the class ModelAnalyserTest method testAnalyzerMultiBit.
public void testAnalyzerMultiBit() throws Exception {
Model model = new ToBreakRunner("dig/analyze/multiBitCounter.dig", false).getModel();
TruthTable tt = new ModelAnalyser(model).analyse();
checkTable(tt.getResult("Q0n+1"), one, zero, one, zero);
checkTable(tt.getResult("Q1n+1"), zero, one, one, zero);
assertEquals("Y1", tt.getResultName(2));
assertEquals("Y0", tt.getResultName(3));
final BoolTable y1 = tt.getResult(2);
final BoolTable y0 = tt.getResult(3);
for (int i = 0; i < 4; i++) {
assertEquals((i & 1) > 0, y0.get(i).invert().bool());
assertEquals((i & 2) > 0, y1.get(i).invert().bool());
}
}
Aggregations