From: adam Date: Tue, 28 Aug 2007 00:23:34 +0000 (+0100) Subject: support for drawing ship diagrams X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=ef023c8cb42adc9d387d8fc9a233d1ba117fb7e9;p=fleet.git support for drawing ship diagrams --- diff --git a/src/edu/berkeley/fleet/doc/Doc.java b/src/edu/berkeley/fleet/doc/Doc.java index 7c0b680..58ba206 100644 --- a/src/edu/berkeley/fleet/doc/Doc.java +++ b/src/edu/berkeley/fleet/doc/Doc.java @@ -24,11 +24,76 @@ public class Doc { pw.println("\\pagebreak"); pw.println("\\section*{The {\\tt "+sd.getName()+"} Ship}"); String tex = sd.getSection("tex"); - if (tex!=null) - pw.println(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) { - pw.println("\\subsection*{"+(bbd.isInbox() ? "Input: " : "Output: ")+"{\\tt "+bbd.getName()+"}}"); + 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); } } \ No newline at end of file