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