dol: initial dol commit
[jump.git] / dol / src / dol / visitor / dot / MapDotVisitor.java
1 /* $Id: MapDotVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.dot;
3
4 import java.util.Iterator;
5
6 import dol.datamodel.architecture.Processor;
7 import dol.datamodel.mapping.Mapping;
8 import dol.datamodel.pn.Channel;
9 import dol.util.CodePrintStream;
10 import dol.visitor.MapVisitor;
11
12 /**
13  * This class is a class for a visitor that is used to generate
14  * ".dot" output in order to visualize a mapping using the DOTTY tool.
15  */
16 public class MapDotVisitor extends MapVisitor {
17
18     /**
19      * Constructor.
20      *
21      * @param printStream print stream to which the contents is written
22      */
23     public MapDotVisitor(CodePrintStream printStream) {
24         _printStream = printStream;
25         _pnVisitor = new PNDotVisitor(printStream);
26         _archiVisitor = new ArchDotVisitor(printStream);
27     }
28
29     /**
30      * Print a .dot file in the correct format for DOTTY.
31      *
32      * @param map process network that needs to be rendered
33      */
34     public void visitComponent(Mapping map) {
35         _printStream.printPrefixln("digraph mapping {");
36         _printStream.println();
37         _printStream.prefixInc();
38         _printStream.printPrefixln("ratio = auto;");
39         _printStream.printPrefixln("rankdir = LR;");
40         _printStream.printPrefixln("ranksep = 0.3;");
41         _printStream.printPrefixln("nodesep = 0.2;");
42         _printStream.printPrefixln("center = true;");
43         _printStream.printPrefixln("");
44         _printStream.printPrefixln("node [ fontsize=12, height=0.4, "
45                 + "width=0.4, style=filled, color=\"0.65 0.20 1.00\" ];");
46         _printStream.printPrefixln("edge [ fontsize=10, arrowhead=normal, "
47                 + "arrowsize=0.8, style=\"setlinewidth(2)\" ];");
48         _printStream.println();
49
50         //visit all processors
51         Processor processor;
52         Iterator<Processor> processorIter = map.getProcessorList().iterator();
53         while( processorIter.hasNext() )
54         {
55             processor = processorIter.next();
56             processor.accept(_archiVisitor);
57         }
58         
59         //visit all channels (from PN)
60         _pnVisitor.setMapping(map);
61         Channel chan;
62         Iterator<Channel> chanIter = map.getPN().getChannelList().iterator();
63         while (chanIter.hasNext() )
64         {
65             chan = chanIter.next();
66             chan.accept(_pnVisitor);
67         }
68
69         _printStream.prefixDec();
70         _printStream.println();
71         _printStream.printPrefixln("}");
72     }
73
74
75     /** DOT Visitor to visit process network resources */
76     protected PNDotVisitor _pnVisitor = null;
77
78     /** DOT Visitor to visit architecture resources */
79     protected ArchDotVisitor _archiVisitor = null;
80 }