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