}
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int outputs = 1 << select.getWidth();
Port[] ps = new Port[outputs + (enable ? 3 : 2)];
Location sel;
int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
if (outputs == 2) {
Location end0;
Location end1;
if (facing == Direction.WEST) {
end0 = Location.create(-30, -10);
end1 = Location.create(-30, 10);
sel = Location.create(-20, selMult * 20);
} else if (facing == Direction.NORTH) {
end0 = Location.create(-10, -30);
end1 = Location.create( 10, -30);
sel = Location.create(selMult * -20, -20);
} else if (facing == Direction.SOUTH) {
end0 = Location.create(-10, 30);
end1 = Location.create( 10, 30);
sel = Location.create(selMult * -20, 20);
} else {
end0 = Location.create(30, -10);
end1 = Location.create(30, 10);
sel = Location.create(20, selMult * 20);
}
ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, data.getWidth());
ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, data.getWidth());
} else {
int dx = -(outputs / 2) * 10;
int ddx = 10;
int dy = dx;
int ddy = 10;
if (facing == Direction.WEST) {
dx = -40; ddx = 0;
sel = Location.create(-20, selMult * (dy + 10 * outputs));
} else if (facing == Direction.NORTH) {
dy = -40; ddy = 0;
sel = Location.create(selMult * dx, -20);
} else if (facing == Direction.SOUTH) {
dy = 40; ddy = 0;
sel = Location.create(selMult * dx, 20);
} else {
dx = 40; ddx = 0;
sel = Location.create(20, selMult * (dy + 10 * outputs));
}
for (int i = 0; i < outputs; i++) {
ps[i] = new Port(dx, dy, Port.OUTPUT, data.getWidth());
dx += ddx;
dy += ddy;
}
}
Location en = sel.translate(facing, -10);
ps[outputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
if (enable) {
ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
}
ps[ps.length - 1] = new Port(0, 0, Port.INPUT, data.getWidth());