Advertisement
Guest User

Untitled

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