use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Pin method getState.
private static PinState getState(InstanceState state) {
PinAttributes attrs = (PinAttributes) state.getAttributeSet();
BitWidth width = attrs.width;
PinState ret = (PinState) state.getData();
if (ret == null) {
Value val = attrs.threeState ? Value.UNKNOWN : Value.FALSE;
if (width.getWidth() > 1) {
Value[] arr = new Value[width.getWidth()];
java.util.Arrays.fill(arr, val);
val = Value.create(arr);
}
ret = new PinState(val, val);
state.setData(ret);
}
if (ret.intendedValue.getWidth() != width.getWidth()) {
ret.intendedValue = ret.intendedValue.extendWidth(width.getWidth(), attrs.threeState ? Value.UNKNOWN : Value.FALSE);
}
if (ret.foundValue.getWidth() != width.getWidth()) {
ret.foundValue = ret.foundValue.extendWidth(width.getWidth(), Value.UNKNOWN);
}
return ret;
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class PinAttributes method setValue.
@Override
public <V> void setValue(Attribute<V> attr, V value) {
V oldvalue = null;
if (attr == StdAttr.WIDTH) {
BitWidth NewWidth = (BitWidth) value;
if (width == NewWidth)
return;
width = (BitWidth) value;
} else if (attr == Pin.ATTR_TRISTATE) {
boolean NewThree = ((Boolean) value).booleanValue();
if (threeState == NewThree)
return;
threeState = NewThree;
} else if (attr == Pin.ATTR_TYPE) {
int Newtype = ((Boolean) value).booleanValue() ? EndData.OUTPUT_ONLY : EndData.INPUT_ONLY;
if (type == Newtype)
return;
type = Newtype;
} else if (attr == Pin.ATTR_PULL) {
Object newPull = value;
if (pull.equals(newPull))
return;
pull = newPull;
} else {
oldvalue = (V) super.getValue(attr);
super.setValue(attr, value);
return;
}
fireAttributeValueChanged(attr, value, oldvalue);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Power method propagate.
@Override
public void propagate(InstanceState state) {
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
state.setPort(0, Value.repeat(Value.TRUE, width.getWidth()), 1);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Power 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.TRUE, width.getWidth()).getColor());
}
g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
g.dispose();
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class BitExtender method paintInstance.
//
// graphics methods
//
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
FontMetrics fm = g.getFontMetrics();
int asc = fm.getAscent();
painter.drawBounds();
String s0;
String type = getType(painter.getAttributeSet());
if (type.equals("zero"))
s0 = Strings.get("extenderZeroLabel");
else if (type.equals("one"))
s0 = Strings.get("extenderOneLabel");
else if (type.equals("sign"))
s0 = Strings.get("extenderSignLabel");
else if (type.equals("input"))
s0 = Strings.get("extenderInputLabel");
else
// should never happen
s0 = "???";
String s1 = Strings.get("extenderMainLabel");
Bounds bds = painter.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y0 = bds.getY() + (bds.getHeight() / 2 + asc) / 2;
int y1 = bds.getY() + (3 * bds.getHeight() / 2 + asc) / 2;
GraphicsUtil.drawText(g, s0, x, y0, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
GraphicsUtil.drawText(g, s1, x, y1, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
BitWidth w0 = painter.getAttributeValue(ATTR_OUT_WIDTH);
BitWidth w1 = painter.getAttributeValue(ATTR_IN_WIDTH);
painter.drawPort(0, "" + w0.getWidth(), Direction.WEST);
painter.drawPort(1, "" + w1.getWidth(), Direction.EAST);
if (type.equals("input"))
painter.drawPort(2);
}
Aggregations