Revision: 7336
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7336&view=rev
Author:   rtv
Date:     2009-02-16 01:59:06 +0000 (Mon, 16 Feb 2009)

Log Message:
-----------
working on simplifying GUI option code

Modified Paths:
--------------
    code/stage/trunk/libstage/CMakeLists.txt
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_draw.cc
    code/stage/trunk/libstage/model_laser.cc
    code/stage/trunk/libstage/option.cc
    code/stage/trunk/libstage/option.hh
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/libstage/worldgui.cc
    code/stage/trunk/worlds/fasr.world

Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt    2009-02-16 00:02:13 UTC (rev 
7335)
+++ code/stage/trunk/libstage/CMakeLists.txt    2009-02-16 01:59:06 UTC (rev 
7336)
@@ -4,7 +4,6 @@
 include_directories(${PROJECT_BINARY_DIR})
 
 set( stageSrcs ancestor.cc
-       model_gripper.cc
        block.cc
        blockgroup.cc
        camera.cc
@@ -21,6 +20,7 @@
        model_camera.cc
        model_fiducial.cc
        model_getset.cc
+       model_gripper.cc
        model_laser.cc
        model_load.cc
        model_position.cc

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/libstage/model.cc  2009-02-16 01:59:06 UTC (rev 7336)
@@ -1019,3 +1019,11 @@
 
   return NULL;
 }
+
+void Model::RegisterOption( Option* opt )
+{ 
+  drawOptions.push_back( opt ); 
+  
+  if( world->IsGUI() )
+        world->RegisterOption( opt );
+}

Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc     2009-02-16 00:02:13 UTC (rev 
7335)
+++ code/stage/trunk/libstage/model_draw.cc     2009-02-16 01:59:06 UTC (rev 
7336)
@@ -263,7 +263,11 @@
        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, world_gui );
+               Option* op = new Option( custom_visual->name(), 
+                                                                               
 custom_visual->name(), 
+                                                                               
 "", 
+                                                                               
 true, 
+                                                                               
 world_gui );
                canvas->_custom_options[ custom_visual->name() ] = op;
                registerOption( op );
        }

Modified: code/stage/trunk/libstage/model_laser.cc
===================================================================
--- code/stage/trunk/libstage/model_laser.cc    2009-02-16 00:02:13 UTC (rev 
7335)
+++ code/stage/trunk/libstage/model_laser.cc    2009-02-16 01:59:06 UTC (rev 
7336)
@@ -108,10 +108,12 @@
   if( world->IsGUI() )
     data_dl = glGenLists(1);
        
-  registerOption( &showLaserData );
-  registerOption( &showLaserStrikes );
-  registerOption( &showLaserFov );
-  registerOption( &showLaserBeams );
+  RegisterOption( &showLaserData );
+  RegisterOption( &showLaserStrikes );
+  RegisterOption( &showLaserFov );
+  RegisterOption( &showLaserBeams );
+  
+  //AddCustomVisualizer( new LaserScanVis( this ));
 }
 
 
@@ -420,3 +422,10 @@
            
   glPopMatrix();
 }
+
+  
+// void ModelLaser::LaserScanVis::DataVisualize( Camera* cam )
+// {
+//   puts( "LSV DataVisualize" );
+//   laser->DataVisualize( cam );
+// }

Modified: code/stage/trunk/libstage/option.cc
===================================================================
--- code/stage/trunk/libstage/option.cc 2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/libstage/option.cc 2009-02-16 01:59:06 UTC (rev 7336)
@@ -13,7 +13,8 @@
 shortcut( key ), 
 menu( NULL ),
 menuCb( NULL ),
-_world( world )
+_world( world ),
+htname( strdup(n.c_str()) )
 { }
 
 Fl_Menu_Item* getMenuItem( Fl_Menu_* menu, int i ) {

Modified: code/stage/trunk/libstage/option.hh
===================================================================
--- code/stage/trunk/libstage/option.hh 2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/libstage/option.hh 2009-02-16 01:59:06 UTC (rev 7336)
@@ -55,6 +55,8 @@
                static void toggleCb( Fl_Widget* w, void* p );
                void Load( Worldfile* wf, int section );
                void Save( Worldfile* wf, int section );          
+
+         const char* htname;
        };
 }
        

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/libstage/stage.hh  2009-02-16 01:59:06 UTC (rev 7336)
@@ -891,6 +891,7 @@
     stg_bounds3d_t extent; ///< Describes the 3D volume of the world
     bool graphics;///< true iff we have a GUI
     stg_usec_t interval_sim; ///< temporal resolution: microseconds that 
elapse between simulated time steps 
+        GHashTable* option_table; ///< GUI options (toggles) registered by 
models
         GList* powerpack_list; ///< List of all the powerpacks attached to 
models in the world
     GList* ray_list;///< List of rays traced for debug visualization
     stg_usec_t sim_time; ///< the current sim time in this world in ms
@@ -1051,6 +1052,9 @@
   
     /** Return the number of times the world has been updated. */
     long unsigned int GetUpdateCount() { return updates; }
+
+        /// Register an Option for pickup by the GUI
+        void RegisterOption( Option* opt );    
   };
 
   class Block
@@ -1376,7 +1380,7 @@
     stg_usec_t real_time_of_last_update;
 
     void UpdateOptions();
-       
+        
     // static callback functions
     static void windowCb( Fl_Widget* w, void* p );     
     static void fileLoadCb( Fl_Widget* w, void* p );
@@ -1507,8 +1511,7 @@
         virtual const std::string& name() = 0; //must return a name for 
visualization (careful not to return stack-memory)
   };
 
