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

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

Suite debugging gestion lock entre threads ds piapp - A l'air de

marcher sur OSF1 et Linux ... Reza 06/01/2004

File size: 8.7 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(PIStdImgApp* app)
149 : Commander()
150{
151mObjMgr = new NamedObjMgr;
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, mObjMgr, 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// <ZThread> Thread control attributes
183fg_thrstop = false;
184fg_threxe = false;
185}
186
187/* --Methode-- */
188PIACmd::~PIACmd()
189{
190delete mObjMgr;
191delete helpwin;
192delete cxxexwin;
193delete cxxoptwin;
194delete basexec;
195delete fitexec;
196delete pawexec;
197delete cxxexec;
198}
199
200
201/* --Methode-- */
202void PIACmd::AddInputLine(string const & line)
203{
204 mutx_inps.lock();
205 inputlines.push(line);
206 mutx_inps.unlock();
207 mutx_inps.broadcast();
208}
209
210/* --Methode-- */
211void PIACmd::StopThread()
212{
213 fg_thrstop = true;
214 mutx_inps.broadcast();
215}
216
217/* --Methode-- */
218void PIACmd::run()
219{
220 while (!fg_thrstop) {
221 mutx_inps.lock();
222 while (inputlines.empty()) {
223 fg_threxe = false;
224 mutx_inps.wait();
225 }
226 string line = inputlines.top();
227 inputlines.pop();
228 fg_threxe = true;
229 mutx_inps.unlock();
230 Interpret(line);
231 }
232}
233
234/* --Methode-- */
235bool PIACmd::CheckHelpGrp(string& grp, int& gid, string& desc)
236{
237bool fgnewgrp = Commander::CheckHelpGrp(grp, gid, desc);
238if (helpwin_initdone && fgnewgrp) helpwin->AddHelpGroup(grp.c_str(), gid);
239return fgnewgrp;
240}
241
242/* --Methode-- */
243void PIACmd::UpdateHelpList(PIAHelpWind* hw, int gid)
244{
245helpwin->ClearHelpList();
246if (gid == 0) {
247 string htxt = "All registered commands";
248 string hlab = "All (HelpGroup)";
249 helpwin->SetHelpTextLabel(htxt, hlab);
250}
251else {
252 CmdHGroup::iterator ith;
253 for(ith = cmdhgrp.begin(); ith != cmdhgrp.end(); ith++) {
254 if ((*ith).second.gid == gid) {
255 string hlab = (*ith).first;
256 hlab += " (HelpGroup)";
257 helpwin->SetHelpTextLabel((*ith).second.desc, hlab);
258 break;
259 }
260 }
261}
262CmdExmap::iterator it;
263for(it = helpexmap.begin(); it != helpexmap.end(); it++) {
264 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
265 helpwin->AddHelpItem((*it).first.c_str());
266 }
267for(it = cmdexmap.begin(); it != cmdexmap.end(); it++) {
268 if ( (gid != 0) && ((*it).second.group != gid) ) continue;
269 helpwin->AddHelpItem((*it).first.c_str());
270 }
271}
272
273/* --Methode-- */
274void PIACmd::InitializeHelpWindowMenu()
275{
276 helpwin->AddHelpGroup("All", 0);
277 CmdHGroup::iterator it;
278 for(it = cmdhgrp.begin(); it != cmdhgrp.end(); it++)
279 helpwin->AddHelpGroup((*it).first, (*it).second.gid);
280 helpwin_initdone = true;
281}
282
283/* Fonction */
284static string GetStringFrStdin(PIACmd* piac)
285{
286PIStdImgApp* piapp = piac->GetImgApp();
287if (piapp) {
288 PIBaseWdg* wdg = piapp->CurrentBaseWdg();
289 if (wdg) wdg->Refresh();
290#ifndef __mac__
291 /* On vide le buffer X-Window */
292 XSync(PIXDisplay(),False);
293#endif
294}
295char buff[128];
296fgets(buff, 128, stdin);
297buff[127] = '\0';
298return((string)buff);
299}
300
301
302/* --Methode-- */
303int PIACmd::ExecuteCommandLine(string & kw, vector<string> & tokens, string & toks)
304{
305int rc = 0;
306NamedObjMgr omg;
307
308// >>>>>>>>>>> Commande d'interpreteur
309if (kw == "helpwindow") {
310 ShowHelpWindow();
311 return 0;
312}
313// ----> Sortie d'application
314else if (kw == "exitpiapp") {
315 mImgApp->Stop();
316 return 0;
317}
318else return Commander::ExecuteCommandLine(kw, tokens, toks);
319return 0;
320}
321
322
323/* --Methode-- */
324void PIACmd::ShowHelpWindow()
325{
326helpwin->Show();
327}
328
329/* --Methode-- */
330void PIACmd::ShowCxxOptionWindow()
331{
332cxxoptwin->Show();
333}
334
335/* --Methode-- */
336void PIACmd::ShowCxxExecWindow()
337{
338cxxexwin->Show();
339}
340
341/* --Methode-- */
342void PIACmd::SetCurrentPrompt(const char* pr)
343{
344 Commander::SetCurrentPrompt(pr);
345 if (mImgApp) {
346 ZSync(mImgApp->getMutex());
347 mImgApp->GetConsole()->SetPrompt(pr);
348 }
349}
350
351/* --Methode-- */
352void PIACmd::ShowMessage(const char * msg, int att)
353{
354 /*
355 Il faut faire quelque chose pour gerer correctement ca en multithread
356 char va = (att == 0) ? 0 : PIVA_Magenta;
357 if (mImgApp) {
358 ZSync(mImgApp->getMutex());
359 mImgApp->GetConsole()->AddStr(msg, va);
360 }
361 */
362Commander::ShowMessage(msg, att);
363}
Note: See TracBrowser for help on using the repository browser.