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
RevLine 
[293]1#include "piacmd.h"
[165]2#include <stdio.h>
3#include <stdlib.h>
[349]4#include <ctype.h>
[165]5#include <math.h>
6
[293]7#include "basexecut.h"
[165]8
[293]9#include "pdlmgr.h"
[165]10#include "ctimer.h"
[2214]11#include "strutil.h"
[2215]12#include "strutilxx.h"
[293]13// #include "dlftypes.h"
[2307]14#ifdef SANS_EVOLPLANCK
[2308]15#include "nbrandom.h"
[2307]16#else
17#include "srandgen.h"
18#endif
[165]19
[293]20#include "pistdimgapp.h"
[165]21#include "nobjmgr.h"
[361]22#include "piafitting.h"
[463]23#include "pawexecut.h"
[1224]24#include "cxxexecutor.h"
[1251]25#include "cxxexecwin.h"
[1828]26#include "contmodex.h"
[1920]27#include "flowmodex.h"
[165]28
[293]29#include PISTDWDG_H
30#include PILIST_H
[165]31
[293]32// ------------------------------------------------------------
[349]33// Gestion d'une fenetre d'aide interactive
34// Classe PIAHelpWind
[293]35// ------------------------------------------------------------
[165]36
[293]37class PIAHelpWind : public PIWindow {
38public :
39 PIAHelpWind(PIStdImgApp* par, PIACmd* piacmd);
40 virtual ~PIAHelpWind();
[330]41 virtual void Show();
[293]42 virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
[330]43 inline void AddHelpGroup(const char * hgrp, int gid)
44 { hgrpom->AppendItem(hgrp, 20000+gid); }
[2465]45 inline void AddHelpGroup(string const & hgrp, int gid)
46 { hgrpom->AppendItem(hgrp.c_str(), 20000+gid); }
[330]47 inline void ClearHelpList()
48 { mNitem=0; hitemlist->DeleteAllItems(); }
[293]49 inline void AddHelpItem(const char * hitem)
[330]50 { mNitem++; hitemlist->AppendItem(hitem, 100+mNitem); }
[2465]51 inline void SetHelpTextLabel(string const & htxt, string const & hlab)
52 { mTxt->SetText(htxt); mLab->SetLabel(hlab); }
53
[293]54protected :
55 PIStdImgApp* dap;
56 PIACmd* piac;
57 int mNitem;
58 PIList* hitemlist;
[330]59 PIOptMenu* hgrpom;
[293]60 PIButton * mBut;
61 PILabel * mLab;
62 PIText* mTxt;
63};
[165]64
[293]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;
[330]72SetMsg(77);
[165]73
[293]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);
[330]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);
[293]84hitemlist->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
85// hitemlist->SetBorderWidth(2);
[324]86mTxt = new PIText(this, "helptext", true, true, bsx*8.0, 6*bsy, bsx*2.0+1.5*spx, spy);
87// mTxt->SetMutiLineMode(true);
[293]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("");
[330]95mBut = new PIButton(this, "Close", 70, bsx, bsy, tsx-bsx*1.5-spx, tsy-spy-bsy);
[293]96mBut->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
97}
[165]98
99/* --Methode-- */
[293]100PIAHelpWind::~PIAHelpWind()
101{
[330]102delete hgrpom;
[293]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);
[330]113if (((um == 77) && (ModMsg(msg) == PIMsg_Close)) || (um == 70) ) {
[293]114 Hide();
115 return;
116 }
[330]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) ) {
[293]123 string s = hitemlist->GetSelectionStr();
124 mTxt->SetText(piac->GetUsage(s));
125 mLab->SetLabel(s);
126 }
127}
128
[330]129/* --Methode-- */
130void PIAHelpWind::Show()
131{
132hgrpom->SetValue(20000); // Groupe All
133mTxt->SetText("");
134mLab->SetLabel("");
135piac->UpdateHelpList(this, 0);
136PIWindow::Show();
137}
[293]138
[349]139
140// ------------------------------------------------------------
141// Classe PIACmd
142// ------------------------------------------------------------
143
[2463]144// static PIACmd* curpiacmd = NULL;
[293]145/* --Methode-- */
[165]146PIACmd::PIACmd(NamedObjMgr* omg, PIStdImgApp* app)
[2463]147 : Commander()
[165]148{
[293]149mObjMgr = omg;
[165]150mImgApp = app;
[293]151helpwin = new PIAHelpWind(app, this);
[2465]152helpwin_initdone = false;
[293]153
[2463]154string kw = "exitpiapp";
[2305]155string grp = "PIACmd";
[2465]156string gdesc = "piapp interpreter (class PIACmd) additional builtin commands";
157AddHelpGroup(grp, gdesc);
158
[2463]159string usage = "To end the piapp session ";
[2419]160RegisterCommand(kw, usage, NULL, grp);
[2463]161kw = "helpwindow";
162usage = "To display the Help window ";
[2419]163RegisterCommand(kw, usage, NULL, grp);
[2203]164
[293]165basexec = new PIABaseExecutor(this, omg, app);
[361]166fitexec = new PIAFitter(this, app);
[463]167pawexec = new PAWExecutor(this, app);
[1251]168CxxExecutor * cxxe = new CxxExecutor(this, app);
169cxxexec = cxxe;
[1828]170
171ContModExecutor *cntxx = new ContModExecutor(this, app);//_OP_
172cntexec = cntxx; //_OP_
[1920]173FlowModExecutor *flwxx = new FlowModExecutor(this, app);//_OP_
174flwexec = flwxx; //_OP_
[1828]175
[1251]176cxxoptwin = new CxxOptionWind(app, cxxe);
177cxxexwin = new CxxExecWind(app, cxxe);
178
[2465]179InitializeHelpWindowMenu();
[165]180}
181
182/* --Methode-- */
183PIACmd::~PIACmd()
184{
[2236]185
[293]186delete helpwin;
[1251]187delete cxxexwin;
188delete cxxoptwin;
[361]189delete basexec;
190delete fitexec;
[463]191delete pawexec;
[1224]192delete cxxexec;
[165]193}
194
195
[293]196/* --Methode-- */
[2465]197bool PIACmd::CheckHelpGrp(string& grp, int& gid, string& desc)
[330]198{
[2465]199bool fgnewgrp = Commander::CheckHelpGrp(grp, gid, desc);
200if (helpwin_initdone && fgnewgrp) helpwin->AddHelpGroup(grp.c_str(), gid);
201return fgnewgrp;
[330]202}
203
204/* --Methode-- */
205void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
206{
207helpwin->ClearHelpList();
[2465]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}
[330]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
[2465]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}
[165]244
[357]245/* Fonction */
[368]246static string GetStringFrStdin(PIACmd* piac)
[357]247{
[368]248PIStdImgApp* piapp = piac->GetImgApp();
249if (piapp) {
250 PIBaseWdg* wdg = piapp->CurrentBaseWdg();
251 if (wdg) wdg->Refresh();
[357]252#ifndef __mac__
[368]253 /* On vide le buffer X-Window */
[374]254 XSync(PIXDisplay(),False);
[357]255#endif
[368]256}
[357]257char buff[128];
258fgets(buff, 128, stdin);
259buff[127] = '\0';
260return((string)buff);
261}
262
[165]263
[1262]264/* --Methode-- */
265int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
266{
267int rc = 0;
268NamedObjMgr omg;
[349]269
[165]270// >>>>>>>>>>> Commande d'interpreteur
[2465]271if (kw == "helpwindow") {
272 ShowHelpWindow();
273 return 0;
274}
[2307]275// ----> Sortie d'application
276else if (kw == "exitpiapp") {
277 mImgApp->Stop();
[2465]278 return 0;
[2307]279}
[2463]280else return Commander::ExecuteCommandLine(kw, tokens, toks);
[2465]281return 0;
[165]282}
283
[333]284
[165]285/* --Methode-- */
[293]286void PIACmd::ShowHelpWindow()
[165]287{
[293]288helpwin->Show();
[165]289}
[357]290
[463]291/* --Methode-- */
[1251]292void PIACmd::ShowCxxOptionWindow()
293{
294cxxoptwin->Show();
295}
296
297/* --Methode-- */
298void PIACmd::ShowCxxExecWindow()
299{
300cxxexwin->Show();
301}
302
[2463]303/* --Methode-- */
304void PIACmd::SetCurrentPrompt(const char* pr)
[2377]305{
[2463]306 Commander::SetCurrentPrompt(pr);
307 if (mImgApp) mImgApp->GetConsole()->SetPrompt(pr);
[2377]308}
309
[1251]310/* --Methode-- */
[2463]311void PIACmd::ShowMessage(const char * msg, int att)
[463]312{
[2463]313 char va = (att == 0) ? 0 : PIVA_Magenta;
314 if (mImgApp) mImgApp->GetConsole()->AddStr(msg, va);
[2263]315}
Note: See TracBrowser for help on using the repository browser.