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 ClearHelpList()
|
---|
46 | { mNitem=0; hitemlist->DeleteAllItems(); }
|
---|
47 | inline void AddHelpItem(const char * hitem)
|
---|
48 | { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
|
---|
49 | protected :
|
---|
50 | PIStdImgApp* dap;
|
---|
51 | PIACmd* piac;
|
---|
52 | int mNitem;
|
---|
53 | PIList* hitemlist;
|
---|
54 | PIOptMenu* hgrpom;
|
---|
55 | PIButton * mBut;
|
---|
56 | PILabel * mLab;
|
---|
57 | PIText* mTxt;
|
---|
58 | };
|
---|
59 |
|
---|
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;
|
---|
67 | SetMsg(77);
|
---|
68 |
|
---|
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);
|
---|
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);
|
---|
79 | hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
80 | // hitemlist->SetBorderWidth(2);
|
---|
81 | mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
|
---|
82 | // mTxt->SetMutiLineMode(true);
|
---|
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("");
|
---|
90 | mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
|
---|
91 | mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* --Methode-- */
|
---|
95 | PIAHelpWind::~PIAHelpWind()
|
---|
96 | {
|
---|
97 | delete hgrpom;
|
---|
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);
|
---|
108 | if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
|
---|
109 | Hide();
|
---|
110 | return;
|
---|
111 | }
|
---|
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) ) {
|
---|
118 | string s = hitemlist->GetSelectionStr();
|
---|
119 | mTxt->SetText(piac->GetUsage(s));
|
---|
120 | mLab->SetLabel(s);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
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 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | // ------------------------------------------------------------
|
---|
136 | // Classe PIACmd
|
---|
137 | // ------------------------------------------------------------
|
---|
138 |
|
---|
139 | // static PIACmd* curpiacmd = NULL;
|
---|
140 | /* --Methode-- */
|
---|
141 | PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
|
---|
142 | : Commander()
|
---|
143 | {
|
---|
144 | mObjMgr = omg;
|
---|
145 | mImgApp = app;
|
---|
146 |
|
---|
147 | //MOVE if (mImgApp) mImgApp->GetConsole()->SetPrompt(spromptmul);
|
---|
148 | //?? cmdhgrp["All"] = 0;
|
---|
149 | //?? cmdgrpid = 1;
|
---|
150 | //?? cmdhgrp["PIACmd"] = 1;
|
---|
151 | helpwin = new PIAHelpWind(app, this);
|
---|
152 | helpwin->AddHelpGroup("All", 0);
|
---|
153 | // helpwin->AddHelpGroup("PIACmd", 1);
|
---|
154 |
|
---|
155 | string kw = "exitpiapp";
|
---|
156 | string grp = "PIACmd";
|
---|
157 | string usage = "To end the piapp session ";
|
---|
158 | RegisterCommand(kw, usage, NULL, grp);
|
---|
159 | kw = "helpwindow";
|
---|
160 | usage = "To display the Help window ";
|
---|
161 | RegisterCommand(kw, usage, NULL, grp);
|
---|
162 |
|
---|
163 | basexec = new PIABaseExecutor(this, omg, app);
|
---|
164 | fitexec = new PIAFitter(this, app);
|
---|
165 | pawexec = new PAWExecutor(this, app);
|
---|
166 | CxxExecutor * cxxe = new CxxExecutor(this, app);
|
---|
167 | cxxexec = cxxe;
|
---|
168 |
|
---|
169 | ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
|
---|
170 | cntexec = cntxx; //_OP_
|
---|
171 | FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
|
---|
172 | flwexec = flwxx; //_OP_
|
---|
173 |
|
---|
174 | cxxoptwin = new CxxOptionWind(app, cxxe);
|
---|
175 | cxxexwin = new CxxExecWind(app, cxxe);
|
---|
176 |
|
---|
177 | }
|
---|
178 |
|
---|
179 | /* --Methode-- */
|
---|
180 | PIACmd::~PIACmd()
|
---|
181 | {
|
---|
182 |
|
---|
183 | delete helpwin;
|
---|
184 | delete cxxexwin;
|
---|
185 | delete cxxoptwin;
|
---|
186 | delete basexec;
|
---|
187 | delete fitexec;
|
---|
188 | delete pawexec;
|
---|
189 | delete cxxexec;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | /* --Methode-- */
|
---|
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 |
|
---|
222 |
|
---|
223 | /* Fonction */
|
---|
224 | static string GetStringFrStdin(PIACmd* piac)
|
---|
225 | {
|
---|
226 | PIStdImgApp* piapp = piac->GetImgApp();
|
---|
227 | if (piapp) {
|
---|
228 | PIBaseWdg* wdg = piapp->CurrentBaseWdg();
|
---|
229 | if (wdg) wdg->Refresh();
|
---|
230 | #ifndef __mac__
|
---|
231 | /* On vide le buffer X-Window */
|
---|
232 | XSync(PIXDisplay(),False);
|
---|
233 | #endif
|
---|
234 | }
|
---|
235 | char buff[128];
|
---|
236 | fgets(buff, 128, stdin);
|
---|
237 | buff[127] = '\0';
|
---|
238 | return((string)buff);
|
---|
239 | }
|
---|
240 |
|
---|
241 |
|
---|
242 | /* --Methode-- */
|
---|
243 | int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
|
---|
244 | {
|
---|
245 | int rc = 0;
|
---|
246 | NamedObjMgr omg;
|
---|
247 |
|
---|
248 | // >>>>>>>>>>> Commande d'interpreteur
|
---|
249 | if (kw == "helpwindow") ShowHelpWindow();
|
---|
250 | // ----> Sortie d'application
|
---|
251 | else if (kw == "exitpiapp") {
|
---|
252 | mImgApp->Stop();
|
---|
253 | return(0);
|
---|
254 | }
|
---|
255 | else return Commander::ExecuteCommandLine(kw, tokens, toks);
|
---|
256 |
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 | /* --Methode-- */
|
---|
261 | void PIACmd::ShowHelpWindow()
|
---|
262 | {
|
---|
263 | helpwin->Show();
|
---|
264 | }
|
---|
265 |
|
---|
266 | /* --Methode-- */
|
---|
267 | void PIACmd::ShowCxxOptionWindow()
|
---|
268 | {
|
---|
269 | cxxoptwin->Show();
|
---|
270 | }
|
---|
271 |
|
---|
272 | /* --Methode-- */
|
---|
273 | void PIACmd::ShowCxxExecWindow()
|
---|
274 | {
|
---|
275 | cxxexwin->Show();
|
---|
276 | }
|
---|
277 |
|
---|
278 | /* --Methode-- */
|
---|
279 | void PIACmd::SetCurrentPrompt(const char* pr)
|
---|
280 | {
|
---|
281 | Commander::SetCurrentPrompt(pr);
|
---|
282 | if (mImgApp) mImgApp->GetConsole()->SetPrompt(pr);
|
---|
283 | }
|
---|
284 |
|
---|
285 | /* --Methode-- */
|
---|
286 | void PIACmd::ShowMessage(const char * msg, int att)
|
---|
287 | {
|
---|
288 | char va = (att == 0) ? 0 : PIVA_Magenta;
|
---|
289 | if (mImgApp) mImgApp->GetConsole()->AddStr(msg, va);
|
---|
290 | }
|
---|