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

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

Petites modifs ds piacmd.cc .h - Reza 4/12/2003

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