From dc65076ee35effb4573aa8bf85c3b87a4ea79af5 Mon Sep 17 00:00:00 2001 From: Sebastian Blumenthal Date: Wed, 16 Nov 2016 14:30:10 +0100 Subject: [PATCH] Bugfix for DotVisualizer not beeing able to handle JSON in attributes. Closes #10. --- .../sceneGraph/DotGraphGenerator.cpp | 18 ++++++++++++++---- .../worldModel/sceneGraph/DotGraphGenerator.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.cpp b/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.cpp index 323fbf7..196f9ef 100644 --- a/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.cpp +++ b/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.cpp @@ -20,6 +20,8 @@ #include "DotGraphGenerator.h" #include "brics_3d/core/Logger.h" +#include + namespace brics_3d { namespace rsg { @@ -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; } @@ -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\" "; @@ -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"; @@ -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 "; @@ -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; +} + } } diff --git a/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.h b/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.h index cfeaec3..e6804a8 100644 --- a/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.h +++ b/src/brics_3d/worldModel/sceneGraph/DotGraphGenerator.h @@ -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;