Search in sources :

Example 1 with BitWidth

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

the class CanvasPainter method drawWidthIncompatibilityData.

private void drawWidthIncompatibilityData(Graphics base, Graphics g, Project proj) {
    Set<WidthIncompatibilityData> exceptions;
    exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
    if (exceptions == null || exceptions.size() == 0)
        return;
    g.setColor(Value.WIDTH_ERROR_COLOR);
    GraphicsUtil.switchToWidth(g, 2);
    FontMetrics fm = base.getFontMetrics(g.getFont());
    for (WidthIncompatibilityData ex : exceptions) {
        for (int i = 0; i < ex.size(); i++) {
            Location p = ex.getPoint(i);
            BitWidth w = ex.getBitWidth(i);
            // ensure it hasn't already been drawn
            boolean drawn = false;
            for (int j = 0; j < i; j++) {
                if (ex.getPoint(j).equals(p)) {
                    drawn = true;
                    break;
                }
            }
            if (drawn)
                continue;
            // compute the caption combining all similar points
            String caption = "" + w.getWidth();
            for (int j = i + 1; j < ex.size(); j++) {
                if (ex.getPoint(j).equals(p)) {
                    caption += "/" + ex.getBitWidth(j);
                    break;
                }
            }
            g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
            g.drawString(caption, p.getX() + 5, p.getY() + 2 + fm.getAscent());
        }
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 1);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) WidthIncompatibilityData(com.cburch.logisim.circuit.WidthIncompatibilityData) FontMetrics(java.awt.FontMetrics) Location(com.cburch.logisim.data.Location)

Example 2 with BitWidth

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

the class ValueTable method computePreferredSize.

private void computePreferredSize() {
    int oldCellHeight = cellHeight;
    int oldTableWidth = tableWidth;
    int oldTableHeight = tableHeight;
    int columns = model == null ? 0 : model.getColumnCount();
    if (columnWidth == null || columnWidth.length < columns)
        columnWidth = new int[columns];
    if (columns == 0) {
        cellHeight = 16;
        tableWidth = tableHeight = 0;
    } else {
        Graphics g = getGraphics();
        int cellsWidth = 0;
        if (g == null) {
            cellHeight = 16;
            cellsWidth = 24 * columns;
        } else {
            FontMetrics headerMetric = g.getFontMetrics(HEAD_FONT);
            FontMetrics bodyMetric = g.getFontMetrics(BODY_FONT);
            cellHeight = Math.max(headerMetric.getHeight(), bodyMetric.getHeight());
            for (int i = 0; i < columns; i++) {
                int radix = model.getColumnValueRadix(i);
                // column should be at least as wide as 24, as header, and
                // as formatted value
                String header = model.getColumnName(i);
                int cellWidth = Math.max(24, headerMetric.stringWidth(header));
                BitWidth w = model.getColumnValueWidth(i);
                if (w != null) {
                    Value val = Value.createKnown(w, (radix == 2 ? 0 : (radix == 10 ? (1 << (w.getWidth() - 1)) : w.getMask())));
                    String label = val.toDisplayString(radix);
                    cellWidth = Math.max(cellWidth, bodyMetric.stringWidth(label));
                }
                columnWidth[i] = cellWidth;
                cellsWidth += cellWidth;
            }
        }
        tableWidth = cellsWidth + COLUMN_SEP * (columns + 1);
        tableHeight = cellHeight * model.getRowCount();
    }
    if (cellHeight != oldCellHeight || tableWidth != oldTableWidth || tableHeight != oldTableHeight) {
        Dimension headSize = new Dimension(tableWidth, cellHeight + HEADER_SEP);
        Dimension bodySize = new Dimension(tableWidth, tableHeight);
        body.setPreferredSize(bodySize);
        header.setPreferredSize(headSize);
        body.revalidate();
        header.revalidate();
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) FontMetrics(java.awt.FontMetrics) Value(com.cburch.logisim.data.Value) Dimension(java.awt.Dimension)

Example 3 with BitWidth

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

the class TransmissionGate method computeOutput.

private Value computeOutput(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    Value input = state.getPortValue(INPUT);
    Value gate0 = state.getPortValue(GATE0);
    Value gate1 = state.getPortValue(GATE1);
    if (gate0.isFullyDefined() && gate1.isFullyDefined() && gate0 != gate1) {
        if (gate0 == Value.TRUE) {
            return Value.createUnknown(width);
        } else {
            return input;
        }
    } else {
        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);
        }
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 4 with BitWidth

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

the class CircuitState method getValue.

public Value getValue(Location pt) {
    Value ret = values.get(pt);
    if (ret != null)
        return ret;
    BitWidth wid = circuit.getWidth(pt);
    return Value.createUnknown(wid);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 5 with BitWidth

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

the class CircuitWires method getWidthDeterminant.

Location getWidthDeterminant(Location q) {
    BitWidth det = points.getWidth(q);
    if (det != BitWidth.UNKNOWN)
        return q;
    WireBundle qb = getBundleMap().getBundleAt(q);
    if (qb != null && qb.isValid())
        return qb.getWidthDeterminant();
    return q;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

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