Search in sources :

Example 71 with Value

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

the class Constant method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getOffsetBounds();
    BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
    int intValue = painter.getAttributeValue(ATTR_VALUE).intValue();
    Value v = Value.createKnown(width, intValue);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    if (painter.shouldDrawColor()) {
        g.setColor(BACKGROUND_COLOR);
        g.fillRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
    }
    if (v.getWidth() == 1) {
        if (painter.shouldDrawColor())
            g.setColor(v.getColor());
        GraphicsUtil.drawCenteredText(g, v.toString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2);
    } else {
        g.setColor(Color.BLACK);
        GraphicsUtil.drawCenteredText(g, v.toHexString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2);
    }
    painter.drawPorts();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Value(com.cburch.logisim.data.Value) Location(com.cburch.logisim.data.Location)

Example 72 with Value

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

the class Constant method paintIcon.

// 
// painting methods
// 
@Override
public void paintIcon(InstancePainter painter) {
    int w = painter.getAttributeValue(StdAttr.WIDTH).getWidth();
    int pinx = 16;
    int piny = 9;
    Direction dir = painter.getAttributeValue(StdAttr.FACING);
    if (dir == Direction.EAST) {
    } else // keep defaults
    if (dir == Direction.WEST) {
        pinx = 4;
    } else if (dir == Direction.NORTH) {
        pinx = 9;
        piny = 4;
    } else if (dir == Direction.SOUTH) {
        pinx = 9;
        piny = 16;
    }
    Graphics g = painter.getGraphics();
    if (w == 1) {
        int v = painter.getAttributeValue(ATTR_VALUE).intValue();
        Value val = v == 1 ? Value.TRUE : Value.FALSE;
        g.setColor(val.getColor());
        GraphicsUtil.drawCenteredText(g, "" + v, 10, 9);
    } else {
        g.setFont(g.getFont().deriveFont(9.0f));
        GraphicsUtil.drawCenteredText(g, "x" + w, 10, 9);
    }
    g.fillOval(pinx, piny, 3, 3);
}
Also used : Graphics(java.awt.Graphics) Value(com.cburch.logisim.data.Value) Direction(com.cburch.logisim.data.Direction)

Example 73 with Value

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

the class Transistor method computeOutput.

private Value computeOutput(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    Value gate = state.getPortValue(GATE);
    Value input = state.getPortValue(INPUT);
    Value desired = state.getAttributeValue(ATTR_TYPE) == TYPE_P ? Value.FALSE : Value.TRUE;
    if (!gate.isFullyDefined()) {
        if (input.isFullyDefined()) {
            return Value.createError(width);
        } else {
            Value[] v = input.getAll();
            for (int i = 0; i < v.length; i++) {
                if (v[i] != Value.UNKNOWN) {
                    v[i] = Value.ERROR;
                }
            }
            return Value.create(v);
        }
    } else if (gate != desired) {
        return Value.createUnknown(width);
    } else {
        return input;
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 74 with Value

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

the class ClockState method updateClock.

public boolean updateClock(Value newClock, Object trigger) {
    Value oldClock = lastClock;
    lastClock = newClock;
    if (trigger == null || trigger == StdAttr.TRIG_RISING) {
        return oldClock == Value.FALSE && newClock == Value.TRUE;
    } else if (trigger == StdAttr.TRIG_FALLING) {
        return oldClock == Value.TRUE && newClock == Value.FALSE;
    } else if (trigger == StdAttr.TRIG_HIGH) {
        return newClock == Value.TRUE;
    } else if (trigger == StdAttr.TRIG_LOW) {
        return newClock == Value.FALSE;
    } else {
        return oldClock == Value.FALSE && newClock == Value.TRUE;
    }
}
Also used : Value(com.cburch.logisim.data.Value)

Example 75 with Value

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

the class Counter method DrawControl.

private void DrawControl(InstancePainter painter, int xpos, int ypos) {
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    g.drawLine(xpos + 20, ypos, xpos + 20 + SymbolWidth(width), ypos);
    g.drawLine(xpos + 20, ypos, xpos + 20, ypos + 100);
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos, xpos + 20 + SymbolWidth(width), ypos + 100);
    g.drawLine(xpos + 20, ypos + 100, xpos + 30, ypos + 100);
    g.drawLine(xpos + 10 + SymbolWidth(width), ypos + 100, xpos + 20 + SymbolWidth(width), ypos + 100);
    g.drawLine(xpos + 30, ypos + 100, xpos + 30, ypos + 110);
    g.drawLine(xpos + 10 + SymbolWidth(width), ypos + 100, xpos + 10 + SymbolWidth(width), ypos + 110);
    /* Draw clock entry symbols */
    painter.drawClockSymbol(xpos + 20, ypos + 80);
    painter.drawClockSymbol(xpos + 20, ypos + 90);
    /* Draw Label */
    int max = painter.getAttributeValue(ATTR_MAX).intValue();
    boolean IsCTRm = (max == painter.getAttributeValue(StdAttr.WIDTH).getMask());
    Object onGoal = painter.getAttributeValue(ATTR_ON_GOAL);
    IsCTRm |= onGoal == ON_GOAL_CONT;
    String Label = (IsCTRm) ? "CTR" + Integer.toString(painter.getAttributeValue(StdAttr.WIDTH).getWidth()) : "CTR DIV0x" + Integer.toHexString(max);
    GraphicsUtil.drawCenteredText(g, Label, xpos + (SymbolWidth(width) / 2) + 20, ypos + 5);
    GraphicsUtil.switchToWidth(g, 2);
    /* Draw Reset Input */
    g.drawLine(xpos, ypos + 20, xpos + 20, ypos + 20);
    GraphicsUtil.drawText(g, "R", xpos + 30, ypos + 20, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(CLR);
    /* Draw Load Input */
    g.drawLine(xpos, ypos + 30, xpos + 20, ypos + 30);
    g.drawLine(xpos + 5, ypos + 40, xpos + 12, ypos + 40);
    g.drawLine(xpos + 5, ypos + 30, xpos + 5, ypos + 40);
    g.drawOval(xpos + 12, ypos + 36, 8, 8);
    g.fillOval(xpos + 2, ypos + 27, 6, 6);
    painter.drawPort(LD);
    GraphicsUtil.drawText(g, "M2 [count]", xpos + 30, ypos + 40, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "M1 [load]", xpos + 30, ypos + 30, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    /* Draw UpDn input */
    g.drawLine(xpos, ypos + 50, xpos + 20, ypos + 50);
    g.drawLine(xpos + 5, ypos + 60, xpos + 12, ypos + 60);
    g.drawLine(xpos + 5, ypos + 50, xpos + 5, ypos + 60);
    g.drawOval(xpos + 12, ypos + 56, 8, 8);
    g.fillOval(xpos + 2, ypos + 47, 6, 6);
    GraphicsUtil.drawText(g, "M3 [up]", xpos + 30, ypos + 50, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "M4 [down]", xpos + 30, ypos + 60, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(UD);
    /* Draw Enable Port */
    g.drawLine(xpos, ypos + 70, xpos + 20, ypos + 70);
    GraphicsUtil.drawText(g, "G5", xpos + 30, ypos + 70, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(EN);
    /* Draw Clock */
    boolean inverted = painter.getAttributeValue(StdAttr.EDGE_TRIGGER).equals(StdAttr.TRIG_FALLING);
    int xend = (inverted) ? xpos + 12 : xpos + 20;
    g.drawLine(xpos, ypos + 80, xend, ypos + 80);
    g.drawLine(xpos + 5, ypos + 90, xend, ypos + 90);
    g.drawLine(xpos + 5, ypos + 80, xpos + 5, ypos + 90);
    g.fillOval(xpos + 2, ypos + 77, 6, 6);
    if (inverted) {
        g.drawOval(xend, ypos + 76, 8, 8);
        g.drawOval(xend, ypos + 86, 8, 8);
    }
    GraphicsUtil.drawText(g, "2,3,5+/C6", xpos + 30, ypos + 80, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "2,4,5-", xpos + 30, ypos + 90, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    painter.drawPort(CK);
    /* Draw Carry */
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos + 50, xpos + 40 + SymbolWidth(width), ypos + 50);
    g.drawLine(xpos + 20 + SymbolWidth(width), ypos + 60, xpos + 35 + SymbolWidth(width), ypos + 60);
    g.drawLine(xpos + 35 + SymbolWidth(width), ypos + 50, xpos + 35 + SymbolWidth(width), ypos + 60);
    g.fillOval(xpos + 32 + SymbolWidth(width), ypos + 47, 6, 6);
    String MaxVal = "3CT=0x" + Integer.toHexString(painter.getAttributeValue(ATTR_MAX).intValue()).toUpperCase();
    GraphicsUtil.drawText(g, MaxVal, xpos + 17 + SymbolWidth(width), ypos + 50, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    GraphicsUtil.drawText(g, "4CT=0", xpos + 17 + SymbolWidth(width), ypos + 60, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    painter.drawPort(CARRY);
    GraphicsUtil.switchToWidth(g, 1);
    /* Draw counter Value */
    RegisterData state = (RegisterData) painter.getData();
    if (painter.getShowState() && (state != null)) {
        int len = (width + 3) / 4;
        int xcenter = SymbolWidth(width) - 25;
        Value val = state.value;
        if (val.isFullyDefined())
            g.setColor(Color.LIGHT_GRAY);
        else if (val.isErrorValue())
            g.setColor(Color.RED);
        else
            g.setColor(Color.BLUE);
        g.fillRect(xpos + xcenter - len * 4, ypos + 22, len * 8, 16);
        String Value = "";
        if (val.isFullyDefined()) {
            g.setColor(Color.DARK_GRAY);
            Value = StringUtil.toHexString(width, val.toIntValue()).toUpperCase();
        } else {
            g.setColor(Color.YELLOW);
            for (int i = 0; i < StringUtil.toHexString(width, val.toIntValue()).length(); i++) Value = (val.isUnknown()) ? Value.concat("?") : Value.concat("!");
        }
        GraphicsUtil.drawText(g, Value, xpos + xcenter - len * 4 + 1, ypos + 30, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
        g.setColor(Color.BLACK);
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Aggregations

Value (com.cburch.logisim.data.Value)89 BitWidth (com.cburch.logisim.data.BitWidth)30 Graphics (java.awt.Graphics)15 Location (com.cburch.logisim.data.Location)9 Color (java.awt.Color)8 Bounds (com.cburch.logisim.data.Bounds)7 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)7 AttributeSet (com.cburch.logisim.data.AttributeSet)6 InstanceState (com.cburch.logisim.instance.InstanceState)6 Direction (com.cburch.logisim.data.Direction)3 Instance (com.cburch.logisim.instance.Instance)3 Port (com.cburch.logisim.instance.Port)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 FailException (com.cburch.logisim.data.FailException)2 TestException (com.cburch.logisim.data.TestException)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2