doc updates to ships
[fleet.git] / src / edu / berkeley / fleet / doc / Doc.java
1 package edu.berkeley.fleet.doc;
2
3 import java.io.*;
4 import java.util.*;
5
6
7 public class Doc {
8     
9     public static void print() throws Exception {
10         if (!new File(".tmp").exists())
11             new File(".tmp").mkdirs();
12         PrintWriter pw = new PrintWriter(new FileOutputStream(".tmp/FleetTwo.Manual.tex"));
13         BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("doc/archman.tex")));
14         for(String s = br.readLine(); s!=null; s = br.readLine())
15             pw.println(s);
16         for(String f : new File("ships").list()) {
17             print(pw, new ShipDescription(f, new BufferedReader(new InputStreamReader(new FileInputStream(new File("ships/"+f))))));
18         }
19         pw.println("\\end{document}");
20         pw.close();
21     }
22
23     private static void print(PrintWriter pw, ShipDescription sd) throws Exception {
24         pw.println("\\pagebreak");
25         pw.println("\\section*{The {\\tt "+sd.getName()+"} Ship}");
26         pw.println("\\addcontentsline{toc}{subsection}{"+sd.getName()+"}");
27         String tex = sd.getSection("tex");
28         /*
29         for(PumpDescription bbd : sd) {
30             pw.println("{\\bf "+(bbd.isInbox() ? "Input: " : "Output: ")+"{\\tt "+bbd.getName()+"}}\n\n");
31         }
32         */
33         int boxGap = 5;
34         int boxHeight = 25;
35         int boxWidth = 75;
36
37         int leftSize = 0;
38         int rightSize = 0;
39         for(PumpDescription bbd : sd)
40             if (bbd.isLeft()) leftSize += (boxHeight+boxGap);
41             else              rightSize += (boxHeight+boxGap);
42
43         int totalHeight = Math.max(leftSize, rightSize);
44         int shipWidth = (int)(boxWidth * 1.5);
45         int totalWidth = boxGap*2 + boxWidth*2 + shipWidth;
46
47         pw.println("");
48         pw.println("\\begin{center}");
49         pw.println("\\begin{empfile}["+sd.getName()+"]");
50         pw.println("\\begin{emp}["+sd.getName()+"]("+(totalWidth+10)+","+(totalHeight+10)+")");
51         pw.println("  beginfig(1)");
52         pw.println("      pickup pencircle scaled 1pt;");
53         pw.println("      draw "+
54                    "("+((totalWidth-shipWidth)/2)+","+0+")--"+
55                    "("+((totalWidth-shipWidth)/2)+","+totalHeight+")--"+
56                    "("+(totalWidth-((totalWidth-shipWidth)/2))+","+totalHeight+")--"+
57                    "("+(totalWidth-((totalWidth-shipWidth)/2))+","+0+")--"+
58                    "("+((totalWidth-shipWidth)/2)+","+0+");");
59         int left = 0;
60         int right = 0;
61         for(PumpDescription bbd : sd) {
62             int ypos = (totalHeight - (boxGap/2) - (bbd.isLeft() ? left : right));
63             int half = (totalWidth-shipWidth)/2;
64             int p1 = bbd.isLeft() ? (half-5) : ((totalWidth-half)+5);
65             int p3 = bbd.isLeft() ? (p1 - boxWidth) : (p1 + boxWidth);
66             if (bbd.isInbox()) {
67                 int p1x = p1;
68                 p1 = p3;
69                 p3 = p1x;
70             }
71             boolean goo = ((bbd.isLeft() && bbd.isInbox()) || (!bbd.isLeft() && bbd.isOutbox()));
72             int p2 = goo ? (p3 - (boxHeight/2)) : (p3 + (boxHeight/2));
73             if (bbd.isLeft()) left += (boxHeight+boxGap);
74             else              right += (boxHeight+boxGap);
75             if (goo) {
76                 pw.println("      label.rt(btex \\tt "+bbd.getName()+" etex, ("+(p1+3)+","+(ypos-boxHeight/2)+"));");
77             } else {
78                 pw.println("      label.lft(btex \\tt "+bbd.getName()+" etex, ("+(p1-3)+","+(ypos-boxHeight/2)+"));");
79             }
80             pw.println("      draw "+
81                        "  ("+p1+","+ypos+")--"+
82                        "  ("+p2+","+ypos+")--"+
83                        "  ("+p3+","+(ypos-(boxHeight/2))+")--"+
84                        "  ("+p2+","+(ypos-boxHeight)+")--"+
85                        "  ("+p1+","+(ypos-boxHeight)+")--"+
86                        "  ("+p1+","+ypos+");");
87             if (bbd.isLeft()) leftSize += boxHeight;
88             else              rightSize += boxHeight;
89         }
90         pw.println("  endfig;");
91         pw.println("\\end{emp}");
92         pw.println("\\end{empfile}");
93         pw.println("\\end{center}");
94         pw.println("");
95
96         if (tex!=null)
97             pw.println(tex);
98     }
99
100 }