Revision: 7282 http://playerstage.svn.sourceforge.net/playerstage/?rev=7282&view=rev Author: alexcb Date: 2009-01-21 23:07:45 +0000 (Wed, 21 Jan 2009)
Log Message: ----------- added data visualization filter support for custom visualization Modified Paths: -------------- code/stage/trunk/libstage/model.cc code/stage/trunk/libstage/model.hh code/stage/trunk/libstage/option.hh code/stage/trunk/libstage/stage.hh code/stage/trunk/libstage/stage_internal.hh Modified: code/stage/trunk/libstage/model.cc =================================================================== --- code/stage/trunk/libstage/model.cc 2009-01-20 05:39:31 UTC (rev 7281) +++ code/stage/trunk/libstage/model.cc 2009-01-21 23:07:45 UTC (rev 7282) @@ -165,7 +165,8 @@ watts(0), wf(NULL), wf_entity(0), - world(world) + world(world), + world_gui( dynamic_cast< WorldGui* >( world ) ) { assert( modelsbyid ); assert( world ); @@ -926,14 +927,34 @@ void Model::AddCustomVisualizer( CustomVisualizer* custom_visual ) { - if( custom_visual ) - custom_visual_list = g_list_append(custom_visual_list, custom_visual ); + if( !custom_visual ) + return; + + //Visualizations can only be added to stage when run in a GUI + if( world_gui == NULL ) { + printf( "Unable to add custom visualization - it must be run with a GUI world\n" ); + return; + } + + //save visual instance + custom_visual_list = g_list_append(custom_visual_list, custom_visual ); + + //register option for all instances which share the same name + Canvas* canvas = world_gui->GetCanvas(); + std::map< std::string, Option* >::iterator i = canvas->_custom_options.find( custom_visual->name() ); + if( i == canvas->_custom_options.end() ) { + Option* op = new Option( custom_visual->name(), custom_visual->name(), "", true ); + canvas->_custom_options[ custom_visual->name() ] = op; + registerOption( op ); + } } void Model::RemoveCustomVisualizer( CustomVisualizer* custom_visual ) { if( custom_visual ) custom_visual_list = g_list_remove(custom_visual_list, custom_visual ); + + //TODO unregister option - tricky because there might still be instances attached to different models which have the same name } @@ -1218,8 +1239,11 @@ PushLocalCoords(); DataVisualize( cam ); // virtual function overridden by most model types + CustomVisualizer* vis; for( GList* item = custom_visual_list; item; item = item->next ) { - static_cast< CustomVisualizer* >( item->data )->DataVisualize( cam ); + vis = static_cast< CustomVisualizer* >( item->data ); + if( world_gui->GetCanvas()->_custom_options[ vis->name() ]->isEnabled() ) + vis->DataVisualize( cam ); } Modified: code/stage/trunk/libstage/model.hh =================================================================== --- code/stage/trunk/libstage/model.hh 2009-01-20 05:39:31 UTC (rev 7281) +++ code/stage/trunk/libstage/model.hh 2009-01-21 23:07:45 UTC (rev 7282) @@ -68,6 +68,7 @@ //TODO allow user to specify name - which will show up in display filter virtual ~CustomVisualizer( void ) { } virtual void DataVisualize( Camera* cam ) = 0; + virtual const std::string& name() = 0; //must return a name for visualization (careful not to return stack-memory) }; @@ -207,6 +208,7 @@ Worldfile* wf; int wf_entity; World* world; // pointer to the world in which this model exists + WorldGui* world_gui; //pointer to the GUI world - NULL if running in non-gui mode public: Modified: code/stage/trunk/libstage/option.hh =================================================================== --- code/stage/trunk/libstage/option.hh 2009-01-20 05:39:31 UTC (rev 7281) +++ code/stage/trunk/libstage/option.hh 2009-01-21 23:07:45 UTC (rev 7282) @@ -33,6 +33,7 @@ Option( std::string n, std::string tok, std::string key, bool v ); const std::string name() const { return optName; } + inline bool isEnabled() const { return value; } inline bool val() const { return value; } inline operator bool() { return val(); } inline bool operator<( const Option& rhs ) const Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2009-01-20 05:39:31 UTC (rev 7281) +++ code/stage/trunk/libstage/stage.hh 2009-01-21 23:07:45 UTC (rev 7282) @@ -1300,6 +1300,7 @@ { friend class Canvas; friend class ModelCamera; + friend class Model; private: Modified: code/stage/trunk/libstage/stage_internal.hh =================================================================== --- code/stage/trunk/libstage/stage_internal.hh 2009-01-20 05:39:31 UTC (rev 7281) +++ code/stage/trunk/libstage/stage_internal.hh 2009-01-21 23:07:45 UTC (rev 7282) @@ -8,6 +8,9 @@ #ifndef STG_INTERNAL_H #define STG_INTERNAL_H +#include <map> +#include <string> + // external definitions for libstage users #include "stage.hh" @@ -100,6 +103,8 @@ showBlur, pCamOn, visualizeAll; + + std::map< std::string, Option* > _custom_options; public: Canvas( WorldGui* world, int x, int y, int width, int height); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit