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;
56 double TSQR = TSIZE / Math.sqrt(2.0);
62 R gateArea = body.plus(12+N, 12+N, -(4+N), -(4+N));
63 if (xgate==null) ygater = gateArea;
64 else if (ygate==null) xgater = gateArea;
66 double factor = gateArea.width()/2;
67 xgater = gateArea.plus(0, 0, -factor, -factor);
68 ygater = gateArea.plus(factor, 0, 0, -factor);
71 R xring = gateArea.plus(-4, -4, 4, 4);
72 R yring = gateArea.plus(-6, -6, 6, 6);
74 xgate.rotation(fpslicCell.yi());
75 xgate.gateArea = gateArea;
79 ygate.rotation(fpslicCell.yi());
80 ygate.gateArea = gateArea;
85 P p = r.corner(fpslicCell.xi());
87 if (ygate != null) ygate.route(g, p, xring, 1);
88 if (xgate != null) xgate.route(g, p, xring, 0);
91 p = r.corner(fpslicCell.yi());
94 if (ygate != null) ygate.route(g, p, yring, 0);
95 if (xgate != null) xgate.route(g, p, yring, 1);
100 if (fpslicCell.zi() != NONE) {
101 g.color(LOCAL_WIRE_COLOR);
102 int layer = fpslicCell.zi() - L0;
103 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
104 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
105 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
106 g.route(p2, r2, xgate.getInput(3));
109 if (fpslicCell.wi() != NONE) {
110 g.color(LOCAL_WIRE_COLOR);
111 int layer = fpslicCell.wi() - L0;
112 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
113 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
114 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
115 g.route(p2, r2, xgate.getInput(2));
116 g.line(xgate.getInput(2), xgate.getInputDest(2));
118 xgate.draw(g, XGATE_COLOR);
120 if (ygater != null) {
122 if (fpslicCell.zi() != NONE) {
123 g.color(LOCAL_WIRE_COLOR);
124 int layer = fpslicCell.zi() - L0;
125 P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
126 R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
127 r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
128 g.route(p2, r2, ygate.getInput(3));
131 if (fpslicCell.wi() != NONE) {
132 g.color(LOCAL_WIRE_COLOR);
133 int layer = fpslicCell.wi() - 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, ygate.getInput(2));
138 g.line(ygate.getInput(2), ygate.getInputDest(2));
140 ygate.draw(g, YGATE_COLOR);