Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

AppControlDoc.h

Go to the documentation of this file.
00001 #ifndef Impala_Visualization_AppControlDoc_h
00002 #define Impala_Visualization_AppControlDoc_h
00003 
00004 #include <sstream>
00005 #include <vector>
00006 #include "Basis/Timer.h"
00007 #include "Visualization/AppControl.h"
00008 #include "Visualization/KeyBindingsMap.h"
00009 #include "OglGui/Sys.h"
00010 #include "Core/Database/DataDocument.h"
00011 #include "Core/Database/DataDocumentListener.h"
00012 
00013 namespace Impala
00014 {
00015 namespace Visualization
00016 {
00017 
00018 
00019 class AppControlDoc : public AppControl
00020 {
00021 public:
00022     typedef Core::Database::DataDocument DataDocument;
00023     typedef Core::Database::DataDocumentListener DataDocumentListener;
00024     typedef Core::Database::DocLevel DocLevel;
00025 
00026     AppControlDoc(int id, DataDocument* doc) : AppControl(id, false), mTimer(1)
00027     {
00028         mDoc = doc;
00029         mDone = false;
00030         mDoContinuous = false;
00031         mNrItemsDone = 0;
00032 
00033         //CmdOptions& options = CmdOptions::GetInstance();
00034         //String videoSet = options.GetString("videoSet", "");
00035 
00036         InitKeyBinding("dataFirstDir","ctrl#home");
00037         InitKeyBinding("dataNextDir", "ctrl#pagedown");
00038         InitKeyBinding("dataPrevDir", "ctrl#pageup");
00039         InitKeyBinding("dataNextFile", "ctrl#down");
00040         InitKeyBinding("dataPrevFile", "ctrl#up");
00041         InitKeyBinding("dataNextShot", "ctrl#right");
00042         InitKeyBinding("dataPrevShot", "ctrl#left");
00043         InitKeyBinding("dataAddBookMark", "b");
00044         InitKeyBinding("dataDelBookMark", "B");
00045         InitKeyBinding("dataContinuous", "c");
00046         InitKeyBinding("dataNotContinuous", "C");
00047     }
00048 
00049     void
00050     AddDocListener(DataDocumentListener* listener)
00051     {
00052         ILOG_DEBUG("(" << GetControlId() << ")::AddDocListener");
00053         mDocListeners.push_back(listener);
00054     }
00055 
00056     void InitKeyBinding(String keyStr, String dfltStr)
00057     {
00058         mKeyBindings[keyStr] = GetKeyBinding(keyStr, dfltStr);
00059     }
00060 
00061     void
00062     SetDoContinuous(bool flag)
00063     {
00064         mDoContinuous = flag;
00065         if (mDoContinuous)
00066             IpsReset();
00067     }
00068 
00069     bool
00070     GetDoContinuous()
00071     {
00072         return mDoContinuous;
00073     }
00074 
00075     void
00076     IpsReset()
00077     {
00078         mTimer.Start();
00079         mNrItemsDone = 0;
00080     }
00081 
00082     std::string
00083     GetIpsString()
00084     {
00085         double timeVal = mTimer.SplitTime();
00086         double ips = (double) mNrItemsDone / timeVal;
00087         std::ostringstream ipsStream;
00088         ipsStream << mNrItemsDone << " items in " << timeVal
00089                   << " sec = " << ips << " ips" << std::ends;
00090         return ipsStream.str();
00091     }
00092 
00093     // in general: doRightOnBookmarks is used with video only
00094     void
00095     VisitAll(bool doRightOnBookmarks, int startDir, int numberDir)
00096     {
00097         if (mDoc->HasBookmarks())
00098         {
00099             DocLevel level;
00100             do
00101             {
00102                 level = mDoc->CursorNextBookmark();
00103                 AllHandleNewCursor(level, true);
00104                 if (doRightOnBookmarks && (level != Core::Database::LEVEL_NONE))
00105                 {
00106                     DocLevel level2;
00107                     do
00108                     {
00109                         level2 = mDoc->CursorNextShot();
00110                         AllHandleNewCursor(level2, false);
00111                     }
00112                     while (level2 != Core::Database::LEVEL_NONE);
00113                 }
00114                 AllHandleDoneCursor(level);
00115             }
00116             while (level != Core::Database::LEVEL_NONE);
00117         }
00118         else
00119         {
00120             if (numberDir == -1)
00121                 numberDir = mDoc->GetDataSet()->NrDirs();
00122             DocLevel level1 = mDoc->CursorToDir(startDir);
00123             AllHandleNewCursor(level1, false);
00124             int nr = 0;
00125             while ((level1 != Core::Database::LEVEL_NONE) && (nr < numberDir))
00126             {
00127                 DocLevel level2;
00128                 do
00129                 {
00130                     level2 = mDoc->CursorNextShot();
00131                     AllHandleNewCursor(level2, false);
00132                 }
00133                 while (level2 != Core::Database::LEVEL_NONE);
00134                 AllHandleDoneCursor(level1);
00135                 nr++;
00136                 if (nr < numberDir)
00137                 {
00138                     level1 = mDoc->CursorNextDir();
00139                     AllHandleNewCursor(level1, false);
00140                 }
00141             }
00142         }
00143         AllHandleDoneVisit();
00144     }
00145 
00146     // specialization of base class
00147 
00148     virtual void
00149     ComputeCycle(double elapsedTime)
00150     {
00151         /*
00152         if (elapsedTime > mLastTime + mInterval)
00153         {
00154             mLastTime = elapsedTime;
00155             AllHandleCycleDoc();
00156         }
00157         */
00158         if (!GetDoContinuous())
00159             return;
00160         AllHandleNewCursor(mDoc->CursorNextShot(), false);
00161         AllHandleCycleDoc();
00162         mNrItemsDone++;
00163     }
00164 
00165     virtual void
00166     HandleActivate()
00167     {
00168         ILOG_DEBUG("(" << GetControlId() << ")::HandleActivate()");
00169         for (int i=0 ; i<mDocListeners.size() ; i++)
00170         {
00171             mDocListeners[i]->HandleNewFile();
00172             mDocListeners[i]->HandleNewBookmarked();
00173         }
00174     }
00175 
00176     bool CheckBinding(String keyStr, int c, int state)
00177     {
00178         return CheckKeyBinding(mKeyBindings,keyStr,c,state);
00179     }
00180 
00181     virtual void
00182     KeyEvent(OglGui::Window* src, int c, int state)
00183     {
00184         ILOG_DEBUG("(" << GetControlId() << ")::KeyEvent: " << c);
00185         //ILOG_INFO("(" << GetControlId() << ")::KeyEvent: " << c);
00186         if (c == 'Q')
00187         {
00188             ILOG_INFO("Instant exit button pressed.");
00189             mDone = true;
00190         }
00191         if (CheckBinding("dataFirstDir",c,state))
00192             AllHandleNewCursor(mDoc->CursorToDir(0), false);
00193         if (CheckBinding("dataNextDir",c,state))
00194             AllHandleNewCursor(mDoc->CursorNextDir(), false);
00195         else if (CheckBinding("dataPrevDir",c,state))
00196             AllHandleNewCursor(mDoc->CursorPrevDir(), false);
00197         else if (CheckBinding("dataNextFile",c,state))
00198             AllHandleNewCursor(mDoc->CursorNextFile(), false);
00199         else if (CheckBinding("dataPrevFile",c,state))
00200             AllHandleNewCursor(mDoc->CursorPrevFile(), false);
00201         else if (CheckBinding("dataNextShot",c,state))
00202             AllHandleNewCursor(mDoc->CursorNextShot(), false);
00203         else if (CheckBinding("dataPrevShot",c,state))
00204             AllHandleNewCursor(mDoc->CursorPrevShot(), false);
00205 
00206 
00207         // from here on, propagation of event is responsibility of callee
00208         else if (CheckBinding("dataAddBookMark",c,state))
00209             AddCursorToBookmarked();
00210         else if (CheckBinding("dataDelBookMark",c,state))
00211             RemoveCursorFromBookmarked();
00212         else if (CheckBinding("dataContinuous",c,state))
00213             SetDoContinuous(true);
00214         else if (CheckBinding("dataNotContinuous",c,state))
00215             SetDoContinuous(false);
00216 
00217         for (int i=0 ; i<mDocListeners.size() ; i++)
00218             mDocListeners[i]->HandleNewKey(c, state);
00219     }
00220 
00221     virtual bool
00222     Done()
00223     {
00224         return mDone;
00225     }
00226 
00227     // interface to derived classes
00228 
00229     virtual void
00230     AddCursorToBookmarked()
00231     {
00232     }
00233 
00234     virtual void
00235     RemoveCursorFromBookmarked()
00236     {
00237     }
00238 
00239 // RvB commented next line, making methods public
00240 // protected:
00241 
00242     void
00243     AllHandleNewCursor(DocLevel docLevel, bool doBookmark)
00244     {
00245         if (docLevel == 0)
00246             return;
00247         for (int i=0 ; i<mDocListeners.size() ; i++)
00248         {
00249             if (doBookmark)
00250                 mDocListeners[i]->HandleCursorBookmarked();
00251             switch (docLevel) {
00252             case Core::Database::LEVEL_DIR:
00253                 mDocListeners[i]->HandleNewDir();
00254                 break;
00255             case Core::Database::LEVEL_FILE:
00256                 mDocListeners[i]->HandleNewFile();
00257                 break;
00258             case Core::Database::LEVEL_SHOT:
00259                 mDocListeners[i]->HandleNewShot();
00260                 break;
00261             case Core::Database::LEVEL_FRAME:
00262                 mDocListeners[i]->HandleNewFrame();
00263                 break;
00264             }
00265         }
00266     }
00267 
00268     void
00269     AllHandleDoneCursor(DocLevel docLevel)
00270     {
00271         if (docLevel == 0)
00272             return;
00273         for (int i=0 ; i<mDocListeners.size() ; i++)
00274         {
00275             switch (docLevel) {
00276             case Core::Database::LEVEL_DIR:
00277                 mDocListeners[i]->HandleDoneDir();
00278                 break;
00279             case Core::Database::LEVEL_FILE:
00280                 mDocListeners[i]->HandleDoneFile();
00281                 break;
00282             }
00283         }
00284     }
00285 
00286     void
00287     AllHandleDoneVisit()
00288     {
00289         for (int i=0 ; i<mDocListeners.size() ; i++)
00290             mDocListeners[i]->HandleDoneVisit();
00291     }
00292 
00293     void
00294     AllHandleBookmarkEvent(int shotid, bool selected)
00295     {
00296         for (int i=0 ; i<mDocListeners.size() ; i++)
00297             mDocListeners[i]->HandleBookmarkEvent(shotid, selected);
00298     }
00299 
00300     void
00301     AllHandleNewBookmarked()
00302     {
00303         for (int i=0 ; i<mDocListeners.size() ; i++)
00304             mDocListeners[i]->HandleNewBookmarked();
00305     }
00306 
00307     void
00308     AllHandleAddedBookmark()
00309     {
00310         for (int i=0 ; i<mDocListeners.size() ; i++)
00311             mDocListeners[i]->HandleAddedBookmark();
00312     }
00313 
00314     void
00315     AllHandleRemovedBookmark()
00316     {
00317         for (int i=0 ; i<mDocListeners.size() ; i++)
00318             mDocListeners[i]->HandleRemovedBookmark();
00319     }
00320 
00321     void
00322     AllHandleCycleDoc()
00323     {
00324         for (int i=0 ; i<mDocListeners.size() ; i++)
00325             mDocListeners[i]->HandleCycleDoc();
00326     }
00327 protected:
00328     KeyBindingsMap                     mKeyBindings;
00329 
00330 // RvB: Commented next line, making the members protected
00331 //private:
00332 
00333     DataDocument*                      mDoc;
00334     std::vector<DataDocumentListener*> mDocListeners;
00335 
00336     Timer mTimer;
00337     bool  mDone;
00338     bool  mDoContinuous;
00339     int   mNrItemsDone;
00340 
00341     ILOG_VAR_DEC;
00342 };
00343 
00344 ILOG_VAR_INIT(AppControlDoc, Visualization);
00345 
00346 } // namespace Visualization
00347 } // namespace Impala
00348 
00349 #endif

Generated on Fri Mar 19 09:31:48 2010 for ImpalaSrc by  doxygen 1.5.1