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);
}
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();
}
}
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);
}
}
}
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);
}
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;
}
Aggregations