Search in sources :

Example 31 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class TransmissionGate method updatePorts.

private void updatePorts(Instance instance) {
    int dx = 0;
    int dy = 0;
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    if (facing == Direction.NORTH) {
        dy = 1;
    } else if (facing == Direction.EAST) {
        dx = -1;
    } else if (facing == Direction.SOUTH) {
        dy = -1;
    } else if (facing == Direction.WEST) {
        dx = 1;
    }
    Object powerLoc = instance.getAttributeValue(Wiring.ATTR_GATE);
    boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
    Port[] ports = new Port[4];
    ports[OUTPUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    ports[INPUT] = new Port(40 * dx, 40 * dy, Port.INPUT, StdAttr.WIDTH);
    if (flip) {
        ports[GATE1] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
        ports[GATE0] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
    } else {
        ports[GATE0] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
        ports[GATE1] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
    }
    instance.setPorts(ports);
}
Also used : Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction)

Example 32 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class Counter method configurePorts.

private void configurePorts(Instance instance) {
    Bounds bds = instance.getBounds();
    BitWidth widthVal = instance.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    Port[] ps = new Port[8];
    if (width == 1) {
        ps[OUT] = new Port(SymbolWidth(width) + 40, 120, Port.OUTPUT, StdAttr.WIDTH);
        ps[IN] = new Port(0, 120, Port.INPUT, StdAttr.WIDTH);
    } else {
        ps[OUT] = new Port(SymbolWidth(width) + 40, 110, Port.OUTPUT, StdAttr.WIDTH);
        ps[IN] = new Port(0, 110, Port.INPUT, StdAttr.WIDTH);
    }
    ps[CK] = new Port(0, 80, Port.INPUT, 1);
    ps[CLR] = new Port(0, 20, Port.INPUT, 1);
    ps[LD] = new Port(0, 30, Port.INPUT, 1);
    ps[UD] = new Port(0, 50, Port.INPUT, 1);
    ps[EN] = new Port(0, 70, Port.INPUT, 1);
    ps[CARRY] = new Port(40 + SymbolWidth(width), 50, Port.OUTPUT, 1);
    ps[OUT].setToolTip(Strings.getter("counterQTip"));
    ps[IN].setToolTip(Strings.getter("counterDataTip"));
    ps[CK].setToolTip(Strings.getter("counterClockTip"));
    ps[CLR].setToolTip(Strings.getter("counterResetTip"));
    ps[LD].setToolTip(Strings.getter("counterLoadTip"));
    ps[UD].setToolTip(Strings.getter("counterUpDownTip"));
    ps[EN].setToolTip(Strings.getter("counterEnableTip"));
    ps[CARRY].setToolTip(Strings.getter("counterCarryTip"));
    instance.setPorts(ps);
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, bds.getX() + bds.getWidth() / 2, bds.getY() - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Port(com.cburch.logisim.instance.Port)

Example 33 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class DipSwitch method configurePorts.

private void configurePorts(Instance instance) {
    Port[] ps = new Port[instance.getAttributeValue(ATTR_SIZE)];
    for (int i = 0; i < instance.getAttributeValue(ATTR_SIZE); i++) {
        ps[i] = new Port((i + 1) * 10, 0, Port.OUTPUT, 1);
    }
    instance.setPorts(ps);
}
Also used : Port(com.cburch.logisim.instance.Port)

Example 34 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class Decoder method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Port[] ps = new Port[outputs + (enable ? 2 : 1)];
    if (outputs == 2) {
        Location end0;
        Location end1;
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            int y = facing == Direction.NORTH ? -10 : 10;
            if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
                end0 = Location.create(-30, y);
                end1 = Location.create(-10, y);
            } else {
                end0 = Location.create(10, y);
                end1 = Location.create(30, y);
            }
        } else {
            int x = facing == Direction.WEST ? -10 : 10;
            if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
                end0 = Location.create(x, 10);
                end1 = Location.create(x, 30);
            } else {
                end0 = Location.create(x, -30);
                end1 = Location.create(x, -10);
            }
        }
        ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, 1);
        ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, 1);
    } else {
        int dx;
        int ddx;
        int dy;
        int ddy;
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            dy = facing == Direction.NORTH ? -20 : 20;
            ddy = 0;
            dx = selectLoc == Plexers.SELECT_TOP_RIGHT ? -10 * outputs : 0;
            ddx = 10;
        } else {
            dx = facing == Direction.WEST ? -20 : 20;
            ddx = 0;
            dy = selectLoc == Plexers.SELECT_TOP_RIGHT ? 0 : -10 * outputs;
            ddy = 10;
        }
        for (int i = 0; i < outputs; i++) {
            ps[i] = new Port(dx, dy, Port.OUTPUT, 1);
            dx += ddx;
            dy += ddy;
        }
    }
    Location en = Location.create(0, 0).translate(facing, -10);
    ps[outputs] = new Port(0, 0, Port.INPUT, select.getWidth());
    if (enable) {
        ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    for (int i = 0; i < outputs; i++) {
        ps[i].setToolTip(Strings.getter("decoderOutTip", "" + i));
    }
    ps[outputs].setToolTip(Strings.getter("decoderSelectTip"));
    if (enable) {
        ps[outputs + 1].setToolTip(Strings.getter("decoderEnableTip"));
    }
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 35 with Port

use of com.cburch.logisim.instance.Port in project logisim-evolution by reds-heig.

the class Ram method configurePorts.

@Override
void configurePorts(Instance instance) {
    Object trigger = instance.getAttributeValue(StdAttr.TRIGGER);
    boolean asynch = trigger.equals(StdAttr.TRIG_HIGH) || trigger.equals(StdAttr.TRIG_LOW);
    Object bus = instance.getAttributeValue(RamAttributes.ATTR_DBUS);
    boolean separate = bus == null ? false : bus.equals(RamAttributes.BUS_SEP);
    Object be = instance.getAttributeValue(RamAttributes.ATTR_ByteEnables);
    boolean byteEnables = be == null ? false : be.equals(RamAttributes.BUS_WITH_BYTEENABLES);
    int NrOfByteEnables = GetNrOfByteEnables(instance.getAttributeSet());
    int portCount = MEM_INPUTS;
    if (asynch) {
        portCount += 2;
    } else {
        portCount += 3;
    }
    if (separate) {
        portCount++;
    }
    if (byteEnables) {
        portCount += NrOfByteEnables;
    }
    Port[] ps = new Port[portCount];
    ps[ADDR] = new Port(0, 10, Port.INPUT, ADDR_ATTR);
    ps[ADDR].setToolTip(Strings.getter("memAddrTip"));
    ps[OE] = new Port(0, 60, Port.INPUT, 1);
    ps[OE].setToolTip(Strings.getter("ramOETip"));
    ps[WE] = new Port(0, 50, Port.INPUT, 1);
    ps[WE].setToolTip(Strings.getter("ramWETip"));
    if (!asynch) {
        int ClockOffset = 70;
        if (byteEnables) {
            ClockOffset += NrOfByteEnables * 10;
        }
        ps[CLK] = new Port(0, ClockOffset, Port.INPUT, 1);
        ps[CLK].setToolTip(Strings.getter("ramClkTip"));
    }
    int ypos = (instance.getAttributeValue(Mem.DATA_ATTR).getWidth() == 1) ? getControlHeight(instance.getAttributeSet()) + 10 : getControlHeight(instance.getAttributeSet());
    if (separate) {
        if (asynch) {
            ps[ADIN] = new Port(0, ypos, Port.INPUT, DATA_ATTR);
            ps[ADIN].setToolTip(Strings.getter("ramInTip"));
        } else {
            ps[SDIN] = new Port(0, ypos, Port.INPUT, DATA_ATTR);
            ps[SDIN].setToolTip(Strings.getter("ramInTip"));
        }
        ps[DATA] = new Port(SymbolWidth + 40, ypos, Port.OUTPUT, DATA_ATTR);
        ps[DATA].setToolTip(Strings.getter("memDataTip"));
    } else {
        ps[DATA] = new Port(SymbolWidth + 50, ypos, Port.INOUT, DATA_ATTR);
        ps[DATA].setToolTip(Strings.getter("ramBusTip"));
    }
    if (byteEnables) {
        int ByteEnableIndex = ByteEnableIndex(instance.getAttributeSet());
        for (int i = 0; i < NrOfByteEnables; i++) {
            ps[ByteEnableIndex + i] = new Port(0, 70 + i * 10, Port.INPUT, 1);
            String Label = "ramByteEnableTip" + Integer.toString(NrOfByteEnables - i - 1);
            ps[ByteEnableIndex + i].setToolTip(Strings.getter(Label));
        }
    }
    instance.setPorts(ps);
}
Also used : Port(com.cburch.logisim.instance.Port)

Aggregations

Port (com.cburch.logisim.instance.Port)40 BitWidth (com.cburch.logisim.data.BitWidth)12 Direction (com.cburch.logisim.data.Direction)10 Location (com.cburch.logisim.data.Location)9 Bounds (com.cburch.logisim.data.Bounds)6 Value (com.cburch.logisim.data.Value)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Graphics (java.awt.Graphics)3 IOException (java.io.IOException)2 Component (com.cburch.logisim.comp.Component)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 VhdlContent (com.cburch.logisim.std.hdl.VhdlContent)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1