Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

dot.cpp

Go to the documentation of this file.
00001 /*
00002  Modular Psi - A graph tracker of the Parapsychologcal scientific development
00003  Copyright (C) 2005 Leonardo Stern
00004 
00005  This program is free software; you can redistribute it and/or modify it under
00006  the terms of the Common Public License Version 1.0 or (at your option) any later version.
00007 
00008  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
00009  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00010  See the Common Public License for more details.
00011 
00012  You should have received a copy of the Common Public License along with this program;
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     // initialize graphviz
00057     aginit();
00058     
00059     // prepare for strict digraph 
00060     g = agopen ("propositions", AGDIGRAPHSTRICT);
00061     
00062     // insert nodes in graphviz
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     // insert edges in graphviz
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     // tells graphviz to calculate nodes position and size and edges bendpoints.
00086     dot_layout(g);
00087     
00088      // send information back to the modularpsi
00089     point p;
00090     int h, w;
00091     
00092     // set bounds
00093     QPoint maxXY = QPoint(GD_bb(g).UR.x , GD_bb(g).UR.y);
00094     caller->checkPos(maxXY);
00095 
00096     //delete edges (because its faster than find and edit then or to use unique ids for edges0
00097     caller->clearAllEdges();
00098     
00099     // nodes    
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         // coordenates reffers to the node center
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         //finish edge cleanning
00110         caller->operator[](s->name)->outgoing->clear();
00111         //edges
00112         for (e = agfstout(g,s); e; e = agnxtout(g,e)) {
00113                 // create edges
00114                 Edge* E;
00115                 E = caller->connect(s->name , e->head->name);
00116                 E->setTrust(agget(e,"trust"));
00117                 // get bezier control points
00118                 splines* spl = getsplinepoints(e);
00119                 // process each bezier;
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 }
Untitled Document Pesquisa Psi SourceForge.net Logo