diff --git a/include/hpp/manipulation/graph/dot.hh b/include/hpp/manipulation/graph/dot.hh index ce9259ecd3a346866f0c20dd0a531c94a5f61b5b..dcb932aa522943c596348bc43ab54fd6fad6f7d7 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 83f360418280ac822ee551d468e6effbe44dca0f..be8ceb6bdb86e9fc10f00c4a5893996958a30d01 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 20ef728e0c2317a11a18dfa3902c3a29717ba42b..7e9f20a2ea5579dca5274f2ad8f1724b5202367d 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 = " "; + const std::string Tooltip::tooltipendl = " "; 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 22b65f80264437fc75d89431dfa24e57c1dfdb90..2b17af68bf532e4549b4a6967fbff0fc01e7ba32 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 e5b83f2a2a0318ebf00651f316aa45604fe4ce1e..9406aa54110207f713cdf0e60272638bac2350da 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 d673280e2ddd4f6e871097d6a63db9d528a84df5..206abfa799ec23a6553d61671e1781939957c97a 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 e67f8e229736d674eb60c6a5f52c0f1f335a06d2..0d629206c58b32328c7621b0b764ad8788d1268c 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;