1 package edu.berkeley.slipway.gui;
3 import com.atmel.fpslic.*;
4 import static com.atmel.fpslic.FpslicConstants.*;
8 public static final int BORDER_COLOR = 0x00BBBBBB;
9 public static final int BODY_COLOR = 0x00555555;
10 public static final int GLOBAL_WIRE_COLOR = 0x00008000;
11 public static final int LOCAL_WIRE_COLOR = 0x000FF000;
12 public static final int XGATE_COLOR = 0x00800000;
13 public static final int YGATE_COLOR = 0x00000080;
14 double MAIN_AREA = 0.75;
16 private final Fpslic.Cell fpslicCell;
17 private GuiGate xgate = null;
18 private GuiGate ygate = null;
20 public GuiCell(Fpslic.Cell fpslicCell) {
21 this.fpslicCell = fpslicCell;
25 * The graphics context argument must already be translated such
26 * that the space allocated to this cell is from (-1,-1) to (1,1)
28 public void draw(G g, R r, boolean selected) {
33 drawGlobalRouting(g, r);
34 if (fpslicCell.relevant()) {
35 xgate = fpslicCell.xlut_relevant() ? new GuiGate() : null;
36 ygate = fpslicCell.ylut_relevant() ? new GuiGate() : null;
41 private void drawGlobalRouting(G g, R r) {
42 g.color(GLOBAL_WIRE_COLOR);
43 for(int i=1; i<6; i++) {
44 g.line(r.minx() + 2*i, r.miny(),
45 r.minx() + 2*i, r.maxy());
46 g.line(r.minx(), r.miny() + 2*i,
47 r.maxx(), r.miny() + 2*i);
51 private void drawBody(G g, R r) {
52 if (xgate == null && ygate == null) return;
58 R gateArea = body.plus(12+N, 12+N, -(4+N), -(4+N));
59 if (xgate==null) ygater = gateArea;
60 else if (ygate==null) xgater = gateArea;
62 double factor = gateArea.width()/2;
63 xgater = gateArea.plus(0, 0, -factor, -factor);
64 ygater = gateArea.plus(factor, 0, 0, -factor);
67 R xring = gateArea.plus(-4, -4, 4, 4);
68 R yring = gateArea.plus(-6, -6, 6, 6);
71 switch (fpslicCell.yi()) {
72 case NORTH: rot = 2; break;
73 case SOUTH: rot = 0; break;
74 case WEST: rot = 3; break;
75 case EAST: rot = 1; break;
80 xgate.gateArea = gateArea;
85 ygate.gateArea = gateArea;
90 double TSQR = TSIZE / Math.sqrt(2.0);
93 switch (fpslicCell.xi()) {
94 case SW: p = new P(r.minx(), r.miny()); break;
95 case SE: p = new P(r.maxx(), r.miny()); break;
96 case NW: p = new P(r.minx(), r.maxy()); break;
97 case NE: p = new P(r.maxx(), r.maxy()); break;
101 g.route(p, xring, ygate.getInput(1));
102 g.line(ygate.getInput(1), ygate.getInputDest(1));
105 g.route(p, xring, xgate.getInput(0));
106 g.line(xgate.getInput(0), xgate.getInputDest(0));
111 g.color(YGATE_COLOR);
112 switch (fpslicCell.yi()) {
113 case NORTH: p = new P(r.cx(), r.maxy()); break;
114 case SOUTH: p = new P(r.cx(), r.miny()); break;
115 case WEST: p = new P(r.minx(), r.cy()); break;
116 case EAST: p = new P(r.maxx(), r.cy()); break;
120 g.route(p, yring, ygate.getInput(0));
121 g.line(ygate.getInput(0), ygate.getInputDest(0));
124 g.route(p, yring, xgate.getInput(1));
125 g.line(xgate.getInput(1), xgate.getInputDest(1));
129 if (xgater != null) {
131 if (fpslicCell.zi() != NONE) {
132 g.color(LOCAL_WIRE_COLOR);
133 int layer = fpslicCell.zi() - L0;
134 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
135 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
136 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
137 g.route(p2, r2, xgate.getInput(3));
140 if (fpslicCell.wi() != NONE) {
141 g.color(LOCAL_WIRE_COLOR);
142 int layer = fpslicCell.wi() - L0;
143 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
144 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
145 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
146 g.route(p2, r2, xgate.getInput(2));
147 g.line(xgate.getInput(2), xgate.getInputDest(2));
149 xgate.draw(g, XGATE_COLOR);
151 if (ygater != null) {
153 if (fpslicCell.zi() != NONE) {
154 g.color(LOCAL_WIRE_COLOR);
155 int layer = fpslicCell.zi() - L0;
156 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
157 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
158 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
159 g.route(p2, r2, ygate.getInput(3));
162 if (fpslicCell.wi() != NONE) {
163 g.color(LOCAL_WIRE_COLOR);
164 int layer = fpslicCell.wi() - L0;
165 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
166 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
167 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
168 g.route(p2, r2, ygate.getInput(2));
169 g.line(ygate.getInput(2), ygate.getInputDest(2));
171 ygate.draw(g, YGATE_COLOR);