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 // uMS.cpp : Defines the entry point for the console application. 00031 00032 // Paul Newman 2005 00033 00034 00035 00036 00037 00038 #include "ScopeGrid.h" 00039 #include <FL/Fl_Double_Window.H> 00040 #include <FL/fl_draw.H> 00041 #include <FL/Fl_Browser.H> 00042 #include <FL/Fl_Tabs.H> 00043 #include <FL/Fl_Browser.H> 00044 #include <FL/fl_ask.H> 00045 #include <FL/Fl_Window.H> 00046 #include <FL/fl_draw.H> 00047 #include <FL/Fl_Preferences.H> 00048 #include <sstream> 00049 #include "ScopeTabPane.h" 00050 #include <FLTKVW/Flv_Table.H> 00051 00052 #define DEFAULT_HEIGHT 460 00053 #define DEFAULT_WIDTH 820 00054 00055 00056 //called to produce a new pane 00057 Fl_Group * MakeCommunityPane(int x ,int y, int w, int h,const std::string & Name) 00058 { 00059 char* nName = new char[Name.size()+1]; 00060 strcpy(nName,Name.c_str()); 00061 Fl_Group *pG = new CScopeTabPane(x,y,w,h,nName); 00062 return pG; 00063 } 00064 00065 //callback for save 00066 void OnSave(Fl_Widget* pWidget,void * pParam) 00067 { 00068 Fl_Tabs* pTab = (Fl_Tabs*)(pParam); 00069 std::ostringstream os; 00070 for(int i = 0;i<pTab->children();i++) 00071 { 00072 CScopeTabPane * pTabPane = (CScopeTabPane*)(pTab->child(i)); 00073 std::string sHost; 00074 int nPort; 00075 pTabPane->GetMOOSInfo(sHost,nPort); 00076 os<<pTabPane->label()<<":"<<nPort<<"@"<<sHost<<","; 00077 } 00078 00079 //here we try to load previous preferences 00080 Fl_Preferences app( Fl_Preferences::USER, "MOOS", "uMS" ); 00081 app.set("Communities",os.str().c_str()); 00082 } 00083 00084 //callback for delete 00085 void OnRemoveCommunity(Fl_Widget* pWidget,void * pParam) 00086 { 00087 Fl_Tabs* pTab = (Fl_Tabs*)(pParam); 00088 00089 if(pTab->children()>1) 00090 { 00091 if(fl_choice("Really delete Scope of \"%s\" ?", "No", "Yes", NULL, pTab->value()->label())) 00092 { 00093 Fl_Group* pG = (Fl_Group*)pTab->value(); 00094 pG->clear(); 00095 pTab->remove(pG); 00096 pTab->value(pTab->child(0)); 00097 delete pG; 00098 } 00099 } 00100 } 00101 00102 00103 00104 void OnRenameCommunity(Fl_Widget* pWidget,void * pParam) 00105 { 00106 Fl_Tabs* pTab = (Fl_Tabs*)(pParam); 00107 const char * scName=fl_input("Enter a new name", ""); 00108 if(scName==NULL) 00109 return ; 00110 00111 char * sName = new char[strlen(scName)*2]; 00112 strcpy(sName,scName); 00113 Fl_Widget* pW = (Fl_Widget*)pTab->value(); 00114 00115 pW->label(scName); 00116 } 00117 00118 00119 //callback for add Community 00120 void OnAddCommunity(Fl_Widget* pWidget,void * pParam) 00121 { 00122 const char * scName=fl_input("New Community Name", ""); 00123 if(scName==NULL) 00124 return ; 00125 00126 char * sName = new char[strlen(scName)*2]; 00127 strcpy(sName,scName); 00128 00129 Fl_Tabs* pTab = (Fl_Tabs*)(pParam); 00130 Fl_Group* pG = (Fl_Group*)pTab->value(); 00131 00132 pTab->begin(); 00133 MakeCommunityPane(10,30,pG->w()-20,pG->h()-10,sName); 00134 pTab->end(); 00135 00136 } 00137 00138 //heres the money..... 00139 int main(int argc, char* argv[]) 00140 { 00141 00142 //make the frame 00143 Fl_Double_Window *w = new Fl_Double_Window( 820, 460, "uMS" ); 00144 w->size_range(DEFAULT_WIDTH,DEFAULT_HEIGHT); 00145 00146 //OK - lets build a whole set of panes 00147 std::string sWho; 00148 { 00149 //note scoping 00150 Fl_Preferences app( Fl_Preferences::USER, "MOOS", "uMS" ); 00151 char Space[2048]; 00152 app.get("Communities",Space,"Unnamed:9000@LOCALHOST",sizeof(Space)); 00153 sWho = std::string(Space); 00154 } 00155 00156 Fl_Tabs* pTab = new Fl_Tabs(10, 10, 800, 400); 00157 00158 while(!sWho.empty()) 00159 { 00160 std::string sChunk = MOOSChomp(sWho,","); 00161 std::string sName = MOOSChomp(sChunk,":"); 00162 int nPort = atoi(MOOSChomp(sChunk,"@").c_str()); 00163 std::string sHost = sChunk; 00164 if(!sChunk.empty() && nPort>0) 00165 { 00166 Fl_Group *pG = MakeCommunityPane(10,30,800,390,(char*)sName.c_str()); 00167 CScopeTabPane * pTabPane = (CScopeTabPane*)(pG); 00168 pTabPane->SetMOOSInfo(sHost,nPort); 00169 Fl_Group::current()->resizable(pG); 00170 } 00171 } 00172 if(pTab->children()==0) 00173 { 00174 Fl_Group *pG = MakeCommunityPane(10,30,800,390,"Unnamed"); 00175 } 00176 00177 w->end(); 00178 00179 00180 //and add some buttons to control them.... 00181 w->begin(); 00182 { 00183 //add 00184 Fl_Button * pNewCommunityButton = new Fl_Button(10,420,160,30,"Add Community"); 00185 pNewCommunityButton->callback(OnAddCommunity,pTab); 00186 00187 //delete 00188 Fl_Button * pDelCommunityButton = new Fl_Button(180,420,160,30,"Remove Community"); 00189 pDelCommunityButton->callback(OnRemoveCommunity,pTab); 00190 00191 //save 00192 Fl_Button * pSaveButton = new Fl_Button(350,420,160,30,"Save Layout"); 00193 pSaveButton->callback(OnSave,pTab); 00194 pSaveButton->callback(); 00195 00196 //rename 00197 Fl_Button * pRenameButton = new Fl_Button(520,420,160,30,"Rename"); 00198 pRenameButton->callback(OnRenameCommunity,pTab); 00199 pRenameButton->callback(); 00200 00201 } 00202 w->end(); 00203 00204 00205 //need to do more work on resizing - maybe even read the manual 00206 w->resizable(pTab); 00207 00208 00209 //and GO! 00210 w->show(argc, argv); 00211 return Fl::run(); 00212 00213 } 00214