00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dot.hpp"
00016 #include "dotneato.h"
00017 #include "../edgelist.hpp"
00018 #include <qfile.h>
00019 #include <qregexp.h>
00020
00021 Dot::Dot(PropositionGraph* cl)
00022 {
00023 caller = cl;
00024 }
00025
00026 Dot::~Dot()
00027 {
00028 }
00029
00030 void Dot::exportDot(QString filename)
00031 {
00032 QFile file(dir + "/" + filename);
00033 if ( file.open( IO_WriteOnly | IO_Translate ) ) {
00034 QTextStream stream( &file );
00035 stream << "Digraph G {\r\n";
00036 QDictIterator<Proposition> it ( *caller );
00037 for( ; it.current(); ++it ) {
00038 stream << it.current()->name() << "[label=\"" << it.current()->publicName() << "\"];\r\n";
00039 }
00040 EdgeList::iterator ix = caller->edges->begin();
00041 while ( ix != caller->edges->end()) {
00042 stream << " " << (*ix)->source()->name() << " -> " << (*ix)->target()->name() << ";\r\n";
00043 ++ix;
00044 }
00045 stream << "}";
00046 file.close();
00047 }
00048 }
00049
00050 void Dot::callDot()
00051 {
00052 Agraph_t* g , *prev = NULL;
00053 Agnode_t* s, *t;
00054 Agedge_t* e;
00055
00056
00057 aginit();
00058
00059
00060 g = agopen ("propositions", AGDIGRAPHSTRICT);
00061
00062
00063 QDictIterator<Proposition> it ( *caller );
00064 agnodeattr(g,"label"," ");
00065 agraphattr(g,"rankdir", "TB");
00066 agraphattr(g,"shape", " ");
00067 agedgeattr(g,"trust"," ");
00068 for( ; it.current(); ++it ) {
00069 s = agnode(g,(char *) it.current()->name());
00070 agset(s,"label",(char*) it.current()->publicName().ascii() );
00071 }
00072 if (caller->gui->orientation == 0) agset (g, "rankdir", "TB");
00073 else agset(g,"rankdir","LR");
00074
00075
00076 EdgeList::iterator ix = caller->edges->begin();
00077 while ( ix != caller->edges->end()) {
00078 s = agfindnode(g, (char *) (*ix)->source()->name());
00079 t = agfindnode(g, (char *) (*ix)->target()->name());
00080 e = agedge(g, s, t);
00081 agset(e,"trust",(char *) (*ix)->trustString().ascii());
00082 ++ix;
00083 }
00084
00085
00086 dot_layout(g);
00087
00088
00089 point p;
00090 int h, w;
00091
00092
00093 QPoint maxXY = QPoint(GD_bb(g).UR.x , GD_bb(g).UR.y);
00094 caller->checkPos(maxXY);
00095
00096
00097 caller->clearAllEdges();
00098
00099
00100 for (s = agfstnode(g); s; s = agnxtnode(g,s)) {
00101 p = ND_coord_i(s);
00102 h = ND_height(s) * 72;
00103 w = ND_width(s) * 72;
00104
00105 caller->operator[](s->name)->center = QPoint (p.x +5, maxXY.y() - p.y +5);
00106 p.x = p.x - w/2;
00107 p.y = maxXY.y() - p.y + h/2;
00108 caller->operator[](s->name)->setGeometry(p.x +5 ,p.y + 5,w,h);
00109
00110 caller->operator[](s->name)->outgoing->clear();
00111
00112 for (e = agfstout(g,s); e; e = agnxtout(g,e)) {
00113
00114 Edge* E;
00115 E = caller->connect(s->name , e->head->name);
00116 E->setTrust(agget(e,"trust"));
00117
00118 splines* spl = getsplinepoints(e);
00119
00120 int ind = 0;
00121 for (int k = 0 ; k < spl->size ; k++) {
00122 bezier* bzr = spl->list;
00123 spl->list ++ ;
00124 for (int b = 0 ; b < bzr->size; b++) {
00125 (E)->vNodes.putPoints(ind, 1, bzr->list->x + 5, maxXY.y() - bzr->list->y + 5);
00126 bzr->list++;
00127 ind++;
00128 }
00129 }
00130 }
00131 }
00132 agclose(g);
00133 }