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

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

Modification du code de PIACmd : La classe PIACmd herite maintenant de la classe Commander (de SysTools) - Reza 26/11/2003

File size: 6.9 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 ClearHelpList()
46 { mNitem=0; hitemlist->DeleteAllItems(); }
47 inline void AddHelpItem(const char * hitem)
48 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
49protected :
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-- */
61PIAHelpWind::PIAHelpWind(PIStdImgApp *par, PIACmd* piacmd)
62 : PIWindow((PIMsgHandler *)par, "Help-PIApp", PIWK_normal, 400, 300, 100, 350)
63{
64dap = par;
65piac = piacmd;
66mNitem = 0;
67SetMsg(77);
68
69int bsx, bsy;
70int tsx, tsy;
71int spx, spy;
72PIApplicationPrefCompSize(bsx, bsy);
73spx = bsx/6; spy = bsy/6;
74tsx = 10*bsx+2*spx; tsy = 7*bsy+3*spy;
75SetSize(tsx,tsy);
76hgrpom = new PIOptMenu(this, "hgrpoptmen", bsx*2.0, bsy, spx/2, spy);
77hgrpom->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
78hitemlist = new PIList(this, "hitemlist", bsx*2.0, tsy-3*spy-bsy, spx/2, 2*spy+bsy);
79hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
80// hitemlist->SetBorderWidth(2);
81mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
82// mTxt->SetMutiLineMode(true);
83mTxt->SetTextEditable(false);
84mTxt->SetText("");
85mTxt->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
86mLab = new PILabel(this, "helpitem", bsx*4, bsy, bsx*2.5+2*spx, tsy-spy-bsy);
87mLab->SetBorderWidth(1);
88mLab->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
89mLab->SetLabel("");
90mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
91mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
92}
93
94/* --Methode-- */
95PIAHelpWind::~PIAHelpWind()
96{
97delete hgrpom;
98delete hitemlist;
99delete mTxt;
100delete mLab;
101delete mBut;
102}
103
104/* --Methode-- */
105void PIAHelpWind::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
106{
107PIMessage um = UserMsg(msg);
108if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
109 Hide();
110 return;
111 }
112else if ( (um >= 20000) && (sender == hgrpom)) { // Selection de groupe de Help
113 mTxt->SetText("");
114 mLab->SetLabel("");
115 piac->UpdateHelpList(this, um-20000);
116}
117else 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-- */
125void PIAHelpWind::Show()
126{
127hgrpom->SetValue(20000); // Groupe All
128mTxt->SetText("");
129mLab->SetLabel("");
130piac->UpdateHelpList(this, 0);
131PIWindow::Show();
132}
133
134
135// ------------------------------------------------------------
136// Classe PIACmd
137// ------------------------------------------------------------
138
139// static PIACmd* curpiacmd = NULL;
140/* --Methode-- */
141PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
142 : Commander()
143{
144mObjMgr = omg;
145mImgApp = app;
146
147//MOVE if (mImgApp) mImgApp->GetConsole()->SetPrompt(spromptmul);
148//?? cmdhgrp["All"] = 0;
149//?? cmdgrpid = 1;
150//?? cmdhgrp["PIACmd"] = 1;
151helpwin = new PIAHelpWind(app, this);
152helpwin->AddHelpGroup("All", 0);
153// helpwin->AddHelpGroup("PIACmd", 1);
154
155string kw = "exitpiapp";
156string grp = "PIACmd";
157string usage = "To end the piapp session ";
158RegisterCommand(kw, usage, NULL, grp);
159kw = "helpwindow";
160usage = "To display the Help window ";
161RegisterCommand(kw, usage, NULL, grp);
162
163basexec = new PIABaseExecutor(this, omg, app);
164fitexec = new PIAFitter(this, app);
165pawexec = new PAWExecutor(this, app);
166CxxExecutor * cxxe = new CxxExecutor(this, app);
167cxxexec = cxxe;
168
169ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
170cntexec = cntxx; //_OP_
171FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
172flwexec = flwxx; //_OP_
173
174cxxoptwin = new CxxOptionWind(app, cxxe);
175cxxexwin = new CxxExecWind(app, cxxe);
176
177}
178
179/* --Methode-- */
180PIACmd::~PIACmd()
181{
182
183delete helpwin;
184delete cxxexwin;
185delete cxxoptwin;
186delete basexec;
187delete fitexec;
188delete pawexec;
189delete cxxexec;
190}
191
192
193/* --Methode-- */
194int PIACmd::CheckHelpGrp(string& grp)
195{
196int gid=0;
197CmdHGroup::iterator it = cmdhgrp.find(grp);
198if (it == cmdhgrp.end()) {
199 cmdgrpid++; gid = cmdgrpid;
200 cmdhgrp[grp] = gid;
201 helpwin->AddHelpGroup(grp.c_str(), gid);
202 }
203else gid = (*it).second;
204return(gid);
205}
206
207/* --Methode-- */
208void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
209{
210helpwin->ClearHelpList();
211CmdExmap::iterator it;
212for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
213 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
214 helpwin->AddHelpItem((*it).first.c_str());
215 }
216for(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 */
224static string GetStringFrStdin(PIACmd* piac)
225{
226PIStdImgApp* piapp = piac->GetImgApp();
227if (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}
235char buff[128];
236fgets(buff, 128, stdin);
237buff[127] = '\0';
238return((string)buff);
239}
240
241
242/* --Methode-- */
243int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
244{
245int rc = 0;
246NamedObjMgr omg;
247
248// >>>>>>>>>>> Commande d'interpreteur
249if (kw == "helpwindow") ShowHelpWindow();
250// ----> Sortie d'application
251else if (kw == "exitpiapp") {
252 mImgApp->Stop();
253 return(0);
254}
255else return Commander::ExecuteCommandLine(kw, tokens, toks);
256
257}
258
259
260/* --Methode-- */
261void PIACmd::ShowHelpWindow()
262{
263helpwin->Show();
264}
265
266/* --Methode-- */
267void PIACmd::ShowCxxOptionWindow()
268{
269cxxoptwin->Show();
270}
271
272/* --Methode-- */
273void PIACmd::ShowCxxExecWindow()
274{
275cxxexwin->Show();
276}
277
278/* --Methode-- */
279void PIACmd::SetCurrentPrompt(const char* pr)
280{
281 Commander::SetCurrentPrompt(pr);
282 if (mImgApp) mImgApp->GetConsole()->SetPrompt(pr);
283}
284
285/* --Methode-- */
286void 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}
Note: See TracBrowser for help on using the repository browser.