Revision: 7604
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7604&view=rev
Author:   rtv
Date:     2009-04-22 02:48:52 +0000 (Wed, 22 Apr 2009)

Log Message:
-----------
adding pose history logging

Modified Paths:
--------------
    code/stage/trunk/libstage/CMakeLists.txt
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc

Added Paths:
-----------
    code/stage/trunk/libstage/logentry.cc

Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt    2009-04-21 00:15:40 UTC (rev 
7603)
+++ code/stage/trunk/libstage/CMakeLists.txt    2009-04-22 02:48:52 UTC (rev 
7604)
@@ -12,6 +12,7 @@
        file_manager.hh
        gl.cc
        glcolorstack.cc
+       logentry.cc
        model.cc
        model_blinkenlight.cc
        model_blobfinder.cc

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2009-04-21 00:15:40 UTC (rev 7603)
+++ code/stage/trunk/libstage/canvas.cc 2009-04-22 02:48:52 UTC (rev 7604)
@@ -357,90 +357,100 @@
                invalidate();
                redraw();
                return 1;
-                       
+               
         case FL_MOVE: // moused moved while no button was pressed
-               if ( startx >=0 ) {
-                 // mouse pointing to valid value
-                       
-                 if( Fl::event_state( FL_CTRL ) )
-                        {
-                               int dx = Fl::event_x() - startx;
-                               int dy = Fl::event_y() - starty;
-
-                               if( pCamOn == true ) {
-                                 perspective_camera.addYaw( -dx );
-                                 perspective_camera.addPitch( -dy );
-                               } 
-                               else {
-                                 camera.addPitch( - 0.5 * static_cast<double>( 
dy ) );
-                                 camera.addYaw( - 0.5 * static_cast<double>( 
dx ) );
+               if( Fl::event_state( FL_META ) )
+                 {
+                        puts( "TODO: HANDLE HISTORY" );
+                        //world->paused = ! world->paused;
+                        return 1;
+                 }
+               
+               if ( startx >=0 ) 
+                 {
+                        // mouse pointing to valid value
+                        
+                        if( Fl::event_state( FL_CTRL ) )
+                               {
+                                 int dx = Fl::event_x() - startx;
+                                 int dy = Fl::event_y() - starty;
+                                 
+                                 if( pCamOn == true ) {
+                                        perspective_camera.addYaw( -dx );
+                                        perspective_camera.addPitch( -dy );
+                                 } 
+                                 else {
+                                        camera.addPitch( - 0.5 * 
static_cast<double>( dy ) );
+                                        camera.addYaw( - 0.5 * 
static_cast<double>( dx ) );
+                                 }
+                                 invalidate();
+                                 redraw();
                                }
-                               invalidate();
-                               redraw();
-                        }
-                 else if( Fl::event_state( FL_ALT ) )
-                        {   
-                               int dx = Fl::event_x() - startx;
-                               int dy = Fl::event_y() - starty;
-
-                               if( pCamOn == true ) {
-                                 perspective_camera.move( -dx, dy, 0.0 );
-                               } 
-                               else {
-                                 camera.move( -dx, dy );
+                        else if( Fl::event_state( FL_ALT ) )
+                               {   
+                                 int dx = Fl::event_x() - startx;
+                                 int dy = Fl::event_y() - starty;
+                                 
+                                 if( pCamOn == true ) {
+                                        perspective_camera.move( -dx, dy, 0.0 
);
+                                 } 
+                                 else {
+                                        camera.move( -dx, dy );
+                                 }
+                                 invalidate();
                                }
-                               invalidate();
-                        }
-               }
+                 }
                startx = Fl::event_x();
                starty = Fl::event_y();
                return 1;
-
         case FL_PUSH: // button pressed
                {
-                 Model* mod = getModel( startx, starty );
-                 startx = Fl::event_x();
-                 starty = Fl::event_y();
-                 selectedModel = false;
-                 switch( Fl::event_button() )
+                 //else
                         {
-                        case 1:
-                               clicked_empty_space = ( mod == NULL );
-                               empty_space_startx = startx;
-                               empty_space_starty = starty;
-                               if( mod ) { 
-                                 // clicked a model
-                                 if ( Fl::event_state( FL_SHIFT ) ) {
-                                        // holding shift, toggle selection
-                                        if ( selected( mod ) ) 
-                                               unSelect( mod );
-                                        else {
-                                               select( mod );
-                                               selectedModel = true; // 
selected a model
+                               Model* mod = getModel( startx, starty );
+                               startx = Fl::event_x();
+                               starty = Fl::event_y();
+                               selectedModel = false;
+                               switch( Fl::event_button() )
+                                 {
+                                 case 1:
+                                        clicked_empty_space = ( mod == NULL );
+                                        empty_space_startx = startx;
+                                        empty_space_starty = starty;
+                                        if( mod ) { 
+                                               // clicked a model
+                                               if ( Fl::event_state( FL_SHIFT 
) ) {
+                                                 // holding shift, toggle 
selection
+                                                 if ( selected( mod ) ) 
+                                                        unSelect( mod );
+                                                 else {
+                                                        select( mod );
+                                                        selectedModel = true; 
// selected a model
+                                                 }
+                                               }
+                                               else {
+                                                 if ( !selected( mod ) ) {
+                                                        // clicked on an 
unselected model while
+                                                        //  not holding shift, 
this is the new
+                                                        //  selection
+                                                        unSelectAll();
+                                                        select( mod );
+                                                 }
+                                                 selectedModel = true; // 
selected a model
+                                               }
                                         }
-                                 }
-                                 else {
-                                        if ( !selected( mod ) ) {
-                                               // clicked on an unselected 
model while
-                                               //  not holding shift, this is 
the new
-                                               //  selection
-                                               unSelectAll();
-                                               select( mod );
+                                        
+                                        return 1;
+                                 case 3:
+                                        {
+                                               // leave selections alone
+                                               // rotating handled within 
FL_DRAG
+                                               return 1;
                                         }
-                                        selectedModel = true; // selected a 
model
-                                 }
-                               }
-               
-                               return 1;
-                        case 3:
-                               {
-                                 // leave selections alone
-                                 // rotating handled within FL_DRAG
-                                 return 1;
-                               }
-                        default:
-                               return 0;
-                        }    
+                                 default:
+                                        return 0;
+                                 }    
+                        }
                }
          
         case FL_DRAG: // mouse moved while button was pressed

Added: code/stage/trunk/libstage/logentry.cc
===================================================================
--- code/stage/trunk/libstage/logentry.cc                               (rev 0)
+++ code/stage/trunk/libstage/logentry.cc       2009-04-22 02:48:52 UTC (rev 
7604)
@@ -0,0 +1,29 @@
+#include "stage.hh"
+using namespace Stg;
+
+// static data members
+std::vector<LogEntry> LogEntry::log;
+
+LogEntry::LogEntry( stg_usec_t timestamp, Model* mod ) :
+  timestamp( timestamp ),
+  mod( mod ),
+  pose( mod->GetPose() )
+{ 
+  // all log entries are added to the static vector history
+  log.push_back( *this );
+}
+
+
+
+void LogEntry::Print()
+{
+  for( size_t i=0; i<log.size(); i++ )
+        {
+               LogEntry* e = &log[i];
+
+               printf( "%.3f\t%u\t%s\n",
+                                 (double)e->timestamp / 1e6,
+                                 e->mod->GetId(),
+                                 e->mod->PoseString().c_str() );
+        }
+}

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-04-21 00:15:40 UTC (rev 7603)
+++ code/stage/trunk/libstage/model.cc  2009-04-22 02:48:52 UTC (rev 7604)
@@ -209,6 +209,7 @@
     initfunc(NULL),
     interval((stg_usec_t)1e4), // 10msec
     last_update(0),
+        log_state(false),
     map_resolution(0.1),
     mass(0),
     on_update_list( false ),
@@ -713,6 +714,9 @@
     }
 
   last_update = world->sim_time;
+  
+  if( log_state )
+        world->Log( this );
 }
 
 void Model::CallUpdateCallbacks( void )

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-04-21 00:15:40 UTC (rev 7603)
+++ code/stage/trunk/libstage/stage.hh  2009-04-22 02:48:52 UTC (rev 7604)
@@ -279,6 +279,14 @@
       printf( "%s pose [x:%.3f y:%.3f z:%.3f a:%.3f]\n",
                                  prefix, x,y,z,a );
     }
