Search in sources :

Example 1 with Circuit

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;
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit)

Example 2 with 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);
}
Also used : ModelEntry(de.neemann.digital.draw.model.ModelEntry) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 3 with Circuit

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();
}
Also used : InputEvent(java.awt.event.InputEvent) Wire(de.neemann.digital.draw.elements.Wire) Signal(de.neemann.digital.core.Signal) SIZE(de.neemann.digital.draw.shapes.GenericShape.SIZE) In(de.neemann.digital.core.io.In) de.neemann.digital.gui.components(de.neemann.digital.gui.components) TestCaseElement(de.neemann.digital.testing.TestCaseElement) GraphicMinMax(de.neemann.digital.draw.graphics.GraphicMinMax) TableDialog(de.neemann.digital.gui.components.table.TableDialog) ArrayList(java.util.ArrayList) Expression(de.neemann.digital.analyse.expression.Expression) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) KarnaughMapDialog(de.neemann.digital.gui.components.karnaugh.KarnaughMapDialog) ElementTypeDescription(de.neemann.digital.core.element.ElementTypeDescription) VisualElement(de.neemann.digital.draw.elements.VisualElement) AllSolutionsDialog(de.neemann.digital.gui.components.table.AllSolutionsDialog) ErrorMessage(de.neemann.gui.ErrorMessage) Main(de.neemann.digital.gui.Main) TestCase(junit.framework.TestCase) Style(de.neemann.digital.draw.graphics.Style) External(de.neemann.digital.core.extern.External) KarnaughMapComponent(de.neemann.digital.gui.components.karnaugh.KarnaughMapComponent) GraphDialog(de.neemann.digital.gui.components.data.GraphDialog) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore) TableModel(javax.swing.table.TableModel) Keys(de.neemann.digital.core.element.Keys) SIZE2(de.neemann.digital.draw.shapes.GenericShape.SIZE2) ROM(de.neemann.digital.core.memory.ROM) IOException(java.io.IOException) Lang(de.neemann.digital.lang.Lang) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) TESTDATA(de.neemann.digital.testing.TestCaseElement.TESTDATA) Circuit(de.neemann.digital.draw.elements.Circuit) NumberingWizard(de.neemann.digital.gui.NumberingWizard) Settings(de.neemann.digital.gui.Settings) java.awt(java.awt) ValueTableDialog(de.neemann.digital.gui.components.testing.ValueTableDialog) List(java.util.List) Out(de.neemann.digital.core.io.Out) And(de.neemann.digital.core.basic.And) Driver(de.neemann.digital.core.wiring.Driver) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription) Vector(de.neemann.digital.draw.graphics.Vector) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) javax.swing(javax.swing) VisualElement(de.neemann.digital.draw.elements.VisualElement) Circuit(de.neemann.digital.draw.elements.Circuit) Main(de.neemann.digital.gui.Main)

Example 4 with Circuit

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);
    }
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) File(java.io.File)

Example 5 with Circuit

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());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Aggregations

Circuit (de.neemann.digital.draw.elements.Circuit)26 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)9 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)8 Vector (de.neemann.digital.draw.graphics.Vector)7 ModelCreator (de.neemann.digital.draw.model.ModelCreator)7 Expression (de.neemann.digital.analyse.expression.Expression)6 VisualElement (de.neemann.digital.draw.elements.VisualElement)6 File (java.io.File)6 TestExecuter (de.neemann.digital.TestExecuter)5 Wire (de.neemann.digital.draw.elements.Wire)5 Variable (de.neemann.digital.analyse.expression.Variable)4 IOException (java.io.IOException)4 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)3 Main (de.neemann.digital.gui.Main)3 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)2 Model (de.neemann.digital.core.Model)2 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)2 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1