Search in sources :

Example 6 with Wire

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

the class NetListTest method testTunnel.

public void testTunnel() 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");
    NetList ns = new NetList(c);
    assertEquals(1, 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)

Example 7 with Wire

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

the class ModifyMoveSelected method rotateElements.

/**
 * Rotates the given elements
 *
 * @param elements the elements to rotate
 * @param center   the center position
 */
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
    Transform transform = new TransformRotate(center, 1) {

        @Override
        public Vector transform(Vector v) {
            return super.transform(v.sub(center));
        }

        @Override
        public VectorFloat transform(VectorFloat v) {
            return super.transform(v.sub(center));
        }
    };
    for (Movable m : elements) {
        if (m instanceof VisualElement) {
            VisualElement ve = (VisualElement) m;
            ve.rotate();
            ve.setPos(transform.transform(ve.getPos()));
        } else if (m instanceof Wire) {
            Wire w = (Wire) m;
            w.p1 = transform.transform(w.p1);
            w.p2 = transform.transform(w.p2);
        } else {
            Vector p = m.getPos();
            Vector t = transform.transform(p);
            m.move(t.sub(p));
        }
    }
}
Also used : TransformRotate(de.neemann.digital.draw.graphics.TransformRotate) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) Transform(de.neemann.digital.draw.graphics.Transform) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector) VectorFloat(de.neemann.digital.draw.graphics.VectorFloat)

Example 8 with Wire

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

the class Net method interconnect.

/**
 * Do the interconnection.
 * All inputs and outputs in the net are connected together.
 * If there is no output an exception is thrown.
 * If there is one single output, all input {@link ObservableValue}s are set to this output
 * If there are more then one output a {@link DataBus} is created.
 * <p>
 * At the end all wires get a reference to the {@link ObservableValue} the represent
 *
 * @param m           the model is needed to create the {@link DataBus}
 * @param attachWires if true, the values are attached to the wires
 * @throws PinException PinException
 */
public void interconnect(Model m, boolean attachWires) throws PinException {
    ArrayList<Pin> inputs = new ArrayList<>();
    ArrayList<Pin> outputs = new ArrayList<>();
    for (Pin p : pins) {
        if (p.getDirection() == Pin.Direction.input)
            inputs.add(p);
        else
            outputs.add(p);
    }
    if (outputs.size() == 0)
        throw new PinException(Lang.get("err_noOutConnectedToWire", this.toString()), this);
    ObservableValue value = null;
    if (outputs.size() == 1 && outputs.get(0).getPullResistor() == PinDescription.PullResistor.none) {
        value = outputs.get(0).getValue();
    } else {
        value = new DataBus(this, m, outputs).getReadableOutput();
    }
    if (value == null)
        throw new PinException(Lang.get("err_output_N_notDefined", outputs.get(0)), this);
    for (Pin i : inputs) i.setValue(value);
    for (// set also the reader for bidirectional pins
    Pin o : // set also the reader for bidirectional pins
    outputs) o.setReaderValue(value);
    if (wires != null && attachWires)
        for (Wire w : wires) w.setValue(value);
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) ArrayList(java.util.ArrayList) ObservableValue(de.neemann.digital.core.ObservableValue) PinException(de.neemann.digital.draw.elements.PinException) DataBus(de.neemann.digital.core.wiring.bus.DataBus) Wire(de.neemann.digital.draw.elements.Wire)

Example 9 with Wire

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

the class NetListTest method testTunnel3.

public void testTunnel3() 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");
    addTunnel(c, new Vector(4, 1), "C");
    c.add(new Wire(new Vector(1, 4), new Vector(2, 4)));
    addTunnel(c, new Vector(2, 4), "B");
    addTunnel(c, new Vector(1, 4), "C");
    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(1, 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)

Example 10 with Wire

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

the class NetListTest method testSimple.

public void testSimple() throws Exception {
    Circuit c = new Circuit();
    c.add(new Wire(new Vector(1, 1), new Vector(1, 2)));
    c.add(new Wire(new Vector(2, 1), new Vector(2, 2)));
    c.add(new Wire(new Vector(1, 2), new Vector(2, 2)));
    c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
    NetList ns = new NetList(c);
    assertEquals(1, 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