Search in sources :

Example 66 with BitWidth

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

the class Pin method getState.

private static PinState getState(InstanceState state) {
    PinAttributes attrs = (PinAttributes) state.getAttributeSet();
    BitWidth width = attrs.width;
    PinState ret = (PinState) state.getData();
    if (ret == null) {
        Value val = attrs.threeState ? Value.UNKNOWN : Value.FALSE;
        if (width.getWidth() > 1) {
            Value[] arr = new Value[width.getWidth()];
            java.util.Arrays.fill(arr, val);
            val = Value.create(arr);
        }
        ret = new PinState(val, val);
        state.setData(ret);
    }
    if (ret.intendedValue.getWidth() != width.getWidth()) {
        ret.intendedValue = ret.intendedValue.extendWidth(width.getWidth(), attrs.threeState ? Value.UNKNOWN : Value.FALSE);
    }
    if (ret.foundValue.getWidth() != width.getWidth()) {
        ret.foundValue = ret.foundValue.extendWidth(width.getWidth(), Value.UNKNOWN);
    }
    return ret;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 67 with BitWidth

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

the class PinAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    V oldvalue = null;
    if (attr == StdAttr.WIDTH) {
        BitWidth NewWidth = (BitWidth) value;
        if (width == NewWidth)
            return;
        width = (BitWidth) value;
    } else if (attr == Pin.ATTR_TRISTATE) {
        boolean NewThree = ((Boolean) value).booleanValue();
        if (threeState == NewThree)
            return;
        threeState = NewThree;
    } else if (attr == Pin.ATTR_TYPE) {
        int Newtype = ((Boolean) value).booleanValue() ? EndData.OUTPUT_ONLY : EndData.INPUT_ONLY;
        if (type == Newtype)
            return;
        type = Newtype;
    } else if (attr == Pin.ATTR_PULL) {
        Object newPull = value;
        if (pull.equals(newPull))
            return;
        pull = newPull;
    } else {
        oldvalue = (V) super.getValue(attr);
        super.setValue(attr, value);
        return;
    }
    fireAttributeValueChanged(attr, value, oldvalue);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 68 with BitWidth

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

the class Power method propagate.

@Override
public void propagate(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    state.setPort(0, Value.repeat(Value.TRUE, width.getWidth()), 1);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 69 with BitWidth

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

the class Power method drawInstance.

private void drawInstance(InstancePainter painter, boolean isGhost) {
    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());
    Direction from = painter.getAttributeValue(StdAttr.FACING);
    int degrees = Direction.EAST.toDegrees() - from.toDegrees();
    double radians = Math.toRadians((degrees + 360) % 360);
    g.rotate(radians);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    if (!isGhost && painter.getShowState()) {
        g.setColor(painter.getPortValue(0).getColor());
    }
    g.drawLine(0, 0, 5, 0);
    GraphicsUtil.switchToWidth(g, 1);
    if (!isGhost && painter.shouldDrawColor()) {
        BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
        g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
    }
    g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
    g.dispose();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D) Location(com.cburch.logisim.data.Location)

Example 70 with BitWidth

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

the class BitExtender method paintInstance.

// 
// graphics methods
// 
@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    FontMetrics fm = g.getFontMetrics();
    int asc = fm.getAscent();
    painter.drawBounds();
    String s0;
    String type = getType(painter.getAttributeSet());
    if (type.equals("zero"))
        s0 = Strings.get("extenderZeroLabel");
    else if (type.equals("one"))
        s0 = Strings.get("extenderOneLabel");
    else if (type.equals("sign"))
        s0 = Strings.get("extenderSignLabel");
    else if (type.equals("input"))
        s0 = Strings.get("extenderInputLabel");
    else
        // should never happen
        s0 = "???";
    String s1 = Strings.get("extenderMainLabel");
    Bounds bds = painter.getBounds();
    int x = bds.getX() + bds.getWidth() / 2;
    int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
    int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
    GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
    BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
    painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
    painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
    if (type.equals("input"))
        painter.drawPort(2);
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds)

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