source: Sophya/trunk/SophyaPI/PIext/piacmd.cc@ 2465

Last change on this file since 2465 was 2465, checked in by ansari, 22 years ago

Suite modification/adaptations a la classe PIACmd qui herite maintenent de SOPHYA::Commander - Reza 27/11/2003

File size: 7.8 KB
Line 
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
37class PIAHelpWind : public PIWindow {
38public :
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
54protected :
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-- */
66PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
67 : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
68{
69dap = par;
70piac = piacmd;
71mNitem = 0;
72SetMsg(77);
73
74int bsx, bsy;
75int tsx, tsy;
76int spx, spy;
77PIApplicationPrefCompSize(bsx, bsy);
78spx = bsx/6; spy = bsy/6;
79tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
80SetSize(tsx,tsy);
81hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
82hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
83hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
84hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
85// hitemlist->SetBorderWidth(2);
86mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
87// mTxt->SetMutiLineMode(true);
88mTxt->SetTextEditable(false);
89mTxt->SetText("");
90mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
91mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
92mLab->SetBorderWidth(1);
93mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
94mLab->SetLabel("");
95mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
96mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
97}
98
99/* --Methode-- */
100PIAHelpWind::~PIAHelpWind()
101{
102delete hgrpom;
103delete hitemlist;
104delete mTxt;
105delete mLab;
106delete mBut;
107}
108
109/* --Methode-- */
110void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
111{
112PIMessage um = UserMsg(msg);
113if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
114 Hide();
115 return;
116 }
117else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
118 mTxt->SetText("");
119 mLab->SetLabel("");
120 piac->UpdateHelpList(this, um-20000);
121}
122else 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-- */
130void PIAHelpWind::Show()
131{
132hgrpom->SetValue(20000); // Groupe All
133mTxt->SetText("");
134mLab->SetLabel("");
135piac->UpdateHelpList(this, 0);
136PIWindow::Show();
137}
138
139
140// ------------------------------------------------------------
141// Classe PIACmd
142// ------------------------------------------------------------
143
144// static PIACmd* curpiacmd = NULL;
145/* --Methode-- */
146PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
147 : Commander()
148{
149mObjMgr = omg;
150mImgApp = app;
151helpwin = new PIAHelpWind(app, this);
152helpwin_initdone = false;
153
154string kw = "exitpiapp";
155string grp = "PIACmd";
156string gdesc = "piapp interpreter (class PIACmd) additional builtin commands";
157AddHelpGroup(grp, gdesc);
158
159string usage = "To end the piapp session ";
160RegisterCommand(kw, usage, NULL, grp);
161kw = "helpwindow";
162usage = "To display the Help window ";
163RegisterCommand(kw, usage, NULL, grp);
164
165basexec = new PIABaseExecutor(this, omg, app);
166fitexec = new PIAFitter(this, app);
167pawexec = new PAWExecutor(this, app);
168CxxExecutor * cxxe = new CxxExecutor(this, app);
169cxxexec = cxxe;
170
171ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
172cntexec = cntxx; //_OP_
173FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
174flwexec = flwxx; //_OP_
175
176cxxoptwin = new CxxOptionWind(app, cxxe);
177cxxexwin = new CxxExecWind(app, cxxe);
178
179InitializeHelpWindowMenu();
180}
181
182/* --Methode-- */
183PIACmd::~PIACmd()
184{
185
186delete helpwin;
187delete cxxexwin;
188delete cxxoptwin;
189delete basexec;
190delete fitexec;
191delete pawexec;
192delete cxxexec;
193}
194
195
196/* --Methode-- */
197bool PIACmd::CheckHelpGrp(string& grp, int& gid, string& desc)
198{
199bool fgnewgrp = Commander::CheckHelpGrp(grp, gid, desc);
200if (helpwin_initdone && fgnewgrp) helpwin->AddHelpGroup(grp.c_str(), gid);
201return fgnewgrp;
202}
203
204/* --Methode-- */
205void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
206{
207helpwin->ClearHelpList();
208if (gid == 0) {
209 string htxt = "All registered commands";
210 string hlab = "All (HelpGroup)";
211 helpwin->SetHelpTextLabel(htxt, hlab);
212}
213else {
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}
224CmdExmap::iterator it;
225for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
226 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
227 helpwin->AddHelpItem((*it).first.c_str());
228 }
229for(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-- */
236void 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 */
246static string GetStringFrStdin(PIACmd* piac)
247{
248PIStdImgApp* piapp = piac->GetImgApp();
249if (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}
257char buff[128];
258fgets(buff, 128, stdin);
259buff[127] = '\0';
260return((string)buff);
261}
262
263
264/* --Methode-- */
265int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
266{
267int rc = 0;
268NamedObjMgr omg;
269
270// >>>>>>>>>>> Commande d'interpreteur
271if (kw == "helpwindow") {
272 ShowHelpWindow();
273 return 0;
274}
275// ----> Sortie d'application
276else if (kw == "exitpiapp") {
277 mImgApp->Stop();
278 return 0;
279}
280else return Commander::ExecuteCommandLine(kw, tokens, toks);
281return 0;
282}
283
284
285/* --Methode-- */
286void PIACmd::ShowHelpWindow()
287{
288helpwin->Show();
289}
290
291/* --Methode-- */
292void PIACmd::ShowCxxOptionWindow()
293{
294cxxoptwin->Show();
295}
296
297/* --Methode-- */
298void PIACmd::ShowCxxExecWindow()
299{
300cxxexwin->Show();
301}
302
303/* --Methode-- */
304void PIACmd::SetCurrentPrompt(const char* pr)
305{
306 Commander::SetCurrentPrompt(pr);
307 if (mImgApp) mImgApp->GetConsole()->SetPrompt(pr);
308}
309
310/* --Methode-- */
311void 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}
Note: See TracBrowser for help on using the repository browser.