use of com.cburch.logisim.data.Value 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.Value 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.Value in project logisim-evolution by reds-heig.
the class CircuitWires method getThreadValue.
private Value getThreadValue(CircuitState state, WireThread t) {
Value ret = Value.UNKNOWN;
Value pull = Value.UNKNOWN;
for (ThreadBundle tb : t.getBundles()) {
for (Location p : tb.b.points) {
Value val = state.getComponentOutputAt(p);
if (val != null && val != Value.NIL) {
ret = ret.combine(val.get(tb.loc));
}
}
Value pullHere = tb.b.getPullValue();
if (pullHere != Value.UNKNOWN)
pull = pull.combine(pullHere);
}
if (pull != Value.UNKNOWN) {
ret = pullValue(ret, pull);
}
return ret;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class AbstractComponentFactory method paintIcon.
public void paintIcon(ComponentDrawContext context, int x, int y, AttributeSet attrs) {
Graphics g = context.getGraphics();
if (toolIcon != null) {
toolIcon.paintIcon(context.getDestination(), g, x + 2, y + 2);
} else {
g.setColor(Color.black);
g.drawRect(x + 5, y + 2, 11, 17);
Value[] v = { Value.TRUE, Value.FALSE };
for (int i = 0; i < 3; i++) {
g.setColor(v[i % 2].getColor());
g.fillOval(x + 5 - 1, y + 5 + 5 * i - 1, 3, 3);
g.setColor(v[(i + 1) % 2].getColor());
g.fillOval(x + 16 - 1, y + 5 + 5 * i - 1, 3, 3);
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class SplitterPainter method drawLines.
static void drawLines(ComponentDrawContext context, SplitterAttributes attrs, Location origin) {
boolean showState = context.getShowState();
CircuitState state = showState ? context.getCircuitState() : null;
if (state == null)
showState = false;
SplitterParameters parms = attrs.getParameters();
int x0 = origin.getX();
int y0 = origin.getY();
int x = x0 + parms.getEnd0X();
int y = y0 + parms.getEnd0Y();
int dx = parms.getEndToEndDeltaX();
int dy = parms.getEndToEndDeltaY();
int dxEndSpine = parms.getEndToSpineDeltaX();
int dyEndSpine = parms.getEndToSpineDeltaY();
Graphics g = context.getGraphics();
Color oldColor = g.getColor();
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
for (int i = 0, n = attrs.fanout; i < n; i++) {
if (showState) {
Value val = state.getValue(Location.create(x, y));
g.setColor(val.getColor());
}
g.drawLine(x, y, x + dxEndSpine, y + dyEndSpine);
x += dx;
y += dy;
}
GraphicsUtil.switchToWidth(g, SPINE_WIDTH);
g.setColor(oldColor);
int spine0x = x0 + parms.getSpine0X();
int spine0y = y0 + parms.getSpine0Y();
int spine1x = x0 + parms.getSpine1X();
int spine1y = y0 + parms.getSpine1Y();
if (spine0x == spine1x && spine0y == spine1y) {
// centered
int fanout = attrs.fanout;
spine0x = x0 + parms.getEnd0X() + parms.getEndToSpineDeltaX();
spine0y = y0 + parms.getEnd0Y() + parms.getEndToSpineDeltaY();
spine1x = spine0x + (fanout - 1) * parms.getEndToEndDeltaX();
spine1y = spine0y + (fanout - 1) * parms.getEndToEndDeltaY();
if (parms.getEndToEndDeltaX() == 0) {
// vertical spine
if (spine0y < spine1y) {
spine0y++;
spine1y--;
} else {
spine0y--;
spine1y++;
}
g.drawLine(x0 + parms.getSpine1X() / 4, y0, spine0x, y0);
} else {
if (spine0x < spine1x) {
spine0x++;
spine1x--;
} else {
spine0x--;
spine1x++;
}
g.drawLine(x0, y0 + parms.getSpine1Y() / 4, x0, spine0y);
}
if (fanout <= 1) {
// spine is empty
int diam = SPINE_DOT;
g.fillOval(spine0x - diam / 2, spine0y - diam / 2, diam, diam);
} else {
g.drawLine(spine0x, spine0y, spine1x, spine1y);
}
} else {
int[] xSpine = { spine0x, spine1x, x0 + parms.getSpine1X() / 4 };
int[] ySpine = { spine0y, spine1y, y0 + parms.getSpine1Y() / 4 };
g.drawPolyline(xSpine, ySpine, 3);
}
}
Aggregations