use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.
the class CircuitBuilder method createCircuit.
/**
* Creates the circuit
*
* @return the circuit
*/
public Circuit createCircuit() {
// determine maximum width
int maxWidth = 0;
for (Fragment f : fragments) {
Box b = f.doLayout();
if (maxWidth < b.getWidth())
maxWidth = b.getWidth();
}
// add space for clock wire!
if (!sequentialVars.isEmpty())
maxWidth += SIZE * 2;
// set width to fragments
for (Fragment f : fragments) {
if (f instanceof FragmentExpression)
((FragmentExpression) f).setWidth(maxWidth);
}
Circuit circuit = new Circuit();
int outSplitterY = 0;
if (mis != null)
outSplitterY = checkForOutputBus(maxWidth + SIZE * 15, circuit);
// add fragments to circuit
for (Fragment f : fragments) addFragmentToCircuit(f, circuit);
// order bus variables
Collection<Variable> variables = variableVisitor.getVariables();
if (desiredVarOrdering != null)
variables = order(variables, desiredVarOrdering);
if (!sequentialVars.isEmpty())
variables = order(variables, sequentialVars);
if (mis != null)
checkForInputBus(variables, -(variables.size() + 5) * SIZE * 2, circuit);
createInputBus(variables, circuit);
// add clock
if (!flipflops.isEmpty())
addClockToFlipFlops(circuit);
if (combinatorialOutputs.isEmpty())
addNetConnections(circuit, maxWidth + SIZE * 17, outSplitterY);
circuit.setModified(false);
return circuit;
}
use of de.neemann.digital.draw.elements.Circuit 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.elements.Circuit in project Digital by hneemann.
the class TestInGUI method testShortcutsPlusMinus.
public void testShortcutsPlusMinus() {
new GuiTester().mouseMove(100 + SIZE * 2, 100 + SIZE * 2).add(new GuiTester.WindowCheck<>(Main.class, (gt, main) -> {
final CircuitComponent cc = main.getCircuitComponent();
final VisualElement ve = new VisualElement(And.DESCRIPTION.getName()).setShapeFactory(cc.getLibrary().getShapeFactory());
cc.setPartToInsert(ve);
})).mouseClick(InputEvent.BUTTON1_MASK).mouseMove(100, 100).press("PLUS").press("PLUS").add(new GuiTester.WindowCheck<>(Main.class, (gt, main) -> {
final Circuit c = main.getCircuitComponent().getCircuit();
assertEquals(1, c.getElements().size());
assertEquals(4, (int) c.getElements().get(0).getElementAttributes().get(Keys.INPUT_COUNT));
})).press("MINUS").press("MINUS").add(new GuiTester.WindowCheck<>(Main.class, (gt, main) -> {
final Circuit c = main.getCircuitComponent().getCircuit();
assertEquals(1, c.getElements().size());
assertEquals(2, (int) c.getElements().get(0).getElementAttributes().get(Keys.INPUT_COUNT));
})).execute();
}
use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.
the class TestLib method check.
private void check(File dig) throws PinException, NodeException, ElementNotFoundException, IOException {
Circuit circuit = new ToBreakRunner(dig).getCircuit();
boolean is74xx = dig.getPath().contains("74xx") && !dig.getName().endsWith("-inc.dig");
if (is74xx) {
assertTrue("is not DIL", circuit.getAttributes().get(Keys.IS_DIL));
count74xx++;
}
assertTrue("is not locked", circuit.getAttributes().get(Keys.LOCKED_MODE));
final String descr = circuit.getAttributes().get(Keys.DESCRIPTION);
assertTrue("missing description", descr.length() > 0);
File f = descrMap.get(descr);
if (f != null)
fail("duplicate description '" + descr + "' in " + f + " and " + dig);
descrMap.put(descr, dig);
PinChecker pc = new PinChecker(is74xx);
for (VisualElement e : circuit.getElements()) {
if (e.equalsDescription(In.DESCRIPTION))
pc.checkPin(e);
if (e.equalsDescription(Out.DESCRIPTION))
pc.checkPin(e);
if (e.equalsDescription(Clock.DESCRIPTION))
pc.checkPin(e);
if (e.equalsDescription(ROM.DESCRIPTION) || e.equalsDescription(EEPROM.DESCRIPTION))
assertEquals("*", e.getElementAttributes().getLabel());
}
if (is74xx) {
assertTrue("GND is missing", pc.isGND);
assertTrue("VCC is missing", pc.isVCC);
}
}
use of de.neemann.digital.draw.elements.Circuit in project Digital by hneemann.
the class NetListTest method testTunnel2.
public void testTunnel2() throws Exception {
Circuit c = new Circuit();
c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
addTunnel(c, new Vector(2, 1), "A");
c.add(new Wire(new Vector(3, 1), new Vector(4, 1)));
addTunnel(c, new Vector(3, 1), "A");
c.add(new Wire(new Vector(1, 4), new Vector(2, 4)));
addTunnel(c, new Vector(2, 4), "B");
c.add(new Wire(new Vector(3, 4), new Vector(4, 4)));
addTunnel(c, new Vector(3, 4), "B");
NetList ns = new NetList(c);
assertEquals(2, ns.size());
}
Aggregations