boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
int inputs = 1 << select.getWidth();
Port[] ps = new Port[inputs + (enable ? 3 : 2)];
Location sel;
if (inputs == 2) {
Location end0;
Location end1;
if (dir == Direction.WEST) {
end0 = Location.create(30, -10);
end1 = Location.create(30, 10);
sel = Location.create(20, selMult * 20);
} else if (dir == Direction.NORTH) {
end0 = Location.create(-10, 30);
end1 = Location.create( 10, 30);
sel = Location.create(selMult * -20, 20);
} else if (dir == 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.INPUT, data.getWidth());
ps[1] = new Port(end1.getX(), end1.getY(), Port.INPUT, data.getWidth());
} else {
int dx = -(inputs / 2) * 10;
int ddx = 10;
int dy = -(inputs / 2) * 10;
int ddy = 10;
if (dir == Direction.WEST) {
dx = 40; ddx = 0;
sel = Location.create(20, selMult * (dy + 10 * inputs));
} else if (dir == Direction.NORTH) {
dy = 40; ddy = 0;
sel = Location.create(selMult * dx, 20);
} else if (dir == Direction.SOUTH) {
dy = -40; ddy = 0;
sel = Location.create(selMult * dx, -20);
} else {
dx = -40; ddx = 0;
sel = Location.create(-20, selMult * (dy + 10 * inputs));
}
for (int i = 0; i < inputs; i++) {
ps[i] = new Port(dx, dy, Port.INPUT, data.getWidth());
dx += ddx;
dy += ddy;
}
}
Location en = sel.translate(dir, 10);
ps[inputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
if (enable) {
ps[inputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
}
ps[ps.length - 1] = new Port(0, 0, Port.OUTPUT, data.getWidth());
for (int i = 0; i < inputs; i++) {
ps[i].setToolTip(Strings.getter("multiplexerInTip", "" + i));