From b6db7517e3e380d9b4a6cf9db1ff33f700daaa60 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Wed, 14 Jan 2015 14:04:15 +0100
Subject: [PATCH] Tooltip is now an attribute of DOT graph components.

---
 include/hpp/manipulation/graph/dot.hh         | 31 ++++++++++++++-----
 .../hpp/manipulation/graph/graph-component.hh |  2 +-
 src/graph/dot.cc                              | 13 ++------
 src/graph/edge.cc                             | 12 ++++---
 src/graph/graph-component.cc                  |  6 ++--
 src/graph/graph.cc                            |  5 +--
 src/graph/node.cc                             |  5 +--
 7 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/include/hpp/manipulation/graph/dot.hh b/include/hpp/manipulation/graph/dot.hh
index ce9259ec..dcb932aa 100644
--- a/include/hpp/manipulation/graph/dot.hh
+++ b/include/hpp/manipulation/graph/dot.hh
@@ -18,6 +18,7 @@
 # define HPP_MANIPULATION_GRAPH_DOT_HH
 
 # include <ostream>
+# include <sstream>
 # include <map>
 # include <list>
 
@@ -29,16 +30,10 @@ namespace hpp {
         struct DrawingAttributes {
           typedef std::pair <std::string, std::string> Pair;
           typedef std::map <std::string, std::string> Map;
-          typedef std::list <std::string> TooltipLineVector;
 
-          static const std::string tooltipendl;
           std::string separator, openSection, closeSection;
           Map attr;
-          TooltipLineVector tooltip;
 
-          inline void addTooltipLine (const std::string& l) {
-            tooltip.push_back (l);
-          }
           inline void insertWithQuote (const std::string& K, const std::string& V) {
             attr.insert (Pair (K, "\"" + V + "\""));
           }
@@ -50,7 +45,29 @@ namespace hpp {
           }
           DrawingAttributes () :
             separator (", "), openSection ("["), closeSection ("]"),
-            attr (), tooltip () {};
+            attr () {};
+        };
+
+        struct Tooltip {
+          static const std::string tooltipendl;
+          typedef std::list <std::string> TooltipLineVector;
+          TooltipLineVector v;
+
+          Tooltip () : v() {};
+          inline std::string toStr () const {
+            std::stringstream ss;
+            size_t i = v.size ();
+            for (TooltipLineVector::const_iterator
+                it = v.begin (); it != v.end (); ++it ) {
+              ss << *it;
+              i--;
+              if (i > 0) ss << tooltipendl;
+            }
+            return ss.str ();
+          }
+          inline void addLine (const std::string& l) {
+            v.push_back (l);
+          }
         };
 
         std::ostream& insertComments (std::ostream& os, const std::string& c);
diff --git a/include/hpp/manipulation/graph/graph-component.hh b/include/hpp/manipulation/graph/graph-component.hh
index 83f36041..be8ceb6b 100644
--- a/include/hpp/manipulation/graph/graph-component.hh
+++ b/include/hpp/manipulation/graph/graph-component.hh
@@ -100,7 +100,7 @@ namespace hpp {
           friend std::ostream& operator<< (std::ostream&, const GraphComponent&);
 
           /// Populate DrawingAttributes tooltip
-          virtual void populateTooltip (dot::DrawingAttributes& da) const;
+          virtual void populateTooltip (dot::Tooltip& tp) const;
 
         private:
           /// Keep track of the created components in order to retrieve them
diff --git a/src/graph/dot.cc b/src/graph/dot.cc
index 20ef728e..7e9f20a2 100644
--- a/src/graph/dot.cc
+++ b/src/graph/dot.cc
@@ -20,10 +20,11 @@ namespace hpp {
   namespace manipulation {
     namespace graph {
       namespace dot {
-        const std::string DrawingAttributes::tooltipendl = "&#10;";
+        const std::string Tooltip::tooltipendl = "&#10;";
 
         std::ostream& operator<< (std::ostream& os, const DrawingAttributes& da)
         {
+          if (da.attr.empty ()) return os;
           os << da.openSection;
           size_t i = da.attr.size ();
           for (DrawingAttributes::Map::const_iterator it = da.attr.begin ();
@@ -32,16 +33,6 @@ namespace hpp {
             i--;
             if (i > 0) os << da.separator;
           }
-          if (!da.attr.empty ()) os << da.separator;
-          os << "tooltip=\"";
-          i = da.tooltip.size ();
-          for (DrawingAttributes::TooltipLineVector::const_iterator
-              it = da.tooltip.begin (); it != da.tooltip.end (); ++it ) {
-            os << *it;
-            i--;
-            if (i > 0) os << DrawingAttributes::tooltipendl;
-          }
-          os << "\"";
           return os << da.closeSection;
         }
 
diff --git a/src/graph/edge.cc b/src/graph/edge.cc
index 22b65f80..2b17af68 100644
--- a/src/graph/edge.cc
+++ b/src/graph/edge.cc
@@ -88,8 +88,10 @@ namespace hpp {
       {
         da.insertWithQuote ("label", name ());
         da.insert ("shape", "onormal");
-        da.addTooltipLine ("Edge constains:");
-        populateTooltip (da);
+        dot::Tooltip tp; tp.addLine ("Edge constains:");
+        populateTooltip (tp);
+        da.insertWithQuote ("tooltip", tp.toStr());
+        da.insertWithQuote ("labeltooltip", tp.toStr());
         os << from()->id () << " -> " << to()->id () << " " << da << ";";
         return os;
       }
@@ -301,8 +303,10 @@ namespace hpp {
         da ["arrowtail"]="dot";
         da.insert ("shape", "onormal");
         da.insertWithQuote ("label", name());
-        da.addTooltipLine ("Edge constains:");
-        populateTooltip (da);
+        dot::Tooltip tp; tp.addLine ("Edge constains:");
+        populateTooltip (tp);
+        da.insertWithQuote ("tooltip", tp.toStr());
+        da.insertWithQuote ("labeltooltip", tp.toStr());
         os << waypoint_.second->id () << " -> " << to()->id () << " " << da << ";";
         return os;
       }
diff --git a/src/graph/graph-component.cc b/src/graph/graph-component.cc
index e5b83f2a..9406aa54 100644
--- a/src/graph/graph-component.cc
+++ b/src/graph/graph-component.cc
@@ -123,15 +123,15 @@ namespace hpp {
         return graphComp.print (os);
       }
 
-      void GraphComponent::populateTooltip (dot::DrawingAttributes& da) const
+      void GraphComponent::populateTooltip (dot::Tooltip& tp) const
       {
         for (NumericalConstraints_t::const_iterator it = numericalConstraints_.begin ();
             it != numericalConstraints_.end (); ++it) {
-          da.addTooltipLine ("- " + (*it)->function ().name ());
+          tp.addLine ("- " + (*it)->function ().name ());
         }
         for (LockedJoints_t::const_iterator it = lockedJoints_.begin ();
             it != lockedJoints_.end (); ++it) {
-          da.addTooltipLine ("- " + (*it)->jointName ());
+          tp.addLine ("- " + (*it)->jointName ());
         }
       }
     } // namespace graph
diff --git a/src/graph/graph.cc b/src/graph/graph.cc
index d673280e..206abfa7 100644
--- a/src/graph/graph.cc
+++ b/src/graph/graph.cc
@@ -114,8 +114,9 @@ namespace hpp {
         da.separator = "; ";
         da.openSection = "\n";
         da.closeSection = ";\n";
-        da.addTooltipLine ("Graph contains:");
-        populateTooltip (da);
+        dot::Tooltip tp; tp.addLine ("Graph constains:");
+        populateTooltip (tp);
+        da.insertWithQuote ("tooltip", tp.toStr());
         os << "digraph " << id() << " {" << da;
         nodeSelector_->dotPrint (os);
         os << "}" << std::endl;
diff --git a/src/graph/node.cc b/src/graph/node.cc
index e67f8e22..0d629206 100644
--- a/src/graph/node.cc
+++ b/src/graph/node.cc
@@ -63,8 +63,9 @@ namespace hpp {
       {
         da.insertWithQuote ("label", name ());
         da.insert ("style","filled");
-        da.addTooltipLine ("Node contains:");
-        populateTooltip (da);
+        dot::Tooltip tp; tp.addLine ("Node contains:");
+        populateTooltip (tp);
+        da.insertWithQuote ("tooltip", tp.toStr());
         os << id () << " " << da << ";" << std::endl;
 
         dot::DrawingAttributes dac;
-- 
GitLab