Changeset 330 in Sophya for trunk/SophyaPI/PIext/piacmd.cc
- Timestamp:
- Jun 24, 1999, 4:26:47 PM (26 years ago)
- File:
-
- 1 edited
-
trunk/SophyaPI/PIext/piacmd.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/piacmd.cc
r324 r330 24 24 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd); 25 25 virtual ~PIAHelpWind(); 26 virtual void Show(); 26 27 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL); 28 inline void AddHelpGroup(const char * hgrp, int gid) 29 { hgrpom->AppendItem(hgrp, 20000+gid); } 30 inline void ClearHelpList() 31 { mNitem=0; hitemlist->DeleteAllItems(); } 27 32 inline void AddHelpItem(const char * hitem) 28 { mNitem++; hitemlist->AppendItem(hitem, 1000+mNitem); }33 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); } 29 34 protected : 30 35 PIStdImgApp* dap; … … 32 37 int mNitem; 33 38 PIList* hitemlist; 39 PIOptMenu* hgrpom; 34 40 PIButton * mBut; 35 41 PILabel * mLab; … … 44 50 piac = piacmd; 45 51 mNitem = 0; 46 SetMsg(77 7);52 SetMsg(77); 47 53 48 54 int bsx, bsy; … … 53 59 tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy; 54 60 SetSize(tsx,tsy); 55 hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-2*spy, spx/2, spy); 61 hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy); 62 hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 63 hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy); 56 64 hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 57 65 // hitemlist->SetBorderWidth(2); … … 65 73 mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 66 74 mLab->SetLabel(""); 67 mBut = new PIButton(this, "Close", 70 0, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);75 mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy); 68 76 mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic); 69 77 } … … 72 80 PIAHelpWind::~PIAHelpWind() 73 81 { 82 delete hgrpom; 74 83 delete hitemlist; 75 84 delete mTxt; … … 82 91 { 83 92 PIMessage um = UserMsg(msg); 84 if (((um == 77 7) && (ModMsg(msg) == PIMsg_Close)) || (um == 700) ) {93 if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) { 85 94 Hide(); 86 95 return; 87 96 } 88 else if ( (um > 1000) && (sender == hitemlist)) { 97 else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help 98 mTxt->SetText(""); 99 mLab->SetLabel(""); 100 piac->UpdateHelpList(this, um-20000); 101 } 102 else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) { 89 103 string s = hitemlist->GetSelectionStr(); 90 104 mTxt->SetText(piac->GetUsage(s)); … … 93 107 } 94 108 109 /* --Methode-- */ 110 void PIAHelpWind::Show() 111 { 112 hgrpom->SetValue(20000); // Groupe All 113 mTxt->SetText(""); 114 mLab->SetLabel(""); 115 piac->UpdateHelpList(this, 0); 116 PIWindow::Show(); 117 } 95 118 96 119 static PIACmd* curpiacmd = NULL; … … 105 128 gltimer = NULL; 106 129 130 cmdhgrp["All"] = 0; 131 cmdgrpid = 1; 132 cmdhgrp["Commands"] = 1; 107 133 helpwin = new PIAHelpWind(app, this); 134 helpwin->AddHelpGroup("All", 0); 135 helpwin->AddHelpGroup("Commands", 1); 108 136 109 137 string kw = "piacmd"; … … 120 148 usage += " > help <command_name> # <command_name> usage info \n"; 121 149 usage += " > helpwindow # Displays help window \n"; 122 RegisterCommand(kw, usage, NULL); 150 string grp = "Commands"; 151 RegisterHelp(kw, usage, grp); 123 152 124 153 basexec = new PIABaseExecutor(this, omg, app); … … 156 185 157 186 /* --Methode-- */ 158 void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce) 159 { 160 // if (!ce) return; 187 void PIACmd::RegisterCommand(string& keyw, string& usage, CmdExecutor * ce, string grp) 188 { 189 if (!ce) { 190 RegisterHelp(keyw, usage, grp); 191 return; 192 } 193 int gid = CheckHelpGrp(grp); 161 194 cmdex cme; 195 cme.group = gid; 162 196 cme.us = usage; 163 197 cme.cex = ce; 164 198 cmdexmap[keyw] = cme; 165 if (helpwin) helpwin->AddHelpItem(keyw.c_str()); 199 } 200 201 /* --Methode-- */ 202 void PIACmd::RegisterHelp(string& keyw, string& usage, string& grp) 203 { 204 int gid = CheckHelpGrp(grp); 205 cmdex cme; 206 cme.group = gid; 207 cme.us = usage; 208 cme.cex = NULL; 209 helpexmap[keyw] = cme; 210 } 211 212 /* --Methode-- */ 213 int PIACmd::CheckHelpGrp(string& grp) 214 { 215 int gid=0; 216 CmdHGroup::iterator it = cmdhgrp.find(grp); 217 if (it == cmdhgrp.end()) { 218 cmdgrpid++; gid = cmdgrpid; 219 cmdhgrp[grp] = gid; 220 helpwin->AddHelpGroup(grp.c_str(), gid); 221 } 222 else gid = (*it).second; 223 return(gid); 224 } 225 226 /* --Methode-- */ 227 void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid) 228 { 229 helpwin->ClearHelpList(); 230 CmdExmap::iterator it; 231 for(it = helpexmap.begin(); it != helpexmap.end(); it++) { 232 if ( (gid != 0) && ((*it).second.group != gid) ) continue; 233 helpwin->AddHelpItem((*it).first.c_str()); 234 } 235 for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) { 236 if ( (gid != 0) && ((*it).second.group != gid) ) continue; 237 helpwin->AddHelpItem((*it).first.c_str()); 238 } 166 239 } 167 240 … … 252 325 if (kw == "helpwindow") ShowHelpWindow(); 253 326 else if (kw == "help") { 254 if (tokens.size() > 0) {255 CmdExmap::iterator it = cmdexmap.find(tokens[0]);256 if (it == cmdexmap.end()) cout << "Nothing known about " << tokens[0] << " ?? " << endl;257 else cout << (*it).second.us<< endl;327 if (tokens.size() > 0) cout << GetUsage(tokens[0]) << endl; 328 else { 329 string kwh = "piacmd"; 330 cout << GetUsage(kwh) << endl; 258 331 } 259 else { 260 cout << "\n -------- PIACmd::Interpret() ::::: Help ------------ \n"; 261 cout << ">>> Interpreter's keywords : \n"; 262 cout << " timingon timingoff traceon traceoff \n"; 263 cout << " set unset listvar listcommands exec shell \n"; 264 cout << " > set varname 'string' # To set a variable, $varname \n"; 265 cout << " > unset varname # clear variable definition \n"; 266 cout << " > listvars # List of variable names and values \n"; 267 cout << " > listcommands # List of all known commands \n"; 268 cout << " > exec filename # Execute commands from file \n"; 269 cout << " > shell comand_string # Execute shell command \n"; 270 cout << " > help <command_name> # <command_name> usage info \n"; 271 cout << " > helpwindow # Displays help window \n" << endl; 272 } 273 } 274 332 } 275 333 276 334 else if (kw == "set") { … … 292 350 } 293 351 else if (kw == "listvars") { 294 cout << "---- PIACmd::Interpret() Command keywordList ----- \n";352 cout << "---- PIACmd::Interpret() Command Variable List ----- \n"; 295 353 CmdExmap::iterator it; 296 354 int kc = 0; … … 376 434 string& PIACmd::GetUsage(const string& kw) 377 435 { 436 bool fndok = false; 378 437 CmdExmap::iterator it = cmdexmap.find(kw); 379 if (it == cmdexmap.end()) { 380 if (videstr == NULL) videstr = new string(""); 381 return(*videstr); 382 } 383 else return( (*it).second.us ); 438 if (it == cmdexmap.end()) { 439 it = helpexmap.find(kw); 440 if (it != helpexmap.end()) fndok = true; 441 } 442 else fndok = true; 443 if (fndok) return( (*it).second.us ); 444 // Keyword pas trouve 445 if (videstr == NULL) videstr = new string(""); 446 *videstr = "Nothing known about " + kw + " ?? "; 447 return(*videstr); 448 384 449 } 385 450
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/PI/chrome/site/your_project_logo.png)