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