[293] | 1 | #include "piacmd.h"
|
---|
[165] | 2 | #include <stdio.h>
|
---|
| 3 | #include <stdlib.h>
|
---|
[349] | 4 | #include <ctype.h>
|
---|
[165] | 5 | #include <math.h>
|
---|
| 6 |
|
---|
[293] | 7 | #include "basexecut.h"
|
---|
[165] | 8 |
|
---|
[293] | 9 | #include "pdlmgr.h"
|
---|
[165] | 10 | #include "ctimer.h"
|
---|
[2214] | 11 | #include "strutil.h"
|
---|
[2215] | 12 | #include "strutilxx.h"
|
---|
[293] | 13 | // #include "dlftypes.h"
|
---|
[2307] | 14 | #ifdef SANS_EVOLPLANCK
|
---|
[2308] | 15 | #include "nbrandom.h"
|
---|
[2307] | 16 | #else
|
---|
| 17 | #include "srandgen.h"
|
---|
| 18 | #endif
|
---|
[165] | 19 |
|
---|
[293] | 20 | #include "pistdimgapp.h"
|
---|
[165] | 21 | #include "nobjmgr.h"
|
---|
[361] | 22 | #include "piafitting.h"
|
---|
[463] | 23 | #include "pawexecut.h"
|
---|
[1224] | 24 | #include "cxxexecutor.h"
|
---|
[1251] | 25 | #include "cxxexecwin.h"
|
---|
[1828] | 26 | #include "contmodex.h"
|
---|
[1920] | 27 | #include "flowmodex.h"
|
---|
[165] | 28 |
|
---|
[293] | 29 | #include PISTDWDG_H
|
---|
| 30 | #include PILIST_H
|
---|
[165] | 31 |
|
---|
[293] | 32 | // ------------------------------------------------------------
|
---|
[349] | 33 | // Gestion d'une fenetre d'aide interactive
|
---|
| 34 | // Classe PIAHelpWind
|
---|
[293] | 35 | // ------------------------------------------------------------
|
---|
[165] | 36 |
|
---|
[293] | 37 | class PIAHelpWind : public PIWindow {
|
---|
| 38 | public :
|
---|
| 39 | PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
|
---|
| 40 | virtual ~PIAHelpWind();
|
---|
[330] | 41 | virtual void Show();
|
---|
[293] | 42 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
[330] | 43 | inline void AddHelpGroup(const char * hgrp, int gid)
|
---|
| 44 | { hgrpom->AppendItem(hgrp, 20000+gid); }
|
---|
[2465] | 45 | inline void AddHelpGroup(string const & hgrp, int gid)
|
---|
| 46 | { hgrpom->AppendItem(hgrp.c_str(), 20000+gid); }
|
---|
[330] | 47 | inline void ClearHelpList()
|
---|
| 48 | { mNitem=0; hitemlist->DeleteAllItems(); }
|
---|
[293] | 49 | inline void AddHelpItem(const char * hitem)
|
---|
[330] | 50 | { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
|
---|
[2465] | 51 | inline void SetHelpTextLabel(string const & htxt, string const & hlab)
|
---|
| 52 | { mTxt->SetText(htxt); mLab->SetLabel(hlab); }
|
---|
| 53 |
|
---|
[293] | 54 | protected :
|
---|
| 55 | PIStdImgApp* dap;
|
---|
| 56 | PIACmd* piac;
|
---|
| 57 | int mNitem;
|
---|
| 58 | PIList* hitemlist;
|
---|
[330] | 59 | PIOptMenu* hgrpom;
|
---|
[293] | 60 | PIButton * mBut;
|
---|
| 61 | PILabel * mLab;
|
---|
| 62 | PIText* mTxt;
|
---|
| 63 | };
|
---|
[165] | 64 |
|
---|
[293] | 65 | /* --Methode-- */
|
---|
| 66 | PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
|
---|
| 67 | : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
|
---|
| 68 | {
|
---|
| 69 | dap = par;
|
---|
| 70 | piac = piacmd;
|
---|
| 71 | mNitem = 0;
|
---|
[330] | 72 | SetMsg(77);
|
---|
[165] | 73 |
|
---|
[293] | 74 | int bsx, bsy;
|
---|
| 75 | int tsx, tsy;
|
---|
| 76 | int spx, spy;
|
---|
| 77 | PIApplicationPrefCompSize(bsx, bsy);
|
---|
| 78 | spx = bsx/6; spy = bsy/6;
|
---|
| 79 | tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
|
---|
| 80 | SetSize(tsx,tsy);
|
---|
[330] | 81 | hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
|
---|
| 82 | hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 83 | hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
|
---|
[293] | 84 | hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 85 | // hitemlist->SetBorderWidth(2);
|
---|
[324] | 86 | mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
|
---|
| 87 | // mTxt->SetMutiLineMode(true);
|
---|
[293] | 88 | mTxt->SetTextEditable(false);
|
---|
| 89 | mTxt->SetText("");
|
---|
| 90 | mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 91 | mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
|
---|
| 92 | mLab->SetBorderWidth(1);
|
---|
| 93 | mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 94 | mLab->SetLabel("");
|
---|
[330] | 95 | mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
|
---|
[293] | 96 | mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
| 97 | }
|
---|
[165] | 98 |
|
---|
| 99 | /* --Methode-- */
|
---|
[293] | 100 | PIAHelpWind::~PIAHelpWind()
|
---|
| 101 | {
|
---|
[330] | 102 | delete hgrpom;
|
---|
[293] | 103 | delete hitemlist;
|
---|
| 104 | delete mTxt;
|
---|
| 105 | delete mLab;
|
---|
| 106 | delete mBut;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /* --Methode-- */
|
---|
| 110 | void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
|
---|
| 111 | {
|
---|
| 112 | PIMessage um = UserMsg(msg);
|
---|
[330] | 113 | if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
|
---|
[293] | 114 | Hide();
|
---|
| 115 | return;
|
---|
| 116 | }
|
---|
[330] | 117 | else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
|
---|
| 118 | mTxt->SetText("");
|
---|
| 119 | mLab->SetLabel("");
|
---|
| 120 | piac->UpdateHelpList(this, um-20000);
|
---|
| 121 | }
|
---|
| 122 | else if ( (um > 100) && (sender == hitemlist) && (ModMsg(msg) == PIMsg_Select) ) {
|
---|
[293] | 123 | string s = hitemlist->GetSelectionStr();
|
---|
| 124 | mTxt->SetText(piac->GetUsage(s));
|
---|
| 125 | mLab->SetLabel(s);
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[330] | 129 | /* --Methode-- */
|
---|
| 130 | void PIAHelpWind::Show()
|
---|
| 131 | {
|
---|
| 132 | hgrpom->SetValue(20000); // Groupe All
|
---|
| 133 | mTxt->SetText("");
|
---|
| 134 | mLab->SetLabel("");
|
---|
| 135 | piac->UpdateHelpList(this, 0);
|
---|
| 136 | PIWindow::Show();
|
---|
| 137 | }
|
---|
[293] | 138 |
|
---|
[349] | 139 |
|
---|
| 140 | // ------------------------------------------------------------
|
---|
| 141 | // Classe PIACmd
|
---|
| 142 | // ------------------------------------------------------------
|
---|
| 143 |
|
---|
[2463] | 144 | // static PIACmd* curpiacmd = NULL;
|
---|
[293] | 145 | /* --Methode-- */
|
---|
[165] | 146 | PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
|
---|
[2463] | 147 | : Commander()
|
---|
[165] | 148 | {
|
---|
[293] | 149 | mObjMgr = omg;
|
---|
[165] | 150 | mImgApp = app;
|
---|
[293] | 151 | helpwin = new PIAHelpWind(app, this);
|
---|
[2465] | 152 | helpwin_initdone = false;
|
---|
[293] | 153 |
|
---|
[2463] | 154 | string kw = "exitpiapp";
|
---|
[2305] | 155 | string grp = "PIACmd";
|
---|
[2465] | 156 | string gdesc = "piapp interpreter (class PIACmd) additional builtin commands";
|
---|
| 157 | AddHelpGroup(grp, gdesc);
|
---|
| 158 |
|
---|
[2463] | 159 | string usage = "To end the piapp session ";
|
---|
[2419] | 160 | RegisterCommand(kw, usage, NULL, grp);
|
---|
[2463] | 161 | kw = "helpwindow";
|
---|
| 162 | usage = "To display the Help window ";
|
---|
[2419] | 163 | RegisterCommand(kw, usage, NULL, grp);
|
---|
[2203] | 164 |
|
---|
[293] | 165 | basexec = new PIABaseExecutor(this, omg, app);
|
---|
[361] | 166 | fitexec = new PIAFitter(this, app);
|
---|
[463] | 167 | pawexec = new PAWExecutor(this, app);
|
---|
[1251] | 168 | CxxExecutor * cxxe = new CxxExecutor(this, app);
|
---|
| 169 | cxxexec = cxxe;
|
---|
[1828] | 170 |
|
---|
| 171 | ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
|
---|
| 172 | cntexec = cntxx; //_OP_
|
---|
[1920] | 173 | FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
|
---|
| 174 | flwexec = flwxx; //_OP_
|
---|
[1828] | 175 |
|
---|
[1251] | 176 | cxxoptwin = new CxxOptionWind(app, cxxe);
|
---|
| 177 | cxxexwin = new CxxExecWind(app, cxxe);
|
---|
| 178 |
|
---|
[2465] | 179 | InitializeHelpWindowMenu();
|
---|
[165] | 180 | }
|
---|
| 181 |
|
---|
| 182 | /* --Methode-- */
|
---|
| 183 | PIACmd::~PIACmd()
|
---|
| 184 | {
|
---|
[2236] | 185 |
|
---|
[293] | 186 | delete helpwin;
|
---|
[1251] | 187 | delete cxxexwin;
|
---|
| 188 | delete cxxoptwin;
|
---|
[361] | 189 | delete basexec;
|
---|
| 190 | delete fitexec;
|
---|
[463] | 191 | delete pawexec;
|
---|
[1224] | 192 | delete cxxexec;
|
---|
[165] | 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
[293] | 196 | /* --Methode-- */
|
---|
[2465] | 197 | bool PIACmd::CheckHelpGrp(string& grp, int& gid, string& desc)
|
---|
[330] | 198 | {
|
---|
[2465] | 199 | bool fgnewgrp = Commander::CheckHelpGrp(grp, gid, desc);
|
---|
| 200 | if (helpwin_initdone && fgnewgrp) helpwin->AddHelpGroup(grp.c_str(), gid);
|
---|
| 201 | return fgnewgrp;
|
---|
[330] | 202 | }
|
---|
| 203 |
|
---|
| 204 | /* --Methode-- */
|
---|
| 205 | void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
|
---|
| 206 | {
|
---|
| 207 | helpwin->ClearHelpList();
|
---|
[2465] | 208 | if (gid == 0) {
|
---|
| 209 | string htxt = "All registered commands";
|
---|
| 210 | string hlab = "All (HelpGroup)";
|
---|
| 211 | helpwin->SetHelpTextLabel(htxt, hlab);
|
---|
| 212 | }
|
---|
| 213 | else {
|
---|
| 214 | CmdHGroup::iterator ith;
|
---|
| 215 | for(ith = cmdhgrp.begin(); ith != cmdhgrp.end(); ith++) {
|
---|
| 216 | if ((*ith).second.gid == gid) {
|
---|
| 217 | string hlab = (*ith).first;
|
---|
| 218 | hlab += " (HelpGroup)";
|
---|
| 219 | helpwin->SetHelpTextLabel((*ith).second.desc, hlab);
|
---|
| 220 | break;
|
---|
| 221 | }
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
[330] | 224 | CmdExmap::iterator it;
|
---|
| 225 | for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
|
---|
| 226 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 227 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 228 | }
|
---|
| 229 | for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
|
---|
| 230 | if ( (gid != 0) && ((*it).second.group != gid) ) continue;
|
---|
| 231 | helpwin->AddHelpItem((*it).first.c_str());
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[2465] | 235 | /* --Methode-- */
|
---|
| 236 | void PIACmd::InitializeHelpWindowMenu()
|
---|
| 237 | {
|
---|
| 238 | helpwin->AddHelpGroup("All", 0);
|
---|
| 239 | CmdHGroup::iterator it;
|
---|
| 240 | for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++)
|
---|
| 241 | helpwin->AddHelpGroup((*it).first, (*it).second.gid);
|
---|
| 242 | helpwin_initdone = true;
|
---|
| 243 | }
|
---|
[165] | 244 |
|
---|
[357] | 245 | /* Fonction */
|
---|
[368] | 246 | static string GetStringFrStdin(PIACmd* piac)
|
---|
[357] | 247 | {
|
---|
[368] | 248 | PIStdImgApp* piapp = piac->GetImgApp();
|
---|
| 249 | if (piapp) {
|
---|
| 250 | PIBaseWdg* wdg = piapp->CurrentBaseWdg();
|
---|
| 251 | if (wdg) wdg->Refresh();
|
---|
[357] | 252 | #ifndef __mac__
|
---|
[368] | 253 | /* On vide le buffer X-Window */
|
---|
[374] | 254 | XSync(PIXDisplay(),False);
|
---|
[357] | 255 | #endif
|
---|
[368] | 256 | }
|
---|
[357] | 257 | char buff[128];
|
---|
| 258 | fgets(buff, 128, stdin);
|
---|
| 259 | buff[127] = '\0';
|
---|
| 260 | return((string)buff);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[165] | 263 |
|
---|
[1262] | 264 | /* --Methode-- */
|
---|
| 265 | int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
|
---|
| 266 | {
|
---|
| 267 | int rc = 0;
|
---|
| 268 | NamedObjMgr omg;
|
---|
[349] | 269 |
|
---|
[165] | 270 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
[2465] | 271 | if (kw == "helpwindow") {
|
---|
| 272 | ShowHelpWindow();
|
---|
| 273 | return 0;
|
---|
| 274 | }
|
---|
[2307] | 275 | // ----> Sortie d'application
|
---|
| 276 | else if (kw == "exitpiapp") {
|
---|
| 277 | mImgApp->Stop();
|
---|
[2465] | 278 | return 0;
|
---|
[2307] | 279 | }
|
---|
[2463] | 280 | else return Commander::ExecuteCommandLine(kw, tokens, toks);
|
---|
[2465] | 281 | return 0;
|
---|
[165] | 282 | }
|
---|
| 283 |
|
---|
[333] | 284 |
|
---|
[165] | 285 | /* --Methode-- */
|
---|
[293] | 286 | void PIACmd::ShowHelpWindow()
|
---|
[165] | 287 | {
|
---|
[293] | 288 | helpwin->Show();
|
---|
[165] | 289 | }
|
---|
[357] | 290 |
|
---|
[463] | 291 | /* --Methode-- */
|
---|
[1251] | 292 | void PIACmd::ShowCxxOptionWindow()
|
---|
| 293 | {
|
---|
| 294 | cxxoptwin->Show();
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | /* --Methode-- */
|
---|
| 298 | void PIACmd::ShowCxxExecWindow()
|
---|
| 299 | {
|
---|
| 300 | cxxexwin->Show();
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[2463] | 303 | /* --Methode-- */
|
---|
| 304 | void PIACmd::SetCurrentPrompt(const char* pr)
|
---|
[2377] | 305 | {
|
---|
[2463] | 306 | Commander::SetCurrentPrompt(pr);
|
---|
| 307 | if (mImgApp) mImgApp->GetConsole()->SetPrompt(pr);
|
---|
[2377] | 308 | }
|
---|
| 309 |
|
---|
[1251] | 310 | /* --Methode-- */
|
---|
[2463] | 311 | void PIACmd::ShowMessage(const char * msg, int att)
|
---|
[463] | 312 | {
|
---|
[2463] | 313 | char va = (att == 0) ? 0 : PIVA_Magenta;
|
---|
| 314 | if (mImgApp) mImgApp->GetConsole()->AddStr(msg, va);
|
---|
[2263] | 315 | }
|
---|