Search in sources :

Example 1 with Wire

use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.

the class CircuitBuilder method createInputBus.

private void createInputBus(Collection<Variable> inputs, Circuit circuit) {
    HashMap<String, Integer> varPos = new HashMap<>();
    int dx = -inputs.size() * SIZE * 2;
    pos -= SIZE;
    for (Variable v : inputs) {
        VisualElement visualElement;
        if (sequentialVars.contains(v) || varsToNet.contains(v.getIdentifier())) {
            visualElement = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
            visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(1)).set(Keys.NETNAME, v.getIdentifier());
        } else {
            visualElement = new VisualElement(In.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
            visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3)).set(Keys.LABEL, v.getIdentifier());
            checkPinNumber(visualElement);
        }
        visualElement.setPos(new Vector(dx, -SIZE * 5));
        circuit.add(visualElement);
        circuit.add(new Wire(new Vector(dx, -SIZE * 5), new Vector(dx, pos)));
        if (isNotNeeded(v.getIdentifier())) {
            visualElement = new VisualElement(de.neemann.digital.core.basic.Not.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
            visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3));
            visualElement.setPos(new Vector(dx + SIZE, -SIZE * 3));
            circuit.add(visualElement);
            circuit.add(new Wire(new Vector(dx, -SIZE * 4), new Vector(dx + SIZE, -SIZE * 4)));
            circuit.add(new Wire(new Vector(dx + SIZE, -SIZE * 3), new Vector(dx + SIZE, -SIZE * 4)));
            circuit.add(new Wire(new Vector(dx + SIZE, -SIZE), new Vector(dx + SIZE, pos)));
        }
        varPos.put(v.getIdentifier(), dx);
        dx += SIZE * 2;
    }
    for (FragmentVariable f : fragmentVariables) {
        Vector p = f.getCircuitPos();
        int in = varPos.get(f.getVariable().getIdentifier());
        if (f.isInvert())
            in += SIZE;
        circuit.add(new Wire(p, new Vector(in, p.y)));
    }
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Wire(de.neemann.digital.draw.elements.Wire) Rotation(de.neemann.digital.core.element.Rotation) Vector(de.neemann.digital.draw.graphics.Vector)

Example 2 with Wire

use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.

the class CircuitBuilder method checkForInputBus.

private void checkForInputBus(Collection<Variable> variables, int splitterXPos, Circuit circuit) {
    StringBuilder pinString = new StringBuilder();
    int y = 0;
    for (Map.Entry<String, ArrayList<String>> e : mis.getInputBusMap().entrySet()) {
        pinString.setLength(0);
        int found = 0;
        final ArrayList<String> inputs = e.getValue();
        for (String n : inputs) {
            if (variables.contains(new Variable(n))) {
                found++;
                String p = mis.getPins().get(n);
                if (p != null) {
                    if (pinString.length() != 0)
                        pinString.append(",");
                    pinString.append(p);
                }
            }
        }
        if (found == inputs.size()) {
            varsToNet.addAll(inputs);
            circuit.add(new VisualElement(Splitter.DESCRIPTION.getName()).setAttribute(Keys.INPUT_SPLIT, "" + inputs.size()).setAttribute(Keys.OUTPUT_SPLIT, "1*" + inputs.size()).setPos(new Vector(splitterXPos, y)).setShapeFactory(shapeFactory));
            circuit.add(new VisualElement(In.DESCRIPTION.getName()).setAttribute(Keys.LABEL, e.getKey()).setAttribute(Keys.BITS, inputs.size()).setAttribute(Keys.PINNUMBER, pinString.toString()).setPos(new Vector(splitterXPos - 2 * SIZE, y)).setShapeFactory(shapeFactory));
            circuit.add(new Wire(new Vector(splitterXPos - 2 * SIZE, y), new Vector(splitterXPos, y)));
            for (int i = 0; i < inputs.size(); i++) {
                circuit.add(new VisualElement(Tunnel.DESCRIPTION.getName()).setAttribute(Keys.NETNAME, inputs.get(i)).setPos(new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)).setShapeFactory(shapeFactory));
                circuit.add(new Wire(new Vector(splitterXPos + SIZE, y + i * SIZE), new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)));
            }
            y += (inputs.size() + 2) * SIZE;
        }
    }
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Example 3 with Wire

use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.

the class FragmentExpression method addToCircuit.

@Override
public void addToCircuit(Vector offset, Circuit circuit) {
    Vector p = pos.add(offset);
    merger.addToCircuit(p, circuit);
    for (int i = 0; i < fragments.size(); i++) {
        FragmentHolder fr = fragments.get(i);
        fr.fragment.addToCircuit(p, circuit);
        Vector pin = fr.fragment.getOutputs().get(0);
        Vector start = pin.add(p);
        Vector end = merger.getInputs().get(i).add(p);
        int back = 0;
        if (normalLayout)
            back = calcBackOffset(fragments.size(), i);
        if (back > 0) {
            Vector inter2 = end.add(-back * SIZE, 0);
            Vector inter1 = new Vector(inter2.x, start.y);
            circuit.add(new Wire(start, inter1));
            circuit.add(new Wire(inter1, inter2));
            circuit.add(new Wire(inter2, end));
        } else {
            circuit.add(new Wire(start, end));
        }
    }
}
Also used : Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Example 4 with Wire

use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.

the class FragmentSameInValue method addToCircuit.

@Override
public void addToCircuit(Vector pos, Circuit circuit) {
    List<Vector> in = Vector.add(fragment.getInputs(), pos);
    Vector last = null;
    for (Vector v : in) {
        Vector p = v.add(-SIZE, 0);
        circuit.add(new Wire(v, p));
        if (last != null)
            circuit.add(new Wire(last, p));
        last = p;
    }
    fragment.addToCircuit(pos, circuit);
}
Also used : Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Example 5 with Wire

use of de.neemann.digital.draw.elements.Wire 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

Wire (de.neemann.digital.draw.elements.Wire)14 Vector (de.neemann.digital.draw.graphics.Vector)13 VisualElement (de.neemann.digital.draw.elements.VisualElement)6 Circuit (de.neemann.digital.draw.elements.Circuit)4 Rotation (de.neemann.digital.core.element.Rotation)2 ObservableValue (de.neemann.digital.core.ObservableValue)1 DataBus (de.neemann.digital.core.wiring.bus.DataBus)1 Movable (de.neemann.digital.draw.elements.Movable)1 Pin (de.neemann.digital.draw.elements.Pin)1 PinException (de.neemann.digital.draw.elements.PinException)1 Transform (de.neemann.digital.draw.graphics.Transform)1 TransformRotate (de.neemann.digital.draw.graphics.TransformRotate)1 VectorFloat (de.neemann.digital.draw.graphics.VectorFloat)1 ArrayList (java.util.ArrayList)1