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