Salome HOME
Update to graphviz 2.38
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 9 Oct 2014 12:38:58 +0000 (14:38 +0200)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Thu, 9 Oct 2014 12:38:58 +0000 (14:38 +0200)
src/genericgui/SceneBlocItem.cxx
src/genericgui/SceneBlocItem.hxx

index 5a89167921301ad2ff264ccf3c631aa1e6245845..47d8fe26e3258e5bc5b814d17c973e14bba2c103 100644 (file)
 
 #include <sstream>
 
-// --- for graphviz 2.8
-#undef HAVE_CONFIG_H
-
-#ifdef HAVE_DOTNEATO_H
-  #include <dotneato.h>
-#else
-  #include <gvc.h>
-#endif
-
-#ifndef ND_coord_i
-#define ND_coord_i(n) (n)->u.coord
-#endif
+#include <gvc.h>
 
 #include "Resource.hxx"
 
@@ -58,9 +47,6 @@ using namespace YACS::HMI;
  */
 #define DPI 72.
 
-static GVC_t* aGvc = 0;
-
-
 SceneBlocItem::SceneBlocItem(QGraphicsScene *scene, SceneItem *parent,
                              QString label, Subject *subject)
   : SceneComposedNodeItem(scene, parent, label, subject)
@@ -79,9 +65,12 @@ SceneBlocItem::~SceneBlocItem()
 
 void SceneBlocItem::arrangeChildNodes()
 {
+#ifdef _DEVDEBUG_
   DEBTRACE("SceneBlocItem::arrangeChildNodes");
   clock_t start_t, end_t;
   start_t = clock();
+#endif //_DEVDEBUG_
+  GVC_t* aGvc = 0;
 
 
   SubjectComposedNode *scnode = dynamic_cast<SubjectComposedNode*>(getSubject());
@@ -96,64 +85,30 @@ void SceneBlocItem::arrangeChildNodes()
       DEBTRACE(setlocale(LC_ALL,NULL));
       //Graphviz is sensitive to locale : set the mimimal one ("C")for numeric
       setlocale(LC_NUMERIC, "C");
-      aginit();
+      //aginit();
       aGvc = gvContext();
     }
 
   // ---- Create a graph
 
-  _graph = agopen((char*)( cnode->getName().c_str()), AGDIGRAPH);
+  _graph = agopen((char*)( cnode->getName().c_str()), Agdirected, NULL);
 
   // ---- Initialize and set attributes for the graph
-  
-  Agsym_t* attr;
-  if ( !(attr = agfindattr(_graph, (char *)"compound")))
-    attr = agraphattr(_graph, (char *)"compound", (char *)"false");
-  agxset(_graph, attr->index, (char *)"true");
-
-  if ( !(attr = agfindattr(_graph, (char *)"rankdir")))
-    attr = agraphattr(_graph, (char *)"rankdir", (char *)"TB");
-  agxset(_graph, attr->index, (char *)"LR");
-
-//   if ( !(attr = agfindattr(_graph, (char *)"ordering")))
-//     attr = agraphattr(_graph, (char *)"ordering", (char *)"" );
-//   agxset(_graph, attr->index, (char *)"in" );
-  
-  if ( !(attr = agfindattr(_graph, (char *)"dpi")))
-    attr = agraphattr(_graph, (char *)"dpi", (char *)"72");
-  agxset(_graph, attr->index, (char *)"72"); // --- must be coherent with #define DPI
-
-  // --- label is used to reserve place for bloc banners (adjust size with font !)
-
-  if ( !(attr = agfindattr(_graph, (char *)"label")))
-    attr = agraphattr(_graph, (char *)"label", (char *)"label");
-  agxset(_graph, attr->index, (char *)"myLabel");
-
-  if ( !(attr = agfindattr(_graph, (char *)"labelloc")))
-    attr = agraphattr(_graph, (char *)"labelloc", (char *)"top");
-  agxset(_graph, attr->index, (char *)"top");
-
-  if ( !(attr = agfindattr(_graph, (char *)"fontsize")))
-    attr = agraphattr(_graph, (char *)"fontsize", (char *)"24");
-  agxset(_graph, attr->index, (char *)"24");
-
-  if ( !(attr = agfindattr(_graph, (char *)"splines")))
-    attr = agraphattr(_graph, (char *)"splines", (char *)"");
-  agxset(_graph, attr->index, (char *)"");
-
-  // --- Initialize attributes for nodes
-
-  if ( !(attr = agfindattr( _graph->proto->n, (char *)"height")))
-    attr = agnodeattr(_graph, (char *)"height", (char *)"" );
 
