Search in sources :

Example 11 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class ShiftRegister method getData.

private ShiftRegisterData getData(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    Integer lenObj = state.getAttributeValue(ATTR_LENGTH);
    int length = lenObj == null ? 8 : lenObj.intValue();
    ShiftRegisterData data = (ShiftRegisterData) state.getData();
    if (data == null) {
        data = new ShiftRegisterData(width, length);
        state.setData(data);
    } else {
        data.setDimensions(width, length);
    }
    return data;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 12 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class ShiftRegisterData method setDimensions.

public void setDimensions(BitWidth newWidth, int newLength) {
    Value[] v = vs;
    BitWidth oldWidth = width;
    int oldW = oldWidth.getWidth();
    int newW = newWidth.getWidth();
    if (v.length != newLength) {
        Value[] newV = new Value[newLength];
        int j = vsPos;
        int copy = Math.min(newLength, v.length);
        for (int i = 0; i < copy; i++) {
            newV[i] = v[j];
            j++;
            if (j == v.length)
                j = 0;
        }
        Arrays.fill(newV, copy, newLength, Value.createKnown(newWidth, 0));
        v = newV;
        vsPos = 0;
        vs = newV;
    }
    if (oldW != newW) {
        for (int i = 0; i < v.length; i++) {
            Value vi = v[i];
            if (vi.getWidth() != newW) {
                v[i] = vi.extendWidth(newW, Value.FALSE);
            }
        }
        width = newWidth;
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 13 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class ShiftRegisterPoker method paint.

@Override
public void paint(InstancePainter painter) {
    int loc = this.loc;
    if (loc < 0)
        return;
    BitWidth widObj = painter.getAttributeValue(StdAttr.WIDTH);
    Bounds bds = painter.getInstance().getBounds();
    int len = (widObj.getWidth() + 3) / 4;
    int boxXpos = ((ShiftRegister.SymbolWidth - 30) / 2 + 30) - (len * 4) + bds.getX() + 10;
    int y = bds.getY() + 82 + loc * 20;
    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    g.drawRect(boxXpos, y, 2 + len * 8, 16);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds)

Example 14 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class BitSelector method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth group = instance.getAttributeValue(GROUP_ATTR);
    int groups = (data.getWidth() + group.getWidth() - 1) / group.getWidth() - 1;
    int selectBits = 1;
    if (groups > 0) {
        while (groups != 1) {
            groups >>= 1;
            selectBits++;
        }
    }
    BitWidth select = BitWidth.create(selectBits);
    Location inPt;
    Location selPt;
    if (facing == Direction.WEST) {
        inPt = Location.create(30, 0);
        selPt = Location.create(10, 10);
    } else if (facing == Direction.NORTH) {
        inPt = Location.create(0, 30);
        selPt = Location.create(-10, 10);
    } else if (facing == Direction.SOUTH) {
        inPt = Location.create(0, -30);
        selPt = Location.create(-10, -10);
    } else {
        inPt = Location.create(-30, 0);
        selPt = Location.create(-10, 10);
    }
    Port[] ps = new Port[3];
    ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
    ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
    ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
    ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
    ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
    ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
    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 15 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Decoder method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    Object selectLoc = attrs.getValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
    int outputs = 1 << select.getWidth();
    Bounds bds;
    boolean reversed = facing == Direction.WEST || facing == Direction.NORTH;
    if (selectLoc == Plexers.SELECT_TOP_RIGHT)
        reversed = !reversed;
    if (outputs == 2) {
        int y = reversed ? 0 : -40;
        bds = Bounds.create(-20, y - 5, 30, 40 + 10);
    } else {
        int x = -20;
        int y = reversed ? -10 : -(outputs * 10 + 10);
        bds = Bounds.create(x, y, 40, outputs * 10 + 20);
    }
    return bds.rotate(Direction.EAST, facing, 0, 0);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1