Revision: 6704
http://playerstage.svn.sourceforge.net/playerstage/?rev=6704&view=rev
Author: jeremy_asher
Date: 2008-06-27 14:10:16 -0700 (Fri, 27 Jun 2008)
Log Message:
-----------
Options registration system, allows instance level options, updating of options
list on world load
Modified Paths:
--------------
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_camera.cc
code/stage/trunk/libstage/model_laser.cc
code/stage/trunk/libstage/option.hh
code/stage/trunk/libstage/options_dlg.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/worldgui.cc
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2008-06-27 18:43:35 UTC (rev 6703)
+++ code/stage/trunk/libstage/model.cc 2008-06-27 21:10:16 UTC (rev 6704)
@@ -238,6 +238,13 @@
// now we can add the basic square shape
this->AddBlockRect( -0.5,-0.5,1,1 );
+
+
+ RegisterOption( &ShowFlags );
+ RegisterOption( &ShowFlags );
+ RegisterOption( &ShowVisData );
+ RegisterOption( &ShowBlinken );
+ RegisterOption( &ShowStatus );
PRINT_DEBUG2( "finished model %s @ %p",
this->token, this );
@@ -1719,15 +1726,3 @@
return mod;
}
-
-const std::vector<Option*> StgModel::getOptions() {
- std::vector<Option*> drawOptions;
- drawOptions.push_back( &ShowFlags );
- drawOptions.push_back( &ShowVisData );
- drawOptions.push_back( &ShowBlinken );
- drawOptions.push_back( &ShowStatus );
-
- return drawOptions;
-}
-
-
Modified: code/stage/trunk/libstage/model_camera.cc
===================================================================
--- code/stage/trunk/libstage/model_camera.cc 2008-06-27 18:43:35 UTC (rev
6703)
+++ code/stage/trunk/libstage/model_camera.cc 2008-06-27 21:10:16 UTC (rev
6704)
@@ -69,6 +69,8 @@
memset( &geom, 0, sizeof(geom)); // no size
//TODO can't draw this as it blocks the laser
SetGeom( geom );
+
+ RegisterOption( &ShowCamera );
Startup();
}
@@ -288,11 +290,3 @@
{
StgModel::Draw( flags, canvas );
}
-
-
-const std::vector<Option*> StgModelCamera::getOptions() {
- std::vector<Option*> drawOptions;
- drawOptions.push_back( &ShowCamera );
-
- return drawOptions;
-}
\ No newline at end of file
Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc 2008-06-27 18:43:35 UTC (rev
6703)
+++ code/stage/trunk/libstage/model_laser.cc 2008-06-27 21:10:16 UTC (rev
6704)
@@ -102,6 +102,8 @@
// don't allocate sample buffer memory until Update() is called
samples = NULL;
+
+ RegisterOption( &ShowLaserData );
}
@@ -359,10 +361,3 @@
glDepthMask( GL_TRUE );
glPopMatrix();
}
-
-const std::vector<Option*> StgModelLaser::getOptions() {
- std::vector<Option*> drawOptions;
- drawOptions.push_back( &ShowLaserData );
-
- return drawOptions;
-}
Modified: code/stage/trunk/libstage/option.hh
===================================================================
--- code/stage/trunk/libstage/option.hh 2008-06-27 18:43:35 UTC (rev 6703)
+++ code/stage/trunk/libstage/option.hh 2008-06-27 21:10:16 UTC (rev 6704)
@@ -2,11 +2,15 @@
#define _OPTION_H_
#include <string>
+#include <iostream>
namespace Stg {
class Option {
private:
+ friend bool compare( const Option* lhs, const Option* rhs );
+ friend std::ostream& operator<<( std::ostream& os, const
Option& opt );
+
std::string optName;
bool value;
public:
@@ -17,10 +21,17 @@
inline operator bool() { return val(); }
inline bool operator<( const Option& rhs ) const
{ return optName<rhs.optName; }
- friend bool compare( const Option* lhs, const Option* rhs );
void set( bool val ) { value = val; }
};
+// std::ostream& operator<<( std::ostream& os, const Option& opt ) {
+// os<<opt.optName;
+// os<<": ";
+// os<<opt.value;
+// return os;
+// }
+//
+ // Comparator to dereference Option pointers and compare their strings
struct optComp {
inline bool operator()( const Option* lhs, const Option* rhs )
const
{ return lhs->operator<(*rhs); }
Modified: code/stage/trunk/libstage/options_dlg.cc
===================================================================
--- code/stage/trunk/libstage/options_dlg.cc 2008-06-27 18:43:35 UTC (rev
6703)
+++ code/stage/trunk/libstage/options_dlg.cc 2008-06-27 21:10:16 UTC (rev
6704)
@@ -4,7 +4,7 @@
namespace Stg {
OptionsDlg::OptionsDlg( int x, int y, int w, int h ) :
- Fl_Window( x,y, w,h, "Model Options" ),
+ Fl_Window( x,y, w,h, "Sensor Options" ),
changedItem( NULL ),
showAll( NULL ),
status( NO_EVENT ),
@@ -69,7 +69,8 @@
void OptionsDlg::updateChecks() {
- scroll->clear();
+ if (scroll->children())
+ scroll->clear();
scroll->begin();
Fl_Check_Button* check;
for ( unsigned int i=0; i<options.size(); i++ ) {
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-27 18:43:35 UTC (rev 6703)
+++ code/stage/trunk/libstage/stage.hh 2008-06-27 21:10:16 UTC (rev 6704)
@@ -1166,6 +1166,7 @@
static GHashTable* modelsbyid;
// Draw options
+ std::vector<Option*> drawOptions;
static Option ShowFlags;
static Option ShowVisData;
static Option ShowBlinken;
@@ -1239,7 +1240,9 @@
int gui_outline;
int gui_mask;
+ void RegisterOption( Option* opt ) { drawOptions.push_back( opt ); }
+
StgModel* parent; //< the model that owns this one, possibly NULL
/** GData datalist can contain arbitrary named data items. Can be used
@@ -1709,7 +1712,7 @@
// iff true, model may output some debugging visualizations and other
info
bool debug;
- virtual const std::vector<Option*> getOptions();
+ const std::vector<Option*>& getOptions() const { return drawOptions; }
};
// BLOCKS
@@ -2014,6 +2017,8 @@
StgCanvas* canvas;
Fl_Menu_Bar* mbar;
OptionsDlg* oDlg;
+ std::vector<Option*> drawOptions;
+ void updateOptions();
stg_usec_t interval_log[INTERVAL_LOG_LEN];
stg_usec_t real_time_of_last_update;
@@ -2254,8 +2259,6 @@
// Set the user-tweakable configuration of the laser
void SetConfig( stg_laser_cfg_t cfg );
-
- virtual const std::vector<Option*> getOptions();
};
// \todo GRIPPER MODEL
--------------------------------------------------------
@@ -2544,8 +2547,6 @@
///get a reference to camera color image. 3 bytes (RGB) per
pixel
inline const GLubyte* FrameColor() const { return
_frame_color_data; }
-
- virtual const std::vector<Option*> getOptions();
};
// POSITION MODEL --------------------------------------------------------
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-06-27 18:43:35 UTC (rev
6703)
+++ code/stage/trunk/libstage/worldgui.cc 2008-06-27 21:10:16 UTC (rev
6704)
@@ -110,7 +110,7 @@
#include <set>
-static const char* MITEM_VIEW_DATA = "&View/&Data";
+static const char* MITEM_VIEW_DATA = "&View/&Display Sensor Data";
static const char* MITEM_VIEW_BLOCKS = "&View/&Blocks";
static const char* MITEM_VIEW_GRID = "&View/&Grid";
static const char* MITEM_VIEW_OCCUPANCY = "&View/&Occupancy";
@@ -162,6 +162,7 @@
mbar->add( "&View", 0, 0, 0, FL_SUBMENU );
mbar->add( MITEM_VIEW_DATA, 'd', StgWorldGui::viewToggleCb,
canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_DATA ?
FL_MENU_VALUE : 0 ));
+ mbar->add( "View/&Sensor options...", FL_CTRL + 'o',
StgWorldGui::viewOptionsCb, this, FL_MENU_DIVIDER );
mbar->add( MITEM_VIEW_BLOCKS, 'b', StgWorldGui::viewToggleCb,
canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_BLOCKS ?
FL_MENU_VALUE : 0 ));
mbar->add( MITEM_VIEW_GRID, 'g', StgWorldGui::viewToggleCb,
canvas,
@@ -187,13 +188,14 @@
mbar->add( MITEM_VIEW_BLOCKSRISING, FL_CTRL+'t',
StgWorldGui::viewToggleCb, canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_TRAILRISE
? FL_MENU_VALUE : 0 ));
- mbar->add( "View/&Options", FL_CTRL + 'o', StgWorldGui::viewOptionsCb,
this );
+
mbar->add( "&Help", 0, 0, 0, FL_SUBMENU );
mbar->add( "Help/&About Stage...", 0, StgWorldGui::helpAboutCb, this );
//mbar->add( "Help/HTML Documentation", FL_CTRL + 'g', (Fl_Callback
*)dummy_cb );
callback( StgWorldGui::windowCb, this );
+
show();
}
@@ -207,7 +209,6 @@
-
void StgWorldGui::Load( const char* filename )
{
PRINT_DEBUG1( "%s.Load()", token );
@@ -292,7 +293,7 @@
item = (Fl_Menu_Item*)mbar->find_item( MITEM_VIEW_STATUS );
(flags & STG_SHOW_STATUS) ? item->check() : item->clear();
-
+ updateOptions();
// TODO - per model visualizations load
}
@@ -550,13 +551,6 @@
void StgWorldGui::viewOptionsCb( Fl_Widget* w, void* p ) {
StgWorldGui* worldGui = static_cast<StgWorldGui*>( p );
-
- std::set<Option*, optComp> options;
- std::vector<Option*> modOpts;
- for( GList* it=worldGui->update_list; it; it=it->next ) {
- modOpts = ((StgModel*)it->data)->getOptions();
- options.insert( modOpts.begin(), modOpts.end() );
- }
if ( !worldGui->oDlg ) {
int x = worldGui->w()+worldGui->x() + 10;
@@ -564,7 +558,7 @@
OptionsDlg* oDlg = new OptionsDlg( x,y, 180,250 );
oDlg->callback( optionsDlgCb, worldGui );
oDlg->showAllOpt( &worldGui->ShowAll );
- oDlg->setOptions( options );
+ oDlg->setOptions( worldGui->drawOptions );
oDlg->show();
worldGui->oDlg = oDlg;
@@ -606,7 +600,7 @@
// instance before the dialog is destroyed
worldGui->oDlg = NULL;
oDlg->hide();
- Fl::delete_widget( oDlg );
+ //Fl::delete_widget( oDlg );
return;
case OptionsDlg::NO_EVENT:
case OptionsDlg::CHANGE_ALL:
@@ -743,3 +737,18 @@
return true;
}
}
+
+void StgWorldGui::updateOptions() {
+ std::set<Option*, optComp> options;
+ std::vector<Option*> modOpts;
+ for( GList* it=update_list; it; it=it->next ) {
+ modOpts = ((StgModel*)it->data)->getOptions();
+ options.insert( modOpts.begin(), modOpts.end() );
+ }
+
+ drawOptions.assign( options.begin(), options.end() );
+
+ if ( oDlg ) {
+ oDlg->setOptions( drawOptions );
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit