checkpoint
[slipway.git] / src / edu / berkeley / slipway / gui / GuiCell.java
index ebd3044..283c9d4 100644 (file)
@@ -11,11 +11,12 @@ public class GuiCell {
     public static final int LOCAL_WIRE_COLOR  = 0x000FF000;
     public static final int XGATE_COLOR       = 0x00800000;
     public static final int YGATE_COLOR       = 0x00000080;
-    double MAIN_AREA = 0.75;
+
+    private static final int LOCAL_ROUTING_CHANNEL_WIDTH = 7;
 
     private final Fpslic.Cell fpslicCell;
-    private GuiGate xgate = null;
-    private GuiGate ygate = null;
+    private GuiGate xgate = new GuiGate();
+    private GuiGate ygate = new GuiGate();
 
     public GuiCell(Fpslic.Cell fpslicCell) {
         this.fpslicCell = fpslicCell;
@@ -32,8 +33,8 @@ public class GuiCell {
         }
         drawGlobalRouting(g, r);
         if (fpslicCell.relevant()) {
-            xgate = fpslicCell.xlut_relevant() ? new GuiGate() : null;
-            ygate = fpslicCell.ylut_relevant() ? new GuiGate() : null;
+            xgate.disabled = !fpslicCell.xlut_relevant();
+            ygate.disabled = !fpslicCell.ylut_relevant();
             drawBody(g, r);
         }
     }
@@ -41,115 +42,54 @@ public class GuiCell {
     private void drawGlobalRouting(G g, R r) {
         g.color(GLOBAL_WIRE_COLOR);
         for(int i=1; i<6; i++) {
-            g.line(r.minx() + 2*i, r.miny(),
-                   r.minx() + 2*i, r.maxy());
-            g.line(r.minx(),       r.miny() + 2*i,
-                   r.maxx(),       r.miny() + 2*i);
+            g.line(r.corner(SW).translate(2*i,0),
+                   r.corner(NW).translate(2*i,0));
+            g.line(r.corner(SW).translate(0,2*i),
+                   r.corner(SE).translate(0,2*i));
         }
     }
 
     private void drawBody(G g, R r) {
-        if (xgate == null && ygate == null) return;
+        if (xgate.disabled && ygate.disabled) return;
 
-        int N = 7;
-        int TSIZE   = 10;
-        double TSQR = TSIZE / Math.sqrt(2.0);
+        R gateArea =
+            xgate.gateArea = 
+            ygate.gateArea = 
+            r.plus(12+LOCAL_ROUTING_CHANNEL_WIDTH,
+                   12+LOCAL_ROUTING_CHANNEL_WIDTH,
+                   -(4+LOCAL_ROUTING_CHANNEL_WIDTH),
+                   -(4+LOCAL_ROUTING_CHANNEL_WIDTH));
 
-        R body = r;
-        g.color(BODY_COLOR);
-        R xgater = null;
-        R ygater = null;
-        R gateArea = body.plus(12+N, 12+N, -(4+N), -(4+N));
-        if      (xgate==null) ygater = gateArea;
-        else if (ygate==null) xgater = gateArea;
-        else {
-            double factor = gateArea.width()/2;
-            xgater = gateArea.plus(0, 0, -factor, -factor);
-            ygater = gateArea.plus(factor, 0, 0, -factor);
-        }
+        double factor = gateArea.width()/2;
+        xgate.r = xgate.disabled || ygate.disabled ? gateArea : gateArea.plus(factor, 0, 0, -factor);
+        ygate.r = xgate.disabled || ygate.disabled ? gateArea : gateArea.plus(0, 0, -factor, -factor);
 
+        P xip   = r.corner(fpslicCell.xi());
+        P yip   = r.corner(fpslicCell.yi());
         R xring = gateArea.plus(-4, -4, 4, 4);
         R yring = gateArea.plus(-6, -6, 6, 6);
-        if (xgate != null) {
-            xgate.rotation(fpslicCell.yi());
-            xgate.gateArea = gateArea;
-            xgate.r = xgater;
-        }
-        if (ygate != null) {
-            ygate.rotation(fpslicCell.yi());
-            ygate.gateArea = gateArea;
-            ygate.r = ygater;
-        }
+        xgate.rotation(fpslicCell.yi());
+        ygate.rotation(fpslicCell.yi());
+        if (xip != null) xgate.route(g, xip, xring, 0, XGATE_COLOR);
+        if (yip != null) xgate.route(g, yip, yring, 2, YGATE_COLOR);
+        if (xip != null) ygate.route(g, xip, xring, 2, XGATE_COLOR);
+        if (yip != null) ygate.route(g, yip, yring, 0, YGATE_COLOR);
 
-        g.color(XGATE_COLOR);
-        P p = r.corner(fpslicCell.xi());
-        if (p!=null) {
-            if (ygate != null) {
-                g.route(p, xring, ygate.getInput(1));
-                g.line(ygate.getInput(1), ygate.getInputDest(1));
-            }
-            if (xgate != null) {
-                g.route(p, xring, xgate.getInput(0));
-                g.line(xgate.getInput(0), xgate.getInputDest(0));
-            }
-        }
+        drawWin(g, r);
+        drawGates(g);
+    }
 
-        p = r.corner(fpslicCell.yi());
-        g.color(YGATE_COLOR);
-        if (p!=null) {
-            if (ygate != null) {
-                g.route(p, yring, ygate.getInput(0));
-                g.line(ygate.getInput(0), ygate.getInputDest(0));
-            }
-            if (xgate != null) {
-                g.route(p, yring, xgate.getInput(1));
-                g.line(xgate.getInput(1), xgate.getInputDest(1));
-            }
-        }
+    private void drawWin(G g, R r) {
+        int layer = fpslicCell.wi() - L0;
+        P   wip   = r.corner(SW).translate(2*(layer+1), 2*(layer+1));
+        R   wring = r.plus(2*(layer+1), 2*(layer+1), -2*(layer+1), -2*(layer+1));
+        ygate.route(g, wip, wring, 1, LOCAL_WIRE_COLOR);
+        xgate.route(g, wip, wring, 1, LOCAL_WIRE_COLOR);
+    }
 
-        if (xgater != null) {
-            /*
-            if (fpslicCell.zi() != NONE) {
-                g.color(LOCAL_WIRE_COLOR);
-                int layer = fpslicCell.zi() - L0;
-                P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
-                R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
-                             r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
-                g.route(p2, r2, xgate.getInput(3));
-            }
-            */
-            if (fpslicCell.wi() != NONE) {
-                g.color(LOCAL_WIRE_COLOR);
-                int layer = fpslicCell.wi() - L0;
-                P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
-                R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
-                             r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
-                g.route(p2, r2, xgate.getInput(2));
-                g.line(xgate.getInput(2), xgate.getInputDest(2));
-            }
-            xgate.draw(g, XGATE_COLOR);
-        }
-        if (ygater != null) {
-            /*
-            if (fpslicCell.zi() != NONE) {
-                g.color(LOCAL_WIRE_COLOR);
-                int layer = fpslicCell.zi() - L0;
-                P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
-                R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
-                             r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
-                g.route(p2, r2, ygate.getInput(3));
-            }
-            */
-            if (fpslicCell.wi() != NONE) {
-                g.color(LOCAL_WIRE_COLOR);
-                int layer = fpslicCell.wi() - L0;
-                P p2 = new P(r.minx()+2*(layer+1), r.miny()+2*(layer+1));
-                R r2 = new R(r.minx()+2*(layer+1), r.miny()+2*(layer+1),
-                             r.maxx()-2*(layer+1), r.maxy()-2*(layer+1));
-                g.route(p2, r2, ygate.getInput(2));
-                g.line(ygate.getInput(2), ygate.getInputDest(2));
-            }
-            ygate.draw(g, YGATE_COLOR);
-        }
+    private void drawGates(G g) {
+        xgate.draw(g, XGATE_COLOR);
+        ygate.draw(g, YGATE_COLOR);
     }
+
 }
\ No newline at end of file