-  if ( !(attr = agfindattr( _graph->proto->n, (char *)"width")))
-    attr = agnodeattr(_graph, (char *)"width", (char *)"" );
+  agattr(_graph, AGRAPH, const_cast<char*>("compound"), const_cast<char*>("true"));
+  agattr(_graph, AGRAPH, const_cast<char*>("rankdir"), const_cast<char*>("LR"));
+  agattr(_graph, AGRAPH, const_cast<char*>("dpi"), const_cast<char*>("72"));
+  agattr(_graph, AGRAPH, const_cast<char*>("label"), const_cast<char*>("myLabel"));
+  agattr(_graph, AGRAPH, const_cast<char*>("labelloc"), const_cast<char*>("top"));
+  agattr(_graph, AGRAPH, const_cast<char*>("fontsize"), const_cast<char*>("24"));
+  agattr(_graph, AGRAPH, const_cast<char*>("splines"), const_cast<char*>(""));
 
-  if ( !(attr = agfindattr( _graph->proto->n, (char *)"shape")))
-    attr = agnodeattr(_graph, (char *)"shape", (char *)"" );
+  // --- Initialize attributes for nodes
 
-  if ( !(attr = agfindattr( _graph->proto->n, (char *)"fixedsize")))
-    attr = agnodeattr(_graph, (char *)"fixedsize", (char *)"false" );
+  agattr(_graph, AGNODE, const_cast<char*>("height"), const_cast<char*>("" ));
+  agattr(_graph, AGNODE, const_cast<char*>("width"), const_cast<char*>("" ));
+  agattr(_graph, AGNODE, const_cast<char*>("shape"), const_cast<char*>("" ));
+  agattr(_graph, AGNODE, const_cast<char*>("fixedsize"), const_cast<char*>("false" ));
 
   // ---- Bind graph to graphviz context - must be done before layout
   // ---- Compute a layout
@@ -166,18 +121,13 @@ void SceneBlocItem::arrangeChildNodes()
 #ifdef _DEVDEBUG_
       agwrite(_graph, stderr);
 #endif
-#ifdef HAVE_DOTNEATO_H
-      gvBindContext(aGvc, _graph);
-      dot_layout(_graph);
-#else
       //DEBTRACE("external render for test");
       //gvRenderFilename(aGvc, _mainGraph, "dot", "graph1.dot");
       DEBTRACE("compute layout");
-      gvLayout(aGvc, _graph, (char *)"dot");
+      gvLayout(aGvc, _graph, "dot");
       DEBTRACE("external render for test");
 #ifdef _DEVDEBUG_
-      gvRenderFilename(aGvc, _graph, (char *)"dot", (char *)"graph2.dot");
-#endif
+      gvRenderFilename(aGvc, _graph, "dot", "graph2.dot");
 #endif
    }
   catch (std::exception &e)
@@ -190,6 +140,7 @@ void SceneBlocItem::arrangeChildNodes()
       DEBTRACE("Unknown Exception Graphviz layout ");
       return;
     }
+#ifdef _DEVDEBUG_
   {
     end_t = clock();
     double passe =  (end_t -start_t);
@@ -197,6 +148,7 @@ void SceneBlocItem::arrangeChildNodes()
     DEBTRACE("graphviz : " << passe);
     start_t = end_t;
   }
+#endif //_DEVDEBUG_
   DEBTRACE("start of display");
   // ---- layout Canvas nodes recursively
 
@@ -205,11 +157,7 @@ void SceneBlocItem::arrangeChildNodes()
   DEBTRACE("clean up graphviz");
   // ---- Delete layout
 
-#ifdef HAVE_DOTNEATO_H
-  dot_cleanup(_graph);
-#else
   gvFreeLayout(aGvc, _graph);
-#endif
 
   // ---- Free graph structures
 
@@ -217,11 +165,10 @@ void SceneBlocItem::arrangeChildNodes()
 
   // ---- Free context and return number of errors
 
-#ifndef HAVE_DOTNEATO_H
-  //gvFreeContext( aGvc );
-#endif
+  gvFreeContext( aGvc );
 
   // --- update scene
+#ifdef _DEVDEBUG_
   {
     end_t = clock();
     double passe =  (end_t -start_t);
@@ -229,6 +176,7 @@ void SceneBlocItem::arrangeChildNodes()
     DEBTRACE("display : " << passe);
     start_t = end_t;
   }
+#endif //_DEVDEBUG_
 }
 
 void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