+        
+        std::string String()
+        {
+               char buf[256];
+               snprintf( buf, 256, "[ %.3f %.3f %.3f %.3f ]",
+                                        x,y,z,a );
+               return std::string(buf);
+        }
 
         /* returns true iff all components of the velocity are zero. */
         bool IsZero() const { return( !(x || y || z || a )); };
@@ -818,6 +826,28 @@
   class BlockGroup;
   class PowerPack;
 
+  class LogEntry
+  {
+        stg_usec_t timestamp;
+        Model* mod;
+        Pose pose;
+        
+  public:
+        LogEntry( stg_usec_t timestamp, Model* mod );
+        
+        /** A log of all LogEntries ever created */
+        static std::vector<LogEntry> log;
+        
+        /** Returns the number of logged entries */
+        static size_t Count(){ return log.size(); }
+        
+        /** Clear the log */
+        static void Clear(){ log.clear(); }
+
+        /** Print the log on stdout */
+        static void Print();
+  };
+
   /// %World class
   class World : public Ancestor
   {
@@ -879,6 +909,9 @@
     static const int DEFAULT_PPM = 50;  // default resolution in pixels per 
meter
     static const stg_msec_t DEFAULT_INTERVAL_SIM = 100;  ///< duration of sim 
timestep
 
+        /** Log the state of a Model */
+        void Log( Model* mod );
+
     /** hint that the world needs to be redrawn if a GUI is attached */
     void NeedRedraw(){ dirty = true; };
 
@@ -1699,6 +1732,7 @@
         ctrlinit_t* initfunc;
         stg_usec_t interval; ///< time between updates in us
         stg_usec_t last_update; ///< time of last update in us  
+        bool log_state; ///< iff true, model state is logged
         stg_meters_t map_resolution;
         stg_kg_t mass;
         bool on_update_list;
@@ -1935,6 +1969,8 @@
         void PlaceInFreeSpace( stg_meters_t xmin, stg_meters_t xmax, 
                                                                        
stg_meters_t ymin, stg_meters_t ymax );
        
+        std::string PoseString(){ return pose.String(); }
+
         /** Look up a model pointer by a unique model ID */
         static Model* LookupId( uint32_t id )
         { return (Model*)g_hash_table_lookup( modelsbyid, (void*)id ); }

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-04-21 00:15:40 UTC (rev 7603)
+++ code/stage/trunk/libstage/world.cc  2009-04-22 02:48:52 UTC (rev 7604)
@@ -53,6 +53,7 @@
 #include "option.hh"
 using namespace Stg;
 
+
 // static data members
 unsigned int World::next_id = 0;
 bool World::quit_all = false;
@@ -1040,3 +1041,13 @@
 
 stg_usec_t World::SimTimeNow(void)
 { return sim_time; }
+
+void World::Log( Model* mod )
+{
+  LogEntry( sim_time, mod);
+
+  printf( "log entry count %lu\n", LogEntry::Count() );
+  //LogEntry::Print();
+}
+
+


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

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to