From 0b44409fca8b7f0e8df7f1e7252daee5c21ae684 Mon Sep 17 00:00:00 2001 From: frohlich Date: Sat, 26 May 2007 11:39:13 +0000 Subject: [PATCH] Modified Files: src/GUI/gui.h src/GUI/gui_funcs.cxx src/Main/fg_commands.cxx src/Main/renderer.cxx src/Main/renderer.hxx: Tim Moore: These patches implement a command to dump the entire OSG scene graph as a .osg text file. While large, this allows debuggers to really see what's happening in the scene graph. --- src/GUI/gui.h | 1 + src/GUI/gui_funcs.cxx | 46 ++++++++++++++++++++++++++++++++++++++++ src/Main/fg_commands.cxx | 7 ++++++ src/Main/renderer.cxx | 5 +++++ src/Main/renderer.hxx | 2 ++ 5 files changed, 61 insertions(+) diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 6f3dcb875..31e65bb10 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -47,6 +47,7 @@ extern void guiErrorMessage(const char *txt); extern void guiErrorMessage(const char *txt, const sg_throwable &throwable); extern void fgDumpSnapShot(); +extern void fgDumpSceneGraph(); extern puFont guiFnt; extern fntTexFont *guiFntHandle; diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index b87c5c0fe..d8bb9b280 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -571,3 +571,49 @@ void fgDumpSnapShot () { } } +// do a screen snap shot +void fgDumpSceneGraph() +{ + char *filename = new char [24]; + string message; + static int count = 1; + + FGRenderer *renderer = globals->get_renderer(); + + static const SGPropertyNode *master_freeze + = fgGetNode("/sim/freeze/master"); + + bool freeze = master_freeze->getBoolValue(); + if ( !freeze ) { + fgSetBool("/sim/freeze/master", true); + } + + while (count < 1000) { + FILE *fp; + snprintf(filename, 24, "fgfs-graph-%03d.osg", count++); + if ( (fp = fopen(filename, "r")) == NULL ) + break; + fclose(fp); + } + + if ( fgDumpSceneGraphToFile(filename)) { + message = "Scene graphe saved to \""; + message += filename; + message += "\"."; + } else { + message = "Failed to save to \""; + message += filename; + message += "\"."; + } + + mkDialog (message.c_str()); + + delete [] filename; + + if ( !freeze ) { + fgSetBool("/sim/freeze/master", false); + } +} + + + diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 78f4119cc..2c0f7c23d 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -487,6 +487,12 @@ do_screen_capture (const SGPropertyNode * arg) return true; } +static bool +do_dump_scene_graph (const SGPropertyNode*) +{ + fgDumpSceneGraph(); + return true; +} /** * Built-in command: hires capture screen. @@ -1481,6 +1487,7 @@ static struct { { "savexml", do_save_xml_from_proptree }, { "press-cockpit-button", do_press_cockpit_button }, { "release-cockpit-button", do_release_cockpit_button }, + { "dump-scenegraph", do_dump_scene_graph }, { 0, 0 } // zero-terminated }; diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index 913a2372a..a6ab199bb 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -1109,5 +1109,10 @@ FGRenderer::pick( unsigned x, unsigned y, return !pickList.empty(); } +bool fgDumpSceneGraphToFile(const char* filename) +{ + return osgDB::writeNodeFile(*mRealRoot.get(), filename); +} + // end of renderer.cxx diff --git a/src/Main/renderer.hxx b/src/Main/renderer.hxx index 7bc54bfe9..1ac1af354 100644 --- a/src/Main/renderer.hxx +++ b/src/Main/renderer.hxx @@ -74,4 +74,6 @@ protected: osg::ref_ptr manipulator; }; +bool fgDumpSceneGraphToFile(const char* filename); + #endif -- 2.39.5