Skip to content
Snippets Groups Projects
Commit ed9e0245 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Enhance dot output

parent a2c29d64
No related branches found
No related tags found
No related merge requests found
......@@ -19,16 +19,26 @@
# include <ostream>
# include <map>
# include <list>
namespace hpp {
namespace manipulation {
namespace graph {
namespace dot {
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 + "\""));
}
......@@ -38,6 +48,9 @@ namespace hpp {
std::string& operator [] (const std::string& K) {
return attr [K];
}
DrawingAttributes () :
separator (", "), openSection ("["), closeSection ("]"),
attr (), tooltip () {};
};
std::ostream& insertComments (std::ostream& os, const std::string& c);
......
......@@ -99,6 +99,9 @@ namespace hpp {
virtual std::ostream& print (std::ostream& os) const;
friend std::ostream& operator<< (std::ostream&, const GraphComponent&);
/// Populate DrawingAttributes tooltip
virtual void populateTooltip (dot::DrawingAttributes& da) const;
private:
/// Keep track of the created components in order to retrieve them
/// easily.
......
......@@ -20,18 +20,29 @@ namespace hpp {
namespace manipulation {
namespace graph {
namespace dot {
const std::string DrawingAttributes::tooltipendl = "&#10;";
std::ostream& operator<< (std::ostream& os, const DrawingAttributes& da)
{
if (da.attr.empty ()) return os;
os << "[";
os << da.openSection;
size_t i = da.attr.size ();
for (DrawingAttributes::Map::const_iterator it = da.attr.begin ();
it != da.attr.end (); ++it) {
os << it->first << "=" << it->second;
i--;
if (i > 0) os << ", ";
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;
}
return os << "]";
os << "\"";
return os << da.closeSection;
}
std::ostream& insertComments (std::ostream& os, const std::string& c)
......
......@@ -18,6 +18,7 @@
#include <hpp/core/straight-path.hh>
#include <hpp/core/path-vector.hh>
#include <hpp/constraints/differentiable-function.hh>
#include <hpp/util/pointer.hh>
......@@ -86,6 +87,8 @@ namespace hpp {
{
da.insertWithQuote ("label", name ());
da.insert ("shape", "onormal");
da.addTooltipLine ("Edge constains:");
populateTooltip (da);
os << from()->id () << " -> " << to()->id () << " " << da << ";";
return os;
}
......@@ -297,6 +300,8 @@ namespace hpp {
da ["arrowtail"]="dot";
da.insert ("shape", "onormal");
da.insertWithQuote ("label", name());
da.addTooltipLine ("Edge constains:");
populateTooltip (da);
os << waypoint_.second->id () << " -> " << to()->id () << " " << da << ";";
return os;
}
......
......@@ -20,6 +20,8 @@
#include <hpp/core/constraint-set.hh>
#include <hpp/core/locked-joint.hh>
#include <hpp/constraints/differentiable-function.hh>
namespace hpp {
namespace manipulation {
namespace graph {
......@@ -120,6 +122,18 @@ namespace hpp {
{
return graphComp.print (os);
}
void GraphComponent::populateTooltip (dot::DrawingAttributes& da) const
{
for (NumericalConstraints_t::const_iterator it = numericalConstraints_.begin ();
it != numericalConstraints_.end (); ++it) {
da.addTooltipLine ("- " + (*it)->function ().name ());
}
for (LockedJoints_t::const_iterator it = lockedJoints_.begin ();
it != lockedJoints_.end (); ++it) {
da.addTooltipLine ("- " + (*it)->jointName ());
}
}
} // namespace graph
} // namespace manipulation
} // namespace hpp
......@@ -110,7 +110,12 @@ namespace hpp {
std::ostream& Graph::dotPrint (std::ostream& os, dot::DrawingAttributes da) const
{
os << "digraph " << id() << " " << da << " {" << std::endl;
da.separator = "; ";
da.openSection = "\n";
da.closeSection = ";\n";
da.addTooltipLine ("Graph contains:");
populateTooltip (da);
os << "digraph " << id() << " {" << da;
nodeSelector_->dotPrint (os);
os << "}" << std::endl;
return os;
......
......@@ -62,6 +62,8 @@ namespace hpp {
{
da.insertWithQuote ("label", name ());
da.insert ("style","filled");
da.addTooltipLine ("Node contains:");
populateTooltip (da);
os << id () << " " << da << ";" << std::endl;
dot::DrawingAttributes dac;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment