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