MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Utility Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00030 // ScopeTabPane.cpp: implementation of the CScopeTabPane class. 00031 00032 00033 // 00034 00035 00037 00038 00039 #ifdef _WIN32 00040 #pragma warning(disable : 4786) 00041 #endif 00042 00043 #include <FL/Fl_Group.H> 00044 #include <FL/Fl_Browser.H> 00045 #include <FL/Fl_Hold_Browser.H> 00046 #include <FL/Fl_Button.H> 00047 #include <FL/Fl_Light_Button.H> 00048 #include <string> 00049 #include "ScopeTabPane.h" 00050 #include <FL/Fl_Tabs.H> 00051 #include <MOOSGenLib/MOOSGenLibGlobalHelper.h> 00052 00053 #define FONT_SIZE 11 00054 00056 // Construction/Destruction 00058 CScopeTabPane::~CScopeTabPane() 00059 { 00060 StopTimer(); 00061 } 00062 00063 00064 CScopeTabPane::CScopeTabPane( int X, int Y, int W, int H, char *l ) :BASE(X,Y,W,H,l) 00065 { 00066 m_FetchThread.Initialise(FetchWorker,this); 00067 m_FetchThread.Start(); 00068 00069 label(l); 00070 m_sHost = "LOCALHOST"; 00071 m_lPort = 9000; 00072 00073 00074 00075 m_nCounts=0; 00076 00077 00078 int LHS = X+10; 00079 int TOP = Y+10; 00080 int RHS = X+W-10; 00081 int BOTTOM = Y+H; 00082 int GRID_H = (2*H)/3; 00083 int BOTTOM_GRID = TOP+GRID_H; 00084 int PROC_W = int(0.22*W); 00085 int PROC_H = H-BOTTOM_GRID-10; 00086 00087 00088 m_pScopeGrid = new CScopeGrid( LHS, TOP, W-20,GRID_H, "DB" ); 00089 m_pScopeGrid->SetDBImage(&m_DBImage); 00090 m_pScopeGrid->SetComms(&m_Comms); 00091 00092 00093 Fl_Group *pC = new Fl_Group(X,BOTTOM_GRID,W,H-GRID_H); 00094 00095 { 00096 00097 00098 00099 //the process list 00100 m_pProcessList = new Fl_Check_Browser( LHS,BOTTOM_GRID+10,PROC_W,PROC_H,"Processes"); 00101 SetID(m_pProcessList,ID_PROCESS); 00102 m_pProcessList->tooltip("Click a process name to examine subscriptions and publications"); 00103 m_pProcessList->textsize(FONT_SIZE); 00104 m_pProcessList->when(FL_WHEN_RELEASE); 00105 00106 //the subscriber list 00107 m_pSubscribeList = new Fl_Browser( m_pProcessList->x()+PROC_W+30,BOTTOM_GRID+10,PROC_W,PROC_H,"Subscribes"); 00108 m_pSubscribeList->textsize(FONT_SIZE); 00109 00110 //the publish list 00111 m_pPublishList = new Fl_Browser( m_pSubscribeList->x()+PROC_W+5,BOTTOM_GRID+10,PROC_W,PROC_H,"Publishes"); 00112 m_pPublishList->textsize(FONT_SIZE); 00113 00114 00115 Fl_Button* pLB = new Fl_Button(m_pPublishList->x()+PROC_W+5,m_pPublishList->y(),15,20,"?"); 00116 pLB->type(FL_TOGGLE_BUTTON); 00117 pLB->tooltip("show ? (pending) DB entries"); 00118 SetID(pLB,ID_SHOW_PENDING); 00119 00120 00121 Fl_Group *pMOOSParams = new Fl_Group(RHS-180,BOTTOM_GRID+10,180,100); 00122 { 00123 //MOOS parameters - HOST 00124 00125 m_pDBHostInput = new Fl_Input( RHS-180, 00126 BOTTOM_GRID+10, 00127 100,25,"HostName"); 00128 00129 00130 m_pDBHostInput->align(FL_ALIGN_RIGHT ); 00131 m_pDBHostInput->textsize(FONT_SIZE); 00132 m_pDBHostInput->tooltip("name or IP address of machine hosting DB"); 00133 00134 00135 //MOOS parameters - Port 00136 m_pDBPortInput = new Fl_Int_Input( m_pDBHostInput->x(), 00137 m_pDBHostInput->y()+m_pDBHostInput->h()+5, 00138 100,25,"Port"); 00139 00140 00141 m_pDBPortInput->align(FL_ALIGN_RIGHT ); 00142 m_pDBPortInput->textsize(FONT_SIZE); 00143 m_pDBPortInput->tooltip("Port Number MOOSDB is listening on"); 00144 00145 00146 00147 m_pConnectButton= new Fl_Button( m_pDBPortInput->x(), 00148 m_pDBPortInput->y()+m_pDBPortInput->h()+5, 00149 160,25,"Connect"); 00150 00151 00152 SetID(m_pConnectButton,ID_CONNECT); 00153 m_pConnectButton->tooltip("Connect to a MOOSDB"); 00154 00155 //set up MOOS values 00156 m_pDBHostInput->value(m_sHost.c_str()); 00157 m_pDBPortInput->value(MOOSFormat("%ld",m_lPort).c_str()); 00158 00159 } 00160 00161 pMOOSParams->resizable(0); 00162 } 00163 00164 00165 pC->resizable(this); 00166 end(); 00167 00168 //make things initially grey... 00169 m_pScopeGrid->deactivate(); 00170 m_pSubscribeList->deactivate(); 00171 m_pPublishList->deactivate(); 00172 m_pProcessList->deactivate(); 00173 StartTimer(0.5); 00174 00175 }; 00176 00177 void CScopeTabPane::SetMask() 00178 { 00179 std::map<std::string,ProcessOptions>::iterator p; 00180 std::set<std::string> Mask; 00181 for(p = m_ProcessOptions.begin();p!=m_ProcessOptions.end();p++) 00182 { 00183 if(!p->second.m_bShow) 00184 Mask.insert(p->first); 00185 } 00186 00187 m_DBImage.Clear(); 00188 m_DBImage.SetMask(Mask); 00189 } 00190 00191 00192 std::string CScopeTabPane::GetFocusProcess() 00193 { 00194 const char * pStr = m_pProcessList->text(m_pProcessList->value()); 00195 if(pStr==NULL) 00196 return ""; 00197 return std::string(pStr); 00198 } 00199 00200 00201 void CScopeTabPane::OnControlWidget(Fl_Widget* pWidget,int ID) 00202 { 00203 //this is the switch yard for all messages 00204 switch(ID) 00205 { 00206 case ID_PROCESS: 00207 { 00208 if(Fl::event_shift()) 00209 { 00210 //toggling visibility masks... 00211 std::string sFocus = GetFocusProcess(); 00212 00213 if(m_ProcessOptions.find(sFocus)!=m_ProcessOptions.end()) 00214 { 00215 ProcessOptions & rOptions = m_ProcessOptions[sFocus]; 00216 rOptions.m_bShow = !rOptions.m_bShow; 00217 } 00218 00219 m_pProcessList->checked(m_pProcessList->value(),m_ProcessOptions[GetFocusProcess()].m_bShow); 00220 00221 SetMask(); 00222 00223 } 00224 else 00225 { 00226 //changing what appear isn teh subscribed/published box 00227 std::string sFocus= GetFocusProcess(); 00228 00229 STRING_LIST sSubs,sPubs; 00230 if(m_DBImage.GetProcInfo(sFocus,sSubs,sPubs)) 00231 { 00232 m_pSubscribeList->clear(); 00233 m_pPublishList->clear(); 00234 STRING_LIST::iterator p; 00235 for(p = sSubs.begin();p!=sSubs.end();p++) 00236 { 00237 m_pSubscribeList->add(p->c_str()); 00238 } 00239 for(p = sPubs.begin();p!=sPubs.end();p++) 00240 { 00241 m_pPublishList->add(p->c_str()); 00242 } 00243 static char sPubTxt[1024]; 00244 sprintf(sPubTxt,"%s Publishes",sFocus.c_str()); 00245 static char sSubTxt[1024]; 00246 sprintf(sSubTxt,"%s Subscribes",sFocus.c_str()); 00247 00248 } 00249 m_pProcessList->checked(m_pProcessList->value(),m_ProcessOptions[GetFocusProcess()].m_bShow); 00250 } 00251 } 00252 00253 break; 00254 case ID_CONNECT: 00255 { 00256 std::string sMOOSName = "uMS["+m_Comms.GetLocalIPAddress()+"]"; 00257 m_sHost = std::string(m_pDBHostInput->value()); 00258 m_lPort = atoi(m_pDBPortInput->value()); 00259 //set up callbacks 00260 m_Comms.SetOnConnectCallBack(MOOSConnectCallback,this); 00261 m_Comms.SetOnDisconnectCallBack(MOOSDisconnectCallback,this); 00262 00263 //go! 00264 if(!m_Comms.Run(m_sHost.c_str(),m_lPort,sMOOSName.c_str())) 00265 { 00266 } 00267 } 00268 break; 00269 00270 case ID_SHOW_PENDING: 00271 { 00272 Fl_Button* pB = (Fl_Button*)GetByID(ID_SHOW_PENDING); 00273 m_DBImage.Clear(); 00274 SetMask(); 00275 m_DBImage.ShowPending(pB->value()!=0); 00276 } 00277 break; 00278 00279 } 00280 00281 } 00282 00283 00284 bool CScopeTabPane::MOOSConnectCallback(void * pParam) 00285 { 00286 if(pParam) 00287 { 00288 return ((CScopeTabPane*)pParam)->OnMOOSConnect(); 00289 } 00290 return false; 00291 } 00292 00293 bool CScopeTabPane::MOOSDisconnectCallback(void * pParam) 00294 { 00295 if(pParam) 00296 { 00297 return ((CScopeTabPane*)pParam)->OnMOOSDisconnect(); 00298 } 00299 return false; 00300 } 00301 00302 00303 bool CScopeTabPane::OnMOOSConnect() 00304 { 00305 m_pScopeGrid->activate(); 00306 m_pProcessList->activate(); 00307 m_pSubscribeList->activate(); 00308 m_pPublishList->activate(); 00309 00310 m_pConnectButton->deactivate(); 00311 m_pDBPortInput->deactivate(); 00312 m_pDBHostInput->deactivate(); 00313 00314 return true; 00315 } 00316 00317 00318 bool CScopeTabPane::OnMOOSDisconnect() 00319 { 00320 00321 m_pScopeGrid->deactivate(); 00322 m_pProcessList->deactivate(); 00323 m_pSubscribeList->deactivate(); 00324 00325 m_pPublishList->deactivate(); 00326 00327 m_pConnectButton->activate(); 00328 m_pDBPortInput->activate(); 00329 m_pDBHostInput->activate(); 00330 00331 return true; 00332 00333 } 00334 00335 bool CScopeTabPane::FetchLoop() 00336 { 00337 while(!m_FetchThread.IsQuitRequested()) 00338 { 00339 if(m_Comms.IsConnected()) 00340 { 00341 if(m_nCounts++%5==0) 00342 { 00343 if(!GetDBProcSummary()) 00344 { 00345 } 00346 } 00347 if(!GetDBSummary()) 00348 { 00349 } 00350 } 00351 //basic 4Hz Tick - 00352 MOOSPause(250); 00353 } 00354 00355 return true; 00356 00357 } 00358 00359 00360 00361 00362 void CScopeTabPane::OnTimer() 00363 { 00364 Fl_Widget* pActive = ((Fl_Tabs*)parent())->value(); 00365 if(pActive==this) 00366 { 00367 m_pScopeGrid->redraw(); 00368 00369 //we'll update the process list much slower... 00370 if(m_nCounts%5==0) 00371 { 00372 STRING_LIST sProcs; 00373 if(m_DBImage.GetProcesses(sProcs)) 00374 { 00375 const char * pStr = m_pProcessList->text(m_pProcessList->value()); 00376 00377 std::string sSel = pStr==NULL ? "": std::string(pStr); 00378 00379 m_pProcessList->clear(); 00380 int nSel = -1; 00381 STRING_LIST::iterator q; 00382 for(q = sProcs.begin();q!=sProcs.end();q++) 00383 { 00384 ProcessOptions & rOptions = m_ProcessOptions[q->c_str()]; 00385 00386 m_pProcessList->add(q->c_str()); 00387 nSel= m_pProcessList->nitems(); 00388 00389 m_pProcessList->checked(nSel,rOptions.m_bShow); 00390 00391 } 00392 } 00393 m_pScopeGrid->SetTitle(MOOSFormat("%d Processes %d Variables",sProcs.size(), 00394 m_DBImage.GetNumVariables()).c_str()); 00395 } 00396 } 00397 } 00398 00399 00400 bool CScopeTabPane::GetDBSummary() 00401 { 00402 if(!m_Comms.IsConnected()) 00403 { 00404 return true; 00405 } 00406 else 00407 { 00408 MOOSMSG_LIST InMail; 00409 if(m_Comms.ServerRequest("ALL",InMail)) 00410 { 00411 return m_DBImage.Set(InMail); 00412 } 00413 } 00414 return false; 00415 } 00416 00417 bool CScopeTabPane::GetDBProcSummary() 00418 { 00419 MOOSMSG_LIST InMail; 00420 if(!m_Comms.IsConnected()) 00421 { 00422 return true; 00423 } 00424 else 00425 { 00426 if(m_Comms.ServerRequest("PROC_SUMMARY",InMail)) 00427 { 00428 if(m_DBImage.SetProcInfo(InMail)) 00429 { 00430 } 00431 } 00432 } 00433 00434 return false; 00435 } 00436 00437