source: Sophya/trunk/SophyaPI/PIext/cxxexecwin.cc@ 1297

Last change on this file since 1297 was 1297, checked in by ercodmgr, 25 years ago

1-/ complete color map in pihisto2d
2-/ introcution de la notion de module additionnel

dans le C++EXECUTOR cmv 7/11/2000

File size: 11.6 KB
RevLine 
[1251]1// Classe CxxExecWindow : Control Window for CxxExecutor
2// Classe CxxExecOptWindow : Option Window for CxxExecutor
3// (c) DAPNIA (CEA) LAL (IN2P3/CNRS)
[1269]4// R. Ansari C.Magneville 10/2000
[1251]5
6#include "cxxexecutor.h"
7#include "cxxexecwin.h"
8
[1269]9// --------------------------------------------------------------------
10// --------------------------------------------------------------------
11// ------------- Fenetre dde commande pour le CxxExecutor -------------
12// --------------------------------------------------------------------
13// --------------------------------------------------------------------
14
[1251]15/* --Methode-- */
16CxxExecWind::CxxExecWind(PIStdImgApp* par, CxxExecutor * cxxexec)
17: PIWindow((PIMsgHandler *)par, "CxxExecutor", PIWK_normal, 400, 300, 150, 150)
18{
19 dap = par;
20 cxxex = cxxexec;
[1269]21 mFName[0] = "";
22 mFName[1] = "";
[1251]23
24 int bsx, bsy, szx, szy;
25 int px, py, spx, spy;
[1269]26 int xtext, ytext;
27
28 ////////////////////////////////////
29 // Window Definition //
30 ////////////////////////////////////
31
[1251]32 // On definit la taille a partir de la taille par defaut des composantes
33 PIApplicationPrefCompSize(bsx, bsy);
34 // On redefinit la taille de la fenetre
35 spx = bsx/6;
36 spy = bsy/6;
[1269]37 xtext = 8*bsx;
38 ytext = 8*bsy;
39 szx = xtext+2*spx;
40 szy = 2*ytext+5*bsy+10*spy;
[1251]41 SetSize(szx, szy);
42
[1269]43 ////////////////////////////////////
44 // User Function Code //
45 ////////////////////////////////////
46
47// Creation du champ texte
[1251]48 px = spx;
[1269]49 py = spy;
50 mText[0] = new PIText(this,"helptext",true,true,xtext,0.75*ytext,px,py);
51 mText[0]->SetTextEditable(true);
52 mText[0]->SetText("");
[1251]53
[1269]54// Creation du champ titre, des boutons d'action et label fichier
55 px = spx;
56 py += (int)(spy+0.75*ytext);
57 mLab[3] = new PILabel(this,"FileFunc",xtext,bsy,px,py);
58 mLab[3]->SetLabel("");
59 mLab[3]->SetBorderWidth(1);
60 px = spx;
61 py += spy+bsy;
62 mLab[0] = new PILabel(this,"Function",2*bsx,bsy,px,py);
63 mLab[0]->SetLabel("User Function Code");
64 mLab[0]->SetBorderWidth(1);
65 px += spx+2*bsx;
66 mBut[0] = new PIButton(this,"Open",500,bsx,bsy,px,py);
67 px += bsx+spx;
68 mBut[1] = new PIButton(this,"Save",510,bsx,bsy,px,py);
69 px += bsx+spx;
70 mBut[2] = new PIButton(this,"Save As",520,bsx,bsy,px,py);
71 px += bsx+spx;
72 mBut[3] = new PIButton(this,"Reset Name",530,1.5*bsx,bsy,px,py);
73
74 ////////////////////////////////////
75 // User Code //
76 ////////////////////////////////////
77
[1251]78// Creation du champ texte
[1269]79 px = spx;
80 py += 2*spy+bsy;
81 mText[1] = new PIText(this,"helptext",true,true,xtext,1.25*ytext,px,py);
82 mText[1]->SetTextEditable(true);
83 mText[1]->SetText("");
[1251]84
[1269]85// Creation du champ titre, des boutons d'action et label fichier
86 px = spx;
87 py += (int)(spy+1.25*ytext);
88 mLab[4] = new PILabel(this,"FileCode",xtext,bsy,px,py);
89 mLab[4]->SetLabel("");
90 mLab[4]->SetBorderWidth(1);
91 px = spx;
92 py += spy+bsy;
93 mLab[1] = new PILabel(this,"Code",2*bsx,bsy,px,py);
94 mLab[1]->SetLabel("User Code");
95 mLab[1]->SetBorderWidth(1);
96 px += spx+2*bsx;
97 mBut[4] = new PIButton(this,"Open",501,bsx,bsy,px,py);
98 px += bsx+spx;
99 mBut[5] = new PIButton(this,"Save",511,bsx,bsy,px,py);
100 px += bsx+spx;
101 mBut[6] = new PIButton(this,"Save As",521,bsx,bsy,px,py);
102 px += bsx+spx;
103 mBut[7] = new PIButton(this,"Reset Name",531,1.5*bsx,bsy,px,py);
[1251]104
[1269]105 ////////////////////////////////////
106 // Buttons for execution //
107 ////////////////////////////////////
[1251]108
[1269]109// Creation du champ titre pour le code
110 px = spx;
111 py += 2*spy+bsy;
112 mLab[2] = new PILabel(this, "Execute",2*bsx,bsy,px,py);
113 mLab[2]->SetLabel("Execute :");
114 mLab[2]->SetBorderWidth(1);
115
116// Creation des boutons d'action
117 px += (int)(szx/2 - 1.2*bsx - spx);
118 mBut[8] = new PIButton(this,"Exec",600,1.2*bsx,bsy,px,py);
119 px += (int)(1.2*bsx+spx);
120 mBut[9] = new PIButton(this,"Dismiss",601,1.2*bsx,bsy,px,py);
121
122 ////////////////////////////////////
123 // Set Attributes for Elements //
124 ////////////////////////////////////
125
[1285]126 int ii;
127 for(ii=0; ii<5; ii++)
[1269]128 mLab[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
[1285]129 for(ii=0; ii<10; ii++)
[1251]130 mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
[1285]131 for(ii=0; ii<2; ii++)
[1269]132 mText[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
[1251]133
[1269]134 // File Chooser
[1251]135 pfc = new PIFileChooser(this,"CxxExec-FileChooser", 5000);
136}
137
138/* --Methode-- */
139CxxExecWind::~CxxExecWind()
140{
[1285]141 int i;
142 for(i=0; i<5; i++) delete mLab[i];
143 for(i=0; i<10; i++) delete mBut[i];
144 for(i=0; i<2; i++) delete mText[i];
[1251]145 delete pfc;
146}
147
148/* --Methode-- */
149void CxxExecWind::Show()
150{
[1269]151mLab[3]->SetLabel(mFName[0]);
152mLab[4]->SetLabel(mFName[1]);
153PIWindow::Show();
[1251]154}
155
156/* --Methode-- */
157void CxxExecWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
158{
[1269]159 msg = UserMsg(msg);
160 switch (msg) {
161 case 600: // Bouton Execute C++
[1251]162 dap->SetBusy();
[1269]163 mBut[8]->SetUnSensitive();
164 cxxex->ExecuteCXX(mText[1]->GetText(),mText[0]->GetText());
165 mBut[8]->SetSensitive();
[1251]166 dap->SetReady();
167 break;
[1269]168 case 601: // Bouton Dismiss - On cache la fenetre
169 this->Hide();
170 break;
171 case 500: // Open File for Function
172 case 501: // Open File for Code
173 {
174 int i = msg-500;
[1251]175 pfc->AcceptNewFile(false);
[1269]176 pfc->SetMsg(5500+i);
[1251]177 dap->SetBlocked();
178 pfc->Show();
179 break;
[1269]180 }
181 case 5500: // Return from open-file dialog for Function
182 case 5501: // Return from open-file dialog for Code
183 {
184 int i = msg-5500;
[1251]185 dap->SetBusy();
[1269]186 if(data) {
187 mFName[i] = pfc->GetFileName();
188 mLab[3+i]->SetLabel(mFName[i]);
189 string code = stringfrfile(mFName[i]);
190 mText[i]->SetText(code);
[1251]191 }
192 dap->SetReady();
193 break;
194 }
[1269]195 case 510: // Save for Function
196 case 511: // Save for Code
197 case 520: // Save-File for Function
198 case 521: // Save-File for Code
199 {
200 int i = msg%10;
201 if( msg<515 && mFName[i].length()>0 ) {
202 string code = mText[i]->GetText();
203 filefrstring(mFName[i],code);
204 } else {
[1251]205 pfc->AcceptNewFile(true);
[1269]206 pfc->SetMsg(5520+i);
[1251]207 dap->SetBlocked();
208 pfc->Show();
209 }
210 break;
[1269]211 }
212 case 5520: // Return from Save-file dialog for Function
213 case 5521: // Return from Save-file dialog for Code
214 {
215 int i = msg-5520;
[1251]216 dap->SetBusy();
217 if (data) {
[1269]218 mFName[i] = pfc->GetFileName();
219 mLab[3+i]->SetLabel(mFName[i]);
220 string code = mText[i]->GetText();
221 filefrstring(mFName[i],code);
[1251]222 }
223 dap->SetReady();
224 break;
[1269]225 }
226 case 530: // Reset name for Function
227 case 531: // Reset name for Code
228 {
229 int i = msg-530;
230 mFName[i] = "";
231 mLab[3+i]->SetLabel(mFName[i]);
232 }
[1251]233 }
234
235 // In case of compile errors, we end-up here !
[1269]236 mBut[8]->SetSensitive();
[1251]237 dap->SetReady();
238 return;
239}
240
[1269]241/* --Methode-- */
242void CxxExecWind::filefrstring(string filename,string& code)
243{
244if(filename.size()<1) return;
245if(code.size()<1) return;
246ofstream os(filename.c_str(),ios::out);
247if(!os)
248 {cout<<"CxxExecWind::filefrstring: unable to open "<<filename<<endl;
249 return;}
250os<<code<<endl;
251}
252
253/* --Methode-- */
254string CxxExecWind::stringfrfile(string filename)
255{
256string code = "";
257if(filename.size()<1) return code;
258ifstream is(filename.c_str(),ios::in);
259if(!is)
260 {cout<<"CxxExecWind::stringfrfile: unable to open "<<filename<<endl;
261 return code;}
262char c;
263while(is.get(c)) code += c;
264return code;
265}
266
[1251]267// --------------------------------------------------------------------
268// --------------------------------------------------------------------
[1269]269// --------------- Fenetre d'option pour le CxxExecutor ---------------
[1251]270// --------------------------------------------------------------------
[1269]271// --------------------------------------------------------------------
[1251]272
273/* --Methode-- */
274CxxOptionWind::CxxOptionWind(PIStdImgApp* par, CxxExecutor * cxxexec)
275: PIWindow((PIMsgHandler *)par, "CxxOption", PIWK_normal, 400, 300, 150, 150)
276{
277
278 dap = par;
279 cxxex = cxxexec;
280
281 int bsx, bsy, szx, szy;
282 int px, py, spx, spy;
[1269]283 int xtext;
[1251]284 // On definit la taille a partir de la taille par defaut des composantes
285 PIApplicationPrefCompSize(bsx, bsy);
286 // On redefinit la taille de la fenetre
[1269]287 spx = bsx/12; if(spx<2) spx=2;
[1251]288 spy = bsy/6;
[1269]289 xtext = 7*bsx;
290 szx = (int)(xtext+1.5*bsx+3*spx);
[1297]291 szy = 7*bsy+8*spy;
[1251]292 SetSize(szx, szy);
293
294// Creation de champs "labels"
[1269]295 px = (szx-xtext)/2;
296 py = spy;
297 mTit = new PILabel(this,"CxxExecutor Options",xtext,bsy,px,py);
[1251]298 mTit->SetBorderWidth(1);
[1269]299
300// Creation des labels et des champs texte
301 px = spx;
[1251]302 py += spy+bsy;
[1269]303 mLab[0] = new PILabel(this,"Include Files",1.5*bsx,bsy,px,py);
304 px += (int)(1.5*bsx+spx);
305 mText[0] = new PIText(this,"IncFiles",xtext,bsy,px,py);
306 mText[0]->SetText("");
[1251]307
[1269]308 px = spx;
[1251]309 py += spy+bsy;
[1269]310 mLab[1] = new PILabel(this,"Compile Opt.",1.5*bsx,bsy,px,py);
311 px += (int)(1.5*bsx+spx);
312 mText[1] = new PIText(this,"CompOpt",xtext,bsy,px,py);
[1251]313 mText[1]->SetText("");
[1269]314
315 px = spx;
[1251]316 py += spy+bsy;
[1269]317 mLab[2] = new PILabel(this,"Link Options",1.5*bsx,bsy,px,py);
318 px += (int)(1.5*bsx+spx);
319 mText[2] = new PIText(this,"LinkOpt",xtext,bsy,px,py);
[1251]320 mText[2]->SetText("");
[1269]321
322 px = spx;
[1251]323 py += spy+bsy;
[1269]324 mLab[3] = new PILabel(this,"Libraries",1.5*bsx,bsy,px,py);
325 px += (int)(1.5*bsx+spx);
326 mText[3] = new PIText(this,"LinkLib",xtext,bsy,px,py);
[1251]327 mText[3]->SetText("");
328
[1297]329 px = spx;
330 py += spy+bsy;
331 mLab[4] = new PILabel(this,"Modules",1.5*bsx,bsy,px,py);
332 px += (int)(1.5*bsx+spx);
333 mText[4] = new PIText(this,"ModImp",xtext,bsy,px,py);
334 mText[4]->SetText("");
335
[1251]336// Creation de bouton d'action
337
[1269]338 px = (int)(szx/2 - 1.5*bsx - spx - 1.5*bsx/2.);
339 py += spy+bsy;
340 mBut[0] = new PIButton(this,"Set Options",500,1.5*bsx,bsy,px,py);
341 px += (int)(1.5*bsx+spx);
342 mBut[1] = new PIButton(this,"Get Options",600,1.5*bsx,bsy,px,py);
343 px += (int)(1.5*bsx+spx);
344 mBut[2] = new PIButton(this,"Dismiss",700,1.5*bsx, bsy,px,py);
[1251]345
346// Taille et position proportionnelles a la taille de la fenetre pour les elements
347 mTit->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
[1285]348 int i;
349 for(i=0; i<4; i++)
[1251]350 mLab[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
[1285]351 for(i=0; i<4; i++)
[1251]352 mText[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
[1285]353 for(i=0; i<3; i++)
[1269]354 mBut[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
[1251]355}
356
357/* --Methode-- */
358CxxOptionWind::~CxxOptionWind()
359{
360 delete mTit;
[1285]361 int i;
[1297]362 for(i=0; i<5; i++) delete mLab[i];
[1285]363 for(i=0; i<3; i++) delete mBut[i];
[1297]364 for(i=0; i<5; i++) delete mText[i];
[1251]365}
366
367/* --Methode-- */
368void CxxOptionWind::Show()
369{
370 mText[0]->SetText(cxxex->GetInclude());
371 mText[1]->SetText(cxxex->GetCompileOpt());
372 mText[2]->SetText(cxxex->GetLinkOpt());
[1269]373 mText[3]->SetText(cxxex->GetLinkLibs());
[1297]374 mText[4]->SetText(cxxex->GetModuleImport());
[1251]375 PIWindow::Show();
376}
377
378/* --Methode-- */
379void CxxOptionWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
380{
381 string opt;
382 switch (UserMsg(msg)) {
383 case 500: // Bouton Set Options
384 opt = mText[0]->GetText();
385 cxxex->FillInclude(opt);
386 opt = mText[1]->GetText();
387 cxxex->FillCompileOpt(opt);
388 opt = mText[2]->GetText();
389 cxxex->FillLinkOpt(opt);
390 opt = mText[3]->GetText();
391 cxxex->FillLinkLibs(opt);
[1297]392 opt = mText[4]->GetText();
393 cxxex->FillModuleImport(opt);
[1251]394 break;
395 case 600: // Bouton Get Options
396 mText[0]->SetText(cxxex->GetInclude());
397 mText[1]->SetText(cxxex->GetCompileOpt());
398 mText[2]->SetText(cxxex->GetLinkOpt());
[1269]399 mText[3]->SetText(cxxex->GetLinkLibs());
[1297]400 mText[4]->SetText(cxxex->GetModuleImport());
[1251]401 break;
402 case 700: // Bouton Dismiss - On cache la fenetre
403 this->Hide();
404 break;
405 }
406return;
407}
Note: See TracBrowser for help on using the repository browser.