dol: initial dol commit
[jump.git] / dol / src / dol / visitor / dot / MapDotVisitor.java
diff --git a/dol/src/dol/visitor/dot/MapDotVisitor.java b/dol/src/dol/visitor/dot/MapDotVisitor.java
new file mode 100644 (file)
index 0000000..581c615
--- /dev/null
@@ -0,0 +1,80 @@
+/* $Id: MapDotVisitor.java 1 2010-02-24 13:03:05Z haidw $ */
+package dol.visitor.dot;
+
+import java.util.Iterator;
+
+import dol.datamodel.architecture.Processor;
+import dol.datamodel.mapping.Mapping;
+import dol.datamodel.pn.Channel;
+import dol.util.CodePrintStream;
+import dol.visitor.MapVisitor;
+
+/**
+ * This class is a class for a visitor that is used to generate
+ * ".dot" output in order to visualize a mapping using the DOTTY tool.
+ */
+public class MapDotVisitor extends MapVisitor {
+
+    /**
+     * Constructor.
+     *
+     * @param printStream print stream to which the contents is written
+     */
+    public MapDotVisitor(CodePrintStream printStream) {
+        _printStream = printStream;
+        _pnVisitor = new PNDotVisitor(printStream);
+        _archiVisitor = new ArchDotVisitor(printStream);
+    }
+
+    /**
+     * Print a .dot file in the correct format for DOTTY.
+     *
+     * @param map process network that needs to be rendered
+     */
+    public void visitComponent(Mapping map) {
+        _printStream.printPrefixln("digraph mapping {");
+        _printStream.println();
+        _printStream.prefixInc();
+        _printStream.printPrefixln("ratio = auto;");
+        _printStream.printPrefixln("rankdir = LR;");
+        _printStream.printPrefixln("ranksep = 0.3;");
+        _printStream.printPrefixln("nodesep = 0.2;");
+        _printStream.printPrefixln("center = true;");
+        _printStream.printPrefixln("");
+        _printStream.printPrefixln("node [ fontsize=12, height=0.4, "
+                + "width=0.4, style=filled, color=\"0.65 0.20 1.00\" ];");
+        _printStream.printPrefixln("edge [ fontsize=10, arrowhead=normal, "
+                + "arrowsize=0.8, style=\"setlinewidth(2)\" ];");
+        _printStream.println();
+
+        //visit all processors
+        Processor processor;
+        Iterator<Processor> processorIter = map.getProcessorList().iterator();
+        while( processorIter.hasNext() )
+        {
+            processor = processorIter.next();
+            processor.accept(_archiVisitor);
+        }
+        
+        //visit all channels (from PN)
+        _pnVisitor.setMapping(map);
+        Channel chan;
+        Iterator<Channel> chanIter = map.getPN().getChannelList().iterator();
+        while (chanIter.hasNext() )
+        {
+            chan = chanIter.next();
+            chan.accept(_pnVisitor);
+        }
+
+        _printStream.prefixDec();
+        _printStream.println();
+        _printStream.printPrefixln("}");
+    }
+
+
+    /** DOT Visitor to visit process network resources */
+    protected PNDotVisitor _pnVisitor = null;
+
+    /** DOT Visitor to visit architecture resources */
+    protected ArchDotVisitor _archiVisitor = null;
+}