1 /* $Id: PNDotVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
2 package dol.visitor.dot;
4 import java.util.Iterator;
6 import dol.datamodel.mapping.ComputationBinding;
7 import dol.datamodel.mapping.Mapping;
8 import dol.datamodel.pn.Channel;
9 import dol.datamodel.pn.Port;
10 import dol.datamodel.pn.Process;
11 import dol.datamodel.pn.ProcessNetwork;
12 import dol.util.CodePrintStream;
13 import dol.visitor.PNVisitor;
16 * This class is a class for a visitor that is used to generate
17 * ".dot" output in order to visualize a PN using the DOTTY tool.
19 public class PNDotVisitor extends PNVisitor {
21 Mapping _mapping = null;
26 * @param printStream print stream to which the contents is written
28 public PNDotVisitor(CodePrintStream printStream) {
29 _printStream = printStream;
33 * Print a .dot file in the correct format for DOTTY.
35 * @param x process network that needs to be rendered
37 public void visitComponent(ProcessNetwork x) {
38 _printStream.printPrefixln("digraph pn {");
39 _printStream.println();
40 _printStream.prefixInc();
41 _printStream.printPrefixln("ratio = auto;");
42 _printStream.printPrefixln("rankdir = LR;");
43 _printStream.printPrefixln("ranksep = 0.3;");
44 _printStream.printPrefixln("nodesep = 0.2;");
45 _printStream.printPrefixln("center = true;");
46 _printStream.printPrefixln("");
47 _printStream.printPrefixln("node [ fontsize=12, height=0.4, "
48 + "width=0.4, style=filled, color=\"0.65 0.20 1.00\" ];");
49 _printStream.printPrefixln("edge [ fontsize=10, arrowhead=normal, "
50 + "arrowsize=0.8, style=\"setlinewidth(2)\" ];");
51 _printStream.println();
54 Iterator<Process> pIter;
56 pIter = x.getProcessList().iterator();
57 while (pIter.hasNext())
62 _printStream.println();
65 Iterator<Channel> cIter;
67 cIter = x.getChannelList().iterator();
68 while( cIter.hasNext() ) {
73 _printStream.prefixDec();
74 _printStream.println();
75 _printStream.printPrefixln("}");
79 * Print a line for the process in the correct format for DOTTY.
81 * @param x process that needs to be rendered
83 public void visitComponent(Process x) {
84 //other colors: beige, lightgoldenrod, orange, tan, khaki3,
85 //aliceblue, lightskyblue, lightseagreen, mintcream,
86 //burlywood3, lightblue1, linen, papayawhip, azure1,2,3
87 String color = "lightskyblue";
89 _printStream.printPrefix();
90 _printStream.print("\"" + x.getName() + "\" [ label=\""
91 + x.getName() + "\", color=" +
93 if (!x.hasInPorts() || !x.hasOutPorts())
94 _printStream.print(", shape=diamond");
96 _printStream.print(", shape=ellipse");
97 _printStream.print(" ];");
98 _printStream.println();
102 * Print a line for the channel in the correct format for DOTTY.
104 * @param x channel that needs to be rendered
106 public void visitComponent(Channel x) {
107 String color = "lightblue3";
109 //change the color of the channel to indicate whether connection
110 //is on-tile or off-tile
111 if (_mapping != null) {
112 String process1 = _mapping.getPN().getProcess(x.getOrigin().
113 getName()).getName();
114 String process2 = _mapping.getPN().getProcess(x.getTarget().
115 getName()).getName();
116 String processor1 = "";
117 String processor2 = "";
119 for (ComputationBinding binding :
120 _mapping.getCompBindList()) {
121 if (binding.getProcess().getName().
123 processor1 = binding.getProcessor().getName();
124 } else if (binding.getProcess().getName().
126 processor2 = binding.getProcessor().getName();
129 if (processor1.equals(processor2)) {
130 } else if (processor1.length() >= 6 && processor2.length() >=6
131 && processor1.substring(0, 6).equals(
132 processor2.substring(0, 6))) {
142 i = x.getPortList().iterator();
144 port = (Port) i.next();
146 portNext = (Port) i.next();
147 _printStream.printPrefix();
149 _printStream.print("\"" + port.getPeerResource().getName()
150 + "\" -> " + "\"" + portNext.getPeerResource().getName()
152 _printStream.print(" label=\"" + x.getName() + "\""
153 + ", color=" + color + " ];");
154 _printStream.println();
160 public void setMapping(Mapping mapping) {