Advertisement
Guest User

Untitled

a guest
Feb 28th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #include <QApplication>
  2. #include <graphviz/gvc.h>
  3. #include <iostream>
  4.  
  5. void toDot(char* ing)
  6. {
  7.     int err;
  8.     GVC_t* gvc = gvContext();
  9.     Agraph_t* G = agmemread(ing);
  10.     agset(G, (char*) "label", (char*)"");
  11.  
  12.     err = gvLayout (gvc, G, "dot");
  13.     std::cerr << "Layout: " << err << std::endl;
  14.  
  15.     err = gvRenderFilename(gvc, G, "dot", "out.gv");
  16.     std::cerr << "Render: " << err << std::endl;
  17.  
  18.     gvFreeLayout(gvc, G);
  19.     agclose (G);
  20.     gvFreeContext(gvc);
  21. }
  22.  
  23. static char* data =
  24.         "digraph N {\n\
  25.         graph [fontname=Helvetica nodesep=0.25 ranksep=0.25 remincross=true label=\"Petri net\\n&Omega;=((p4=0) &and; (init=0) &and; (p3=0) &and; (p9=0) &and; (p2=0) &and; (final=0) &and; (p5=0) &and; (p7=0) &and; (p1=0) &and; (p8=0) &and; (p6=0))\"]\n\
  26.         node [fontname=Helvetica fixedsize=true width=.3 height=.3 label=\"\" style=filled]\n\
  27.         edge [fontname=Helvetica color=white arrowhead=none weight=20.0]\n\
  28.         \n\
  29.         // interface\n\
  30.         \n\
  31.         // places\n\
  32.         node [shape=circle fillcolor=white]\n\
  33.         p10 []\n\
  34.         p10_l  [style=invis]\n\
  35.         p10_l -> p10 [headlabel=final]\n\
  36.         p11 [fillcolor=black peripheries=2 height=.2 width=.2 ]\n\
  37.         p11_l  [style=invis]\n\
  38.         p11_l -> p11 [headlabel=init]\n\
  39.         p1  []\n\
  40.         p1_l   [style=invis]\n\
  41.         p1_l -> p1 [headlabel=p1]\n\
  42.         p6  []\n\
  43.         p6_l   [style=invis]\n\
  44.         p6_l -> p6 [headlabel=p2]\n\
  45.         p4  []\n\
  46.         p4_l   [style=invis]\n\
  47.         p4_l -> p4 [headlabel=p3]\n\
  48.         p7  []\n\
  49.         p7_l   [style=invis]\n\
  50.         p7_l -> p7 [headlabel=p4]\n\
  51.         p2  []\n\
  52.         p2_l   [style=invis]\n\
  53.         p2_l -> p2 [headlabel=p5]\n\
  54.         p3  []\n\
  55.         p3_l   [style=invis]\n\
  56.         p3_l -> p3 [headlabel=p6]\n\
  57.         p5  []\n\
  58.         p5_l   [style=invis]\n\
  59.         p5_l -> p5 [headlabel=p7]\n\
  60.         p9  []\n\
  61.         p9_l   [style=invis]\n\
  62.         p9_l -> p9 [headlabel=p8]\n\
  63.         p8  []\n\
  64.         p8_l   [style=invis]\n\
  65.         p8_l -> p8 [headlabel=p9]\n\
  66.         // transitions\n\
  67.         node [shape=box]\n\
  68.         t7  []\n\
  69.         t7_l   [style=invis]\n\
  70.         t7_l -> t7 [headlabel=t1]\n\
  71.         t1  []\n\
  72.         t1_l   [style=invis]\n\
  73.         t1_l -> t1 [headlabel=t2]\n\
  74.         t6  []\n\
  75.         t6_l   [style=invis]\n\
  76.         t6_l -> t6 [headlabel=t3]\n\
  77.         t8  []\n\
  78.         t8_l   [style=invis]\n\
  79.         t8_l -> t8 [headlabel=t4]\n\
  80.         t4  []\n\
  81.         t4_l   [style=invis]\n\
  82.         t4_l -> t4 [headlabel=t5]\n\
  83.         t5  []\n\
  84.         t5_l   [style=invis]\n\
  85.         t5_l -> t5 [headlabel=t6]\n\
  86.         t2  []\n\
  87.         t2_l   [style=invis]\n\
  88.         t2_l -> t2 [headlabel=t7]\n\
  89.         t3  []\n\
  90.         t3_l   [style=invis]\n\
  91.         t3_l -> t3 [headlabel=t8]\n\
  92.         \n\
  93.         // inner cluster\n\
  94.         subgraph cluster1\n\
  95. {\n\
  96.     t7 t7_l t1 t1_l t6 t6_l t8 t8_l t4 t4_l t5 t5_l t2 t2_l t3 t3_l\n\
  97.     p10 p10_l p11 p11_l p1 p1_l p6 p6_l p4 p4_l p7 p7_l p2 p2_l p3 p3_l p5 p5_l p9 p9_l p8 p8_l\n\
  98.     label=\"\" style=invis\n\
  99. }\n\
  100. \n\
  101. // arcs\n\
  102. edge [fontname=Helvetica arrowhead=normal color=black]\n\
  103. t3 -> p10  []\n\
  104. p11 -> t7  []\n\
  105. t7 -> p1   []\n\
  106. p1 -> t1   []\n\
  107. t7 -> p6   []\n\
  108. p6 -> t6   []\n\
  109. t1 -> p4   []\n\
  110. p4 -> t8   []\n\
  111. t6 -> p7   []\n\
  112. p7 -> t4   []\n\
  113. t6 -> p2   []\n\
  114. p2 -> t5   []\n\
  115. t4 -> p3   []\n\
  116. t8 -> p3   []\n\
  117. p3 -> t2   []\n\
  118. p5 -> t2   []\n\
  119. t5 -> p5   []\n\
  120. p9 -> t3   []\n\
  121. t2 -> p9   []\n\
  122. t2 -> p8   []\n\
  123. p8 -> t3   []\n\
  124. \n\
  125. \n\
  126. \n\
  127. \n\
  128. \n\
  129. \n\
  130. \n\
  131. \n\
  132. }\n";
  133.  
  134.  
  135. int main(int argc, char *argv[])
  136. {
  137.     QApplication app(argc, argv);
  138.     toDot (data);
  139.  
  140.     return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement