From 9b68062ba7b4ace1eed8e3f1c687374e6e21dc84 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Thu, 17 Oct 2013 13:28:54 +0200 Subject: [PATCH] Add helper to get osg::Node path as string. --- simgear/scene/util/CMakeLists.txt | 2 ++ simgear/scene/util/OsgDebug.cxx | 49 +++++++++++++++++++++++++++++++ simgear/scene/util/OsgDebug.hxx | 36 +++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 simgear/scene/util/OsgDebug.cxx create mode 100644 simgear/scene/util/OsgDebug.hxx diff --git a/simgear/scene/util/CMakeLists.txt b/simgear/scene/util/CMakeLists.txt index 3586844e..9dec4115 100644 --- a/simgear/scene/util/CMakeLists.txt +++ b/simgear/scene/util/CMakeLists.txt @@ -7,6 +7,7 @@ set(HEADERS NodeAndDrawableVisitor.hxx Noise.hxx OptionsReadFileCallback.hxx + OsgDebug.hxx OsgMath.hxx OsgSingleton.hxx parse_color.hxx @@ -37,6 +38,7 @@ set(SOURCES NodeAndDrawableVisitor.cxx Noise.cxx OptionsReadFileCallback.cxx + OsgDebug.cxx parse_color.cxx PrimitiveUtils.cxx QuadTreeBuilder.cxx diff --git a/simgear/scene/util/OsgDebug.cxx b/simgear/scene/util/OsgDebug.cxx new file mode 100644 index 00000000..d2726e02 --- /dev/null +++ b/simgear/scene/util/OsgDebug.cxx @@ -0,0 +1,49 @@ +// Helper for OSG related debugging +// +// Copyright (C) 2013 Thomas Geymayer +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +#include "OsgDebug.hxx" +#include + +namespace simgear +{ + + //---------------------------------------------------------------------------- + std::string getNodePathString(const osg::Node* node) + { + if( !node ) + return "(nullptr)"; + + std::string str; + const osg::NodePathList& paths = node->getParentalNodePaths(); + for(size_t i = 0; i < paths.size(); ++i) + { + if( !str.empty() ) + str += ":"; + + const osg::NodePath& path = paths.at(i); + for(size_t j = 0; j < path.size(); ++j) + { + const osg::Node* node = path[j]; + str += "/'" + node->getName() + "'"; + } + } + + return str; + } + +} // namespace simgear diff --git a/simgear/scene/util/OsgDebug.hxx b/simgear/scene/util/OsgDebug.hxx new file mode 100644 index 00000000..290d407c --- /dev/null +++ b/simgear/scene/util/OsgDebug.hxx @@ -0,0 +1,36 @@ +///@file Helper for OSG related debugging +// +// Copyright (C) 2013 Thomas Geymayer +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +#ifndef OSGDEBUG_HXX_ +#define OSGDEBUG_HXX_ + +#include + +namespace osg { class Node; } +namespace simgear +{ + + /** + * Get parent path(s) of scene graph node as string. + */ + std::string getNodePathString(const osg::Node* node); + +} // namespace simgear + + +#endif /* OSGDEBUG_HXX_ */ -- 2.39.5