@@ -240,8 +188,8 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
   list<Node*> children = cnode->edGetDirectDescendants();
   for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
     {
-      Agnode_t* aNode = agnode(_graph, (char*)(proc->getChildName(*it).c_str()));
-      DEBTRACE("Add node in graph: " << aNode->name);
+      Agnode_t* aNode = agnode(_graph, (char*)(proc->getChildName(*it).c_str()), 1);
+      DEBTRACE("Add node in graph: " << agnameof(aNode));
 
       SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
       SceneItem* sci = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
@@ -254,11 +202,11 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
       height = QString(_format.c_str()).arg(lh, 0, 'g', 3);
       width  = QString(_format.c_str()).arg(lw, 0, 'g', 3);
 
-      DEBTRACE(aNode->name << " (" << nh << "," << nw << ") = (" << height.toStdString()  << " ; " << width.toStdString() <<")");
-      agxset( aNode, agfindattr(_graph->proto->n,(char *)"height")->index, (char*)(height.toAscii().data()));
-      agxset( aNode, agfindattr(_graph->proto->n,(char *)"width")->index, (char*)(width.toAscii().data()));
-      agxset( aNode, agfindattr(_graph->proto->n,(char *)"shape")->index, (char *)"box" );
-      agxset( aNode, agfindattr(_graph->proto->n,(char *)"fixedsize")->index, (char *)"true" );
+      DEBTRACE(agnameof(aNode) << " (" << nh << "," << nw << ") = (" << height.toStdString()  << " ; " << width.toStdString() <<")");
+      agset(aNode, const_cast<char*>("height"),    height.toAscii().data());
+      agset(aNode, const_cast<char*>("width"),     width.toAscii().data());
+      agset(aNode, const_cast<char*>("shape"),     const_cast<char*>("box") );
+      agset(aNode, const_cast<char*>("fixedsize"), const_cast<char*>("true") );
     }
 
   // --- Create edges (i.e. links)
@@ -266,10 +214,10 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
   Agnode_t* aNode;
   for (aNode = agfstnode(_graph); aNode; aNode = agnxtnode(_graph, aNode))
   {
-    string aNodeName = aNode->name;
-    DEBTRACE("--- tail node " << aNode->name);
+    string aNodeName = agnameof(aNode);
+    DEBTRACE("--- tail node " << aNodeName);
     Agnode_t* aTailNode = aNode;
-    Node* outNode = proc->getChildByName(string(aTailNode->name));
+    Node* outNode = proc->getChildByName(string(agnameof(aTailNode)));
     if (outNode->getFather() != cnode)
       {
         DEBTRACE(" =========== problem here ! =============================");
@@ -293,9 +241,9 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
             {
               DEBTRACE("--- edge inside the bloc " << inDCNode->getName());
               string inDCName = proc->getChildName(inDCNode);
-              Agnode_t* aHeadNode = agnode(_graph, (char*)(inDCName.c_str()));
-              Agedge_t* anEdge    = agedge(_graph, aTailNode, aHeadNode);
-              DEBTRACE("--- control link from tail node: --- " << aNode->name << " --> " << inDCName);
+              Agnode_t* aHeadNode = agnode(_graph, (char*)(inDCName.c_str()), 1);
+              Agedge_t* anEdge    = agedge(_graph, aTailNode, aHeadNode, NULL, 1);
+              DEBTRACE("--- control link from tail node: --- " << agnameof(aNode) << " --> " << inDCName);
             }
         }
     }
@@ -318,9 +266,9 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
                 {
                   DEBTRACE("--- edge inside the bloc " << inDCNode->getName());
                   string inDCName = proc->getChildName(inDCNode);
-                  Agnode_t* aHeadNode = agnode(_graph, (char*)(inDCName.c_str()));
-                  Agedge_t* anEdge    = agedge(_graph, aTailNode, aHeadNode);
-                  DEBTRACE("------ data link from tail node: ---- " << aNode->name << " --> " << inDCName);
+                  Agnode_t* aHeadNode = agnode(_graph, (char*)(inDCName.c_str()), 1);
+                  Agedge_t* anEdge    = agedge(_graph, aTailNode, aHeadNode, NULL, 1);
+                  DEBTRACE("------ data link from tail node: ---- " << agnameof(aNode) << " --> " << inDCName);
                 }
             }
         }
@@ -344,13 +292,13 @@ void SceneBlocItem::arrangeCanvasNodes(YACS::ENGINE::ComposedNode *cnode)
   list<Node*> children = cnode->edGetDirectDescendants();
   for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
     {
-      Agnode_t* aNode = agnode(_graph, (char*)(proc->getChildName(*it).c_str()));
-      DEBTRACE("Get node in graph: " << aNode->name);
+      Agnode_t* aNode = agnode(_graph, (char*)(proc->getChildName(*it).c_str()), 1);
+      DEBTRACE("Get node in graph: " << agnameof(aNode));
       SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
       SceneItem* sci = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
 
-      qreal xCenter = ND_coord_i(aNode).x;
-      qreal yCenter = ND_coord_i(aNode).y;
+      qreal xCenter = ND_coord(aNode).x;
+      qreal yCenter = ND_coord(aNode).y;
       qreal halfWidth = sci->boundingRect().width()/2.;
       qreal halfHeight = sci->boundingRect().height()/2.;
 
index 71fb25b0032ebbcea48433a90f41e6c2845c02a1..adaae84c03686a34b3ebb6704757552f554d2afb 100644 (file)
@@ -23,8 +23,7 @@
 #include "SceneComposedNodeItem.hxx"
 
 #include <string>
-
-struct Agraph_t;
+#include <cgraph.h>
 
 namespace YACS
 {