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