| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "SimpleDotVisitor.h" |
|---|
| 15 | |
|---|
| 16 | namespace osgDot { |
|---|
| 17 | |
|---|
| 18 | SimpleDotVisitor::SimpleDotVisitor() { |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | SimpleDotVisitor::~SimpleDotVisitor() { |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | void SimpleDotVisitor::handle(osg::Node& node, int id) { |
|---|
| 25 | std::stringstream label; |
|---|
| 26 | label << "<top> Node"; |
|---|
| 27 | if ( !node.getName().empty() ) { label << "| " << node.getName(); } |
|---|
| 28 | drawNode( id, "record", "solid", label.str(), "black", "white" ); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | void SimpleDotVisitor::handle(osg::Geode& node, int id) { |
|---|
| 32 | std::stringstream label; |
|---|
| 33 | label << "<top> " << node.className(); |
|---|
| 34 | if ( !node.getName().empty() ) { label << "| " << node.getName(); } |
|---|
| 35 | drawNode( id, "record", "solid", label.str(), "brown", "white" ); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | void SimpleDotVisitor::handle(osg::Group& node, int id) { |
|---|
| 39 | std::stringstream label; |
|---|
| 40 | label << "<top> " << node.className(); |
|---|
| 41 | if ( !node.getName().empty() ) { label << "| " << node.getName(); } |
|---|
| 42 | drawNode( id, "record", "solid", label.str(), "black", "white" ); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | void SimpleDotVisitor::handle(osg::Group& parent, osg::Node& child, int parentID, int childID ) { |
|---|
| 46 | drawEdge( parentID, childID, "setlinewidth(2)" ); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | void SimpleDotVisitor::handle(osg::StateSet& stateset, int id) { |
|---|
| 50 | std::stringstream label; |
|---|
| 51 | label << "<top> " << stateset.className(); |
|---|
| 52 | if ( !stateset.getName().empty() ) { label << "| " << stateset.getName(); } |
|---|
| 53 | drawNode( id, "Mrecord", "solid", label.str(), "green", "white" ); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | void SimpleDotVisitor::handle(osg::Node& node, osg::StateSet& stateset, int parentID, int childID ) { |
|---|
| 57 | drawEdge( parentID, childID, "dashed" ); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | void SimpleDotVisitor::handle(osg::Drawable& drawable, int id) { |
|---|
| 61 | std::stringstream label; |
|---|
| 62 | label << "<top> " << drawable.className(); |
|---|
| 63 | if ( !drawable.getName().empty() ) { label << "| " << drawable.getName(); } |
|---|
| 64 | drawNode( id, "record", "solid", label.str(), "blue", "white" ); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void SimpleDotVisitor::handle(osg::Geode& geode, osg::Drawable& drawable, int parentID, int childID ) { |
|---|
| 68 | drawEdge( parentID, childID, "dashed" ); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void SimpleDotVisitor::handle(osg::Drawable& drawable, osg::StateSet& stateset, int parentID, int childID ) { |
|---|
| 72 | drawEdge( parentID, childID, "dashed" ); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | void SimpleDotVisitor::drawNode( int id, const std::string& shape, const std::string& style, const std::string& label, const std::string& color, const std::string& fillColor ) { |
|---|
| 76 | _nodes << id << |
|---|
| 77 | "[shape=\"" << shape << |
|---|
| 78 | "\" ,label=\"" << label << |
|---|
| 79 | "\" ,style=\"" << style << |
|---|
| 80 | "\" ,color=\"" << color << |
|---|
| 81 | "\" ,fillColor=\"" << fillColor << |
|---|
| 82 | "\"]" << std::endl; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | void SimpleDotVisitor::drawEdge( int sourceId, int sinkId, const std::string& style ) { |
|---|
| 86 | _edges |
|---|
| 87 | << sourceId << ":top -> " |
|---|
| 88 | << sinkId << ":top [style=\"" |
|---|
| 89 | << style << "\"];" |
|---|
| 90 | << std::endl; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | } |
|---|