-
-
+  
   /* Hooks for attaching special callback functions (not used as
          variables - we just need unique addresses for them.) */  
   class CallbackHooks
@@ -1534,46 +1537,6 @@
         void Load( Worldfile* wf, int wf_entity );
   };
 
-  // class Option {
-  // private:
-  //   friend bool compare( const Option* lhs, const Option* rhs );
-  
-  //   std::string optName;
-  //   bool value;
-  //   /** worldfile entry string for loading and saving this value */
-  //   std::string wf_token; 
-  //   std::string shortcut;
-  //   Fl_Menu_* menu;
-  //   int menuIndex;
-  //   Fl_Callback* menuCb;
-  //   Fl_Widget* menuCbWidget;
-  
-  // public:
-  //   Option( std::string n, std::string tok, std::string key, bool v, 
WorldGui* worldgui );    
-  
-  //   const std::string name() const { return optName; }
-  //   inline bool val() const { return value; }
-  //   inline operator bool() { return val(); }
-  //   inline bool operator<( const Option& rhs ) const
-  //   { return optName<rhs.optName; } 
-  //   void set( bool val );
-  //   void invert() { set( !value ); }
-  
-  //   // 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); } 
-  //   };
-  
-  
-  //   void createMenuItem( Fl_Menu_Bar* menu, std::string path );
-  //           void menuCallback( Fl_Callback* cb, Fl_Widget* w );
-  //   static void toggleCb( Fl_Widget* w, void* p );
-  //   void Load( Worldfile* wf, int section );
-  //   void Save( Worldfile* wf, int section );          
-  // };
-
-
   /// %Model class
   class Model : public Ancestor
   {
@@ -1720,8 +1683,8 @@
   protected:
 
         /// Register an Option for pickup by the GUI
-        void registerOption( Option* opt )
-        { drawOptions.push_back( opt ); }
+        void RegisterOption( Option* opt );
+        void registerOption( Option* opt ) { RegisterOption( opt) ; };
 
         GList* AppendTouchingModels( GList* list );
         //void AddTouchingModelsToList( GList* list );
@@ -1872,8 +1835,10 @@
         virtual ~Model();
        
         void Say( const char* str );
-        /** Attach a user supplied visualization to a model */
+        
+        /** Attach a user supplied visualization to a model. */
         void AddCustomVisualizer( CustomVisualizer* custom_visual );
+
         /** remove user supplied visualization to a model - supply the same 
ptr passed to AddCustomVisualizer */
         void RemoveCustomVisualizer( CustomVisualizer* custom_visual );
 
@@ -2272,7 +2237,27 @@
         static Option showLaserStrikes;
         static Option showLaserFov;
         static Option showLaserBeams;
-  
+        
+//      class LaserScanVis : public CustomVisualizer 
+//      {
+//      public:
+//             LaserScanVis( ModelLaser* laser ) : 
+//               CustomVisualizer(), 
+//               laser( laser )
+//             { /* nothing to do */ };
+               
+//             virtual void DataVisualize( Camera* cam );
+               
+//             // rtv - surely a static string member would be easier here?
+//             //must return a name for visualization (careful not to return 
stack-memory)     
+
+//             virtual const std::string& name() { return "LaserScanVisName"; 
} ; 
+
+//      private:
+//             ModelLaser* laser;
+//      };
+
+
   public:
         static const char* typestr;
         // constructor

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/libstage/world.cc  2009-02-16 01:59:06 UTC (rev 7336)
@@ -50,6 +50,7 @@
 #include "file_manager.hh"
 #include "worldfile.hh"
 #include "region.hh"
+#include "option.hh"
 using namespace Stg;
 
 // static data members
@@ -95,6 +96,7 @@
   extent(),
   graphics( false ), 
   interval_sim( (stg_usec_t)thousand * interval_sim ),
+  option_table( g_hash_table_new( g_str_hash, g_str_equal ) ), 
   ray_list( NULL ),  
   sim_time( 0 ),
   superregions( g_hash_table_new( (GHashFunc)PointIntHash, 
@@ -945,3 +947,9 @@
 {
   powerpack_list = g_list_remove( powerpack_list, pp ); 
 }
+
+/// Register an Option for pickup by the GUI
+void World:: RegisterOption( Option* opt )
+{
+  g_hash_table_insert( option_table, (void*)opt->htname, opt );
+}

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2009-02-16 00:02:13 UTC (rev 
7335)
+++ code/stage/trunk/libstage/worldgui.cc       2009-02-16 01:59:06 UTC (rev 
7336)
@@ -519,6 +519,12 @@
 }
 
 
+void list_option( char* name, Option* opt, void* dummy )
+{
+  printf( "option %s @ %p\n", name, opt );
+
+}
+
 void WorldGui::viewOptionsCb( Fl_Widget* w, void* p ) 
 {
   WorldGui* worldGui = static_cast<WorldGui*>( p );
@@ -538,6 +544,8 @@
         {
                worldGui->oDlg->show(); // bring it to front
         }
+  
+  //g_hash_table_foreach( worldGui->option_table, (GHFunc)list_option, NULL ); 
 
 }
 
 void WorldGui::optionsDlgCb( Fl_Widget* w, void* p ) {

Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world  2009-02-16 00:02:13 UTC (rev 7335)
+++ code/stage/trunk/worlds/fasr.world  2009-02-16 01:59:06 UTC (rev 7336)
@@ -72,7 +72,7 @@
 
 define autorob pioneer2dx                
 (               
- sicklaser( samples 180 range_max 5 laser_return 2 watts 30 )
+ sicklaser( samples 32 range_max 5 laser_return 2 watts 30 )
  ctrl "fasr"
  joules 100000 
  joules_capacity 400000 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to