update libraries in lib/
[fleet.git] / src / edu / berkeley / fleet / doc / Doc.java
index 48ca5a5..8d23880 100644 (file)
@@ -14,7 +14,7 @@ public class Doc {
         for(String s = br.readLine(); s!=null; s = br.readLine())
             pw.println(s);
         for(String f : new File("ships").list()) {
-            print(pw, new ShipDescription(new BufferedReader(new InputStreamReader(new FileInputStream(new File("ships/"+f))))));
+            print(pw, new ShipDescription(f, new BufferedReader(new InputStreamReader(new FileInputStream(new File("ships/"+f))))));
         }
         pw.println("\\end{document}");
         pw.close();
@@ -23,12 +23,78 @@ public class Doc {
     private static void print(PrintWriter pw, ShipDescription sd) throws Exception {
         pw.println("\\pagebreak");
         pw.println("\\section*{The {\\tt "+sd.getName()+"} Ship}");
+        pw.println("\\addcontentsline{toc}{subsection}{"+sd.getName()+"}");
         String tex = sd.getSection("tex");
+        /*
+        for(PumpDescription bbd : sd) {
+            pw.println("{\\bf "+(bbd.isInbox() ? "Input: " : "Output: ")+"{\\tt "+bbd.getName()+"}}\n\n");
+        }
+        */
+        int boxGap = 5;
+        int boxHeight = 25;
+        int boxWidth = 75;
+
+        int leftSize = 0;
+        int rightSize = 0;
+        for(PumpDescription bbd : sd)
+            if (bbd.isLeft()) leftSize += (boxHeight+boxGap);
+            else              rightSize += (boxHeight+boxGap);
+
+        int totalHeight = Math.max(leftSize, rightSize);
+        int shipWidth = (int)(boxWidth * 1.5);
+        int totalWidth = boxGap*2 + boxWidth*2 + shipWidth;
+
+        pw.println("");
+        pw.println("\\begin{center}");
+        pw.println("\\begin{empfile}["+sd.getName()+"]");
+        pw.println("\\begin{emp}["+sd.getName()+"]("+(totalWidth+10)+","+(totalHeight+10)+")");
+        pw.println("  beginfig(1)");
+        pw.println("      pickup pencircle scaled 1pt;");
+        pw.println("      draw "+
+                   "("+((totalWidth-shipWidth)/2)+","+0+")--"+
+                   "("+((totalWidth-shipWidth)/2)+","+totalHeight+")--"+
+                   "("+(totalWidth-((totalWidth-shipWidth)/2))+","+totalHeight+")--"+
+                   "("+(totalWidth-((totalWidth-shipWidth)/2))+","+0+")--"+
+                   "("+((totalWidth-shipWidth)/2)+","+0+");");
+        int left = 0;
+        int right = 0;
+        for(PumpDescription bbd : sd) {
+            int ypos = (totalHeight - (boxGap/2) - (bbd.isLeft() ? left : right));
+            int half = (totalWidth-shipWidth)/2;
+            int p1 = bbd.isLeft() ? (half-5) : ((totalWidth-half)+5);
+            int p3 = bbd.isLeft() ? (p1 - boxWidth) : (p1 + boxWidth);
+            if (bbd.isInbox()) {
+                int p1x = p1;
+                p1 = p3;
+                p3 = p1x;
+            }
+            boolean goo = ((bbd.isLeft() && bbd.isInbox()) || (!bbd.isLeft() && bbd.isOutbox()));
+            int p2 = goo ? (p3 - (boxHeight/2)) : (p3 + (boxHeight/2));
+            if (bbd.isLeft()) left += (boxHeight+boxGap);
+            else              right += (boxHeight+boxGap);
+            if (goo) {
+                pw.println("      label.rt(btex \\tt "+bbd.getName()+" etex, ("+(p1+3)+","+(ypos-boxHeight/2)+"));");
+            } else {
+                pw.println("      label.lft(btex \\tt "+bbd.getName()+" etex, ("+(p1-3)+","+(ypos-boxHeight/2)+"));");
+            }
+            pw.println("      draw "+
+                       "  ("+p1+","+ypos+")--"+
+                       "  ("+p2+","+ypos+")--"+
+                       "  ("+p3+","+(ypos-(boxHeight/2))+")--"+
+                       "  ("+p2+","+(ypos-boxHeight)+")--"+
+                       "  ("+p1+","+(ypos-boxHeight)+")--"+
+                       "  ("+p1+","+ypos+");");
+            if (bbd.isLeft()) leftSize += boxHeight;
+            else              rightSize += boxHeight;
+        }
+        pw.println("  endfig;");
+        pw.println("\\end{emp}");
+        pw.println("\\end{empfile}");
+        pw.println("\\end{center}");
+        pw.println("");
+
         if (tex!=null)
             pw.println(tex);
-        for(BenkoBoxDescription bbd : sd) {
-            pw.println("\\subsection*{"+(bbd.isInbox() ? "Inbox: " : "Outbox: ")+"{\\tt "+bbd.getName()+"}}");
-        }
     }
 
 }
\ No newline at end of file