use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AppearanceSvgReader method createShape.
public static AbstractCanvasObject createShape(Element elt, Map<Location, Instance> pins) {
String name = elt.getTagName();
if (name.equals("circ-anchor") || name.equals("circ-origin")) {
Location loc = getLocation(elt);
AbstractCanvasObject ret = new AppearanceAnchor(loc);
if (elt.hasAttribute("facing")) {
Direction facing = Direction.parse(elt.getAttribute("facing"));
ret.setValue(AppearanceAnchor.FACING, facing);
}
return ret;
} else if (name.equals("circ-port")) {
Location loc = getLocation(elt);
String[] pinStr = elt.getAttribute("pin").split(",");
Location pinLoc = Location.create(Integer.parseInt(pinStr[0].trim()), Integer.parseInt(pinStr[1].trim()));
Instance pin = pins.get(pinLoc);
if (pin == null) {
return null;
} else {
return new AppearancePort(loc, pin);
}
} else {
return SvgReader.createShape(elt);
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class SplitterAttributes method setValue.
@Override
public <V> void setValue(Attribute<V> attr, V value) {
if (attr == StdAttr.FACING) {
Direction NewFacing = (Direction) value;
if (facing.equals(NewFacing))
return;
facing = (Direction) value;
configureOptions();
parameters = null;
} else if (attr == ATTR_FANOUT) {
int newValue = ((Integer) value).intValue();
byte[] bits = bit_end;
for (int i = 0; i < bits.length; i++) {
if (bits[i] >= newValue)
bits[i] = (byte) (newValue - 1);
}
if (fanout == (byte) newValue)
return;
fanout = (byte) newValue;
configureOptions();
configureDefaults();
parameters = null;
} else if (attr == ATTR_WIDTH) {
BitWidth width = (BitWidth) value;
if (bit_end.length == width.getWidth())
return;
bit_end = new byte[width.getWidth()];
configureOptions();
configureDefaults();
} else if (attr == ATTR_APPEARANCE) {
AttributeOption appearance = (AttributeOption) value;
if (appear.equals(appearance))
return;
appear = appearance;
parameters = null;
} else if (attr instanceof BitOutAttribute) {
BitOutAttribute bitOutAttr = (BitOutAttribute) attr;
int val;
if (value instanceof Integer) {
val = ((Integer) value).intValue();
} else {
val = ((BitOutOption) value).value + 1;
}
if (val >= 0 && val <= fanout) {
if (bit_end[bitOutAttr.which] == (byte) val)
return;
bit_end[bitOutAttr.which] = (byte) val;
} else
return;
} else {
throw new IllegalArgumentException("unknown attribute " + attr);
}
fireAttributeValueChanged(attr, value, null);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class BitSelector method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Plexers.drawTrapezoid(g, painter.getBounds(), facing, 9);
Bounds bds = painter.getBounds();
g.setColor(Color.BLACK);
GraphicsUtil.drawCenteredText(g, "Sel", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class BitSelector method updatePorts.
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
BitWidth group = instance.getAttributeValue(GROUP_ATTR);
int groups = (data.getWidth() + group.getWidth() - 1) / group.getWidth() - 1;
int selectBits = 1;
if (groups > 0) {
while (groups != 1) {
groups >>= 1;
selectBits++;
}
}
BitWidth select = BitWidth.create(selectBits);
Location inPt;
Location selPt;
if (facing == Direction.WEST) {
inPt = Location.create(30, 0);
selPt = Location.create(10, 10);
} else if (facing == Direction.NORTH) {
inPt = Location.create(0, 30);
selPt = Location.create(-10, 10);
} else if (facing == Direction.SOUTH) {
inPt = Location.create(0, -30);
selPt = Location.create(-10, -10);
} else {
inPt = Location.create(-30, 0);
selPt = Location.create(-10, 10);
}
Port[] ps = new Port[3];
ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
instance.setPorts(ps);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class BitSelector method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
Bounds base = Bounds.create(-30, -15, 30, 30);
return base.rotate(Direction.EAST, facing, 0, 0);
}
Aggregations