Salome HOME
[EDF27816] : management of proxy from/to Foreach
[modules/yacs.git] / src / genericgui / SceneBlocItem.cxx
index 5a89167921301ad2ff264ccf3c631aa1e6245845..14b9f482e19154baf198a94869ce8eb88e5874c3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 
 #include <sstream>
 
-// --- for graphviz 2.8
-#undef HAVE_CONFIG_H
+#include <gvc.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 <Qtx.h> // for Localizer
 
 #include "Resource.hxx"
 
@@ -58,9 +49,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 +67,11 @@ SceneBlocItem::~SceneBlocItem()
 
 void SceneBlocItem::arrangeChildNodes()
 {
+#ifdef _DEVDEBUG_
   DEBTRACE("SceneBlocItem::arrangeChildNodes");
   clock_t start_t, end_t;
   start_t = clock();
+#endif //_DEVDEBUG_
 
 
   SubjectComposedNode *scnode = dynamic_cast<SubjectComposedNode*>(getSubject());
@@ -91,69 +81,32 @@ void SceneBlocItem::arrangeChildNodes()
 
   // ---- Create a graphviz context
 
-  if(!aGvc)
-    {
-      DEBTRACE(setlocale(LC_ALL,NULL));
-      //Graphviz is sensitive to locale : set the mimimal one ("C")for numeric
-      setlocale(LC_NUMERIC, "C");
-      aginit();
-      aGvc = gvContext();
-    }
+  // Graphviz is sensitive to locale : set the mimimal one ("C")for numeric
+  Qtx::Localizer loc;
+
+  //aginit();
+  GVC_t* 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 +119,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 +138,7 @@ void SceneBlocItem::arrangeChildNodes()
       DEBTRACE("Unknown Exception Graphviz layout ");
       return;
     }
+#ifdef _DEVDEBUG_
   {
     end_t = clock();
     double passe =  (end_t -start_t);
@@ -197,6 +146,7 @@ void SceneBlocItem::arrangeChildNodes()
     DEBTRACE("graphviz : " << passe);
     start_t = end_t;
   }
+#endif //_DEVDEBUG_
   DEBTRACE("start of display");
   // ---- layout Canvas nodes recursively
 
@@ -205,11 +155,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 +163,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 +174,7 @@ void SceneBlocItem::arrangeChildNodes()
     DEBTRACE("display : " << passe);
     start_t = end_t;
   }
+#endif //_DEVDEBUG_
 }
 
 void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
@@ -240,8 +186,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,22 +200,22 @@ 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.toLatin1().data());
+      agset(aNode, const_cast<char*>("width"),     width.toLatin1().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)
 
-  Agnode_t* aNode;
+  Agnode_t* aNode = NULL;
   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 ! =============================");
@@ -280,8 +226,8 @@ void  SceneBlocItem::getNodesInfo(YACS::ENGINE::ComposedNode *cnode)
 
     {
       OutGate *outGate = outNode->getOutGate();
-      set<InGate*> setOfInGate = outGate->edSetInGate();
-      set<InGate*>::const_iterator itin = setOfInGate.begin();
+      list<InGate*> setOfInGate = outGate->edSetInGate();
+      list<InGate*>::const_iterator itin = setOfInGate.begin();
       for (; itin != setOfInGate.end(); ++itin)
         {
           Node *inNode = (*itin)->getNode();
@@ -293,9 +239,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 +264,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 +290,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.;