Search in sources :

Example 6 with Pin

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

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

the class BusSplitterShape method getPins.

@Override
public Pins getPins() {
    if (pins == null) {
        pins = new Pins();
        pins.add(new Pin(new Vector(0, 0), outputs.get(0)));
        pins.add(new Pin(new Vector(0, SIZE), inputs.get(0)));
        for (int i = 0; i < outputs.size() - 1; i++) pins.add(new Pin(new Vector(SIZE, i * spreading * SIZE), outputs.get(i + 1)));
    }
    return pins;
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) Pins(de.neemann.digital.draw.elements.Pins)

Example 8 with Pin

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

the class DemuxerShape method getPins.

@Override
public Pins getPins() {
    if (pins == null) {
        pins = new Pins();
        pins.add(new Pin(new Vector(SIZE, flip ? 0 : height), inputs.get(0)));
        if (outputCount == 2) {
            pins.add(new Pin(new Vector(SIZE * 2, 0 * SIZE), outputs.get(0)));
            pins.add(new Pin(new Vector(SIZE * 2, 2 * SIZE), outputs.get(1)));
        } else
            for (int i = 0; i < outputCount; i++) {
                pins.add(new Pin(new Vector(SIZE * 2, i * SIZE), outputs.get(i)));
            }
        if (hasInput)
            pins.add(new Pin(new Vector(0, (outputCount / 2) * SIZE), inputs.get(1)));
    }
    return pins;
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) Pins(de.neemann.digital.draw.elements.Pins)

Example 9 with Pin

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

the class GenericShape method drawTo.

@Override
public void drawTo(Graphic graphic, Style highLight) {
    int max = Math.max(inputs.size(), outputs.size());
    int height = (max - 1) * SIZE + SIZE2;
    if (symmetric && inputs.size() > 0 && ((inputs.size() & 1) == 0))
        height += SIZE;
    Polygon polygon = new Polygon(true).add(1, -SIZE2).add(SIZE * width - 1, -SIZE2).add(SIZE * width - 1, height).add(1, height);
    if (color != Color.WHITE && !graphic.isFlagSet(Graphic.LATEX))
        graphic.drawPolygon(polygon, Style.NORMAL.deriveFillStyle(color));
    graphic.drawPolygon(polygon, Style.NORMAL);
    if (invert) {
        int offs = symmetric ? inputs.size() / 2 * SIZE : 0;
        for (int i = 0; i < outputs.size(); i++) graphic.drawCircle(new Vector(SIZE * width + 1, i * SIZE - SIZE2 + 1 + offs), new Vector(SIZE * (width + 1) - 1, i * SIZE + SIZE2 - 1 + offs), Style.NORMAL);
    }
    if (label != null) {
        Vector pos = new Vector(SIZE2 * width, -SIZE2 - 8);
        graphic.drawText(pos, pos.add(1, 0), label, Orientation.CENTERBOTTOM, Style.NORMAL);
    }
    if (showPinLabels) {
        for (Pin p : getPins()) {
            int dx = 4;
            if (isInverted(p.getName(), inverterConfig))
                dx += SIZE;
            if (p.getDirection() == Pin.Direction.input) {
                if (p.isClock()) {
                    final int triangle = SIZE2 / 2 + 2;
                    graphic.drawPolygon(new Polygon(false).add(p.getPos().add(dx - 3, triangle)).add(p.getPos().add(dx + triangle - 3, 0)).add(p.getPos().add(dx - 3, -triangle)), Style.THIN);
                    dx += triangle;
                }
                graphic.drawText(p.getPos().add(dx, 0), p.getPos().add(dx + 1, 0), p.getName(), Orientation.LEFTCENTER, Style.SHAPE_PIN);
            } else
                graphic.drawText(p.getPos().add(-4, 0), p.getPos().add(5, 0), p.getName(), Orientation.RIGHTCENTER, Style.SHAPE_PIN);
        }
    }
    if (name.length() > 0) {
        if (name.length() <= 3 && !showPinLabels) {
            Vector pos = new Vector(SIZE2 * width, -SIZE2 + 4);
            graphic.drawText(pos, pos.add(1, 0), name, Orientation.CENTERTOP, Style.NORMAL);
        } else {
            Vector pos = new Vector(SIZE2 * width, height + 4);
            graphic.drawText(pos, pos.add(1, 0), name, Orientation.CENTERTOP, Style.SHAPE_PIN);
        }
    }
    drawInputInvert(graphic, inverterConfig, getPins());
}
Also used : Pin(de.neemann.digital.draw.elements.Pin) Polygon(de.neemann.digital.draw.graphics.Polygon)

Aggregations

Pin (de.neemann.digital.draw.elements.Pin)9 Pins (de.neemann.digital.draw.elements.Pins)7 Vector (de.neemann.digital.draw.graphics.Vector)3 ObservableValue (de.neemann.digital.core.ObservableValue)1 DataBus (de.neemann.digital.core.wiring.bus.DataBus)1 PinException (de.neemann.digital.draw.elements.PinException)1 Wire (de.neemann.digital.draw.elements.Wire)1 Polygon (de.neemann.digital.draw.graphics.Polygon)1 ArrayList (java.util.ArrayList)1