Skip to content

Commit

Permalink
Bugfix for DotVisualizer not beeing able to handle JSON in attributes.
Browse files Browse the repository at this point in the history
…Closes #10.
  • Loading branch information
blumenthal committed Nov 16, 2016
1 parent 5f28753 commit dc65076
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "DotGraphGenerator.h"
#include "brics_3d/core/Logger.h"

#include <boost/algorithm/string/replace.hpp>

namespace brics_3d {

namespace rsg {
Expand Down Expand Up @@ -129,7 +131,7 @@ void DotGraphGenerator::doHandleNode(Node* node) {
nodes << " [label = \"";
nodes << "ID [" << node->getId() << "]\\n";
}
nodes << aggregatedAttributes.str();
nodes << stringify(aggregatedAttributes.str());
nodes << "\"]";
nodes << ";" << std::endl;
}
Expand Down Expand Up @@ -161,7 +163,7 @@ void DotGraphGenerator::doHandleConnection(Connection* connection) {
nodes << "ID [" << connection->getId() << "]\\n";
}
nodes << "Connection\\n";
nodes << aggregatedAttributes.str();
nodes << stringify(aggregatedAttributes.str());
nodes << "\"";
nodes << "style=\"rounded,filled\" shape=diamond ";
// nodes << "style=\"filled\" ";
Expand Down Expand Up @@ -220,7 +222,7 @@ void DotGraphGenerator::doHandleTransform(Transform* node) {
}
nodes << "T = (" << x << ", " << y <<", " << z << ")\\n";
nodes << "Updates: " << node->getUpdateCount() << "\\n";
nodes << aggregatedAttributes.str();
nodes << stringify(aggregatedAttributes.str());
nodes << "\"";
// nodes << "style=\"rounded,filled\", shape=diamond";
// nodes << "shape=circle";
Expand Down Expand Up @@ -253,7 +255,7 @@ void DotGraphGenerator::doHandleGeometricNode(GeometricNode* node) {
nodes << " [label = \"";
nodes << "ID [" << node->getId() << "]\\n";
}
nodes << aggregatedAttributes.str();
nodes << stringify(aggregatedAttributes.str());
nodes << "\"";
nodes << "style=\"filled\" ";
// nodes << "fillcolor=green ";
Expand Down Expand Up @@ -316,6 +318,14 @@ std::string DotGraphGenerator::getDotGraph() {
return result;
}

std::string DotGraphGenerator::stringify(std::string input) {
std::string stringifiedInput = input;
// LOG(DEBUG) << "DotGraphGenerator::stringify input = " << input;
boost::replace_all(stringifiedInput, "\"", "\\\""); // replace all " with \"
// LOG(DEBUG) << "DotGraphGenerator::stringify stringifiedInput = " << stringifiedInput;
return stringifiedInput;
}

}

}
Expand Down
3 changes: 3 additions & 0 deletions src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class DotGraphGenerator : public INodeVisitor {
virtual void doHandleGeometricNode(GeometricNode* node);
virtual void doHandleEdges(Group* node);

/// Stringify. This is necessary if input contain JOSN objects
std::string stringify(std::string input);

std::stringstream dotGraph;
std::stringstream nodes;
std::stringstream edges;
Expand Down

0 comments on commit dc65076

Please sign in to comment.