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