Search in sources :

Example 71 with BitWidth

use of com.cburch.logisim.data.BitWidth 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 BitWidth

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

the class Constant method propagate.

@Override
public void propagate(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    int value = state.getAttributeValue(ATTR_VALUE).intValue();
    state.setPort(0, Value.createKnown(width, value), 1);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 73 with BitWidth

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

the class Ground method propagate.

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

Example 74 with BitWidth

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

the class Ground 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.FALSE, width.getWidth()).getColor());
    }
    g.drawLine(6, -8, 6, 8);
    g.drawLine(9, -5, 9, 5);
    g.drawLine(12, -2, 12, 2);
    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 75 with BitWidth

use of com.cburch.logisim.data.BitWidth 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)

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