1 | // Classe CxxExecWindow : Control Window for CxxExecutor
|
---|
2 | // Classe CxxExecOptWindow : Option Window for CxxExecutor
|
---|
3 | // (c) DAPNIA (CEA) LAL (IN2P3/CNRS)
|
---|
4 | // R. Ansari C.Magneville 10/2000
|
---|
5 |
|
---|
6 | #include "cxxexecutor.h"
|
---|
7 | #include "cxxexecwin.h"
|
---|
8 |
|
---|
9 | // --------------------------------------------------------------------
|
---|
10 | // --------------------------------------------------------------------
|
---|
11 | // ------------- Fenetre dde commande pour le CxxExecutor -------------
|
---|
12 | // --------------------------------------------------------------------
|
---|
13 | // --------------------------------------------------------------------
|
---|
14 |
|
---|
15 | /* --Methode-- */
|
---|
16 | CxxExecWind::CxxExecWind(PIStdImgApp* par, CxxExecutor * cxxexec)
|
---|
17 | : PIWindow((PIMsgHandler *)par, "CxxExecutor", PIWK_normal, 400, 300, 150, 150)
|
---|
18 | {
|
---|
19 | dap = par;
|
---|
20 | cxxex = cxxexec;
|
---|
21 | mFName[0] = "";
|
---|
22 | mFName[1] = "";
|
---|
23 |
|
---|
24 | int bsx, bsy, szx, szy;
|
---|
25 | int px, py, spx, spy;
|
---|
26 | int xtext, ytext;
|
---|
27 |
|
---|
28 | ////////////////////////////////////
|
---|
29 | // Window Definition //
|
---|
30 | ////////////////////////////////////
|
---|
31 |
|
---|
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;
|
---|
37 | xtext = 8*bsx;
|
---|
38 | ytext = 8*bsy;
|
---|
39 | szx = xtext+2*spx;
|
---|
40 | szy = 2*ytext+5*bsy+10*spy;
|
---|
41 | SetSize(szx, szy);
|
---|
42 |
|
---|
43 | ////////////////////////////////////
|
---|
44 | // User Function Code //
|
---|
45 | ////////////////////////////////////
|
---|
46 |
|
---|
47 | // Creation du champ texte
|
---|
48 | px = spx;
|
---|
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("");
|
---|
53 |
|
---|
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 |
|
---|
78 | // Creation du champ texte
|
---|
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("");
|
---|
84 |
|
---|
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);
|
---|
104 |
|
---|
105 | ////////////////////////////////////
|
---|
106 | // Buttons for execution //
|
---|
107 | ////////////////////////////////////
|
---|
108 |
|
---|
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 |
|
---|
126 | int ii;
|
---|
127 | for(ii=0; ii<5; ii++)
|
---|
128 | mLab[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
129 | for(ii=0; ii<10; ii++)
|
---|
130 | mBut[ii]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
|
---|
131 | for(ii=0; ii<2; ii++)
|
---|
132 | mText[ii]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
|
---|
133 |
|
---|
134 | // File Chooser
|
---|
135 | pfc = new PIFileChooser(this,"CxxExec-FileChooser", 5000);
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* --Methode-- */
|
---|
139 | CxxExecWind::~CxxExecWind()
|
---|
140 | {
|
---|
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];
|
---|
145 | delete pfc;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /* --Methode-- */
|
---|
149 | void CxxExecWind::Show()
|
---|
150 | {
|
---|
151 | mLab[3]->SetLabel(mFName[0]);
|
---|
152 | mLab[4]->SetLabel(mFName[1]);
|
---|
153 | PIWindow::Show();
|
---|
154 | }
|
---|
155 |
|
---|
156 | /* --Methode-- */
|
---|
157 | void CxxExecWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* data)
|
---|
158 | {
|
---|
159 | msg = UserMsg(msg);
|
---|
160 | switch (msg) {
|
---|
161 | case 600: // Bouton Execute C++
|
---|
162 | dap->SetBusy();
|
---|
163 | mBut[8]->SetUnSensitive();
|
---|
164 | cxxex->ExecuteCXX(mText[1]->GetText(),mText[0]->GetText());
|
---|
165 | mBut[8]->SetSensitive();
|
---|
166 | dap->SetReady();
|
---|
167 | break;
|
---|
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;
|
---|
175 | pfc->AcceptNewFile(false);
|
---|
176 | pfc->SetMsg(5500+i);
|
---|
177 | dap->SetBlocked();
|
---|
178 | pfc->Show();
|
---|
179 | break;
|
---|
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;
|
---|
185 | dap->SetBusy();
|
---|
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);
|
---|
191 | }
|
---|
192 | dap->SetReady();
|
---|
193 | break;
|
---|
194 | }
|
---|
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 {
|
---|
205 | pfc->AcceptNewFile(true);
|
---|
206 | pfc->SetMsg(5520+i);
|
---|
207 | dap->SetBlocked();
|
---|
208 | pfc->Show();
|
---|
209 | }
|
---|
210 | break;
|
---|
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;
|
---|
216 | dap->SetBusy();
|
---|
217 | if (data) {
|
---|
218 | mFName[i] = pfc->GetFileName();
|
---|
219 | mLab[3+i]->SetLabel(mFName[i]);
|
---|
220 | string code = mText[i]->GetText();
|
---|
221 | filefrstring(mFName[i],code);
|
---|
222 | }
|
---|
223 | dap->SetReady();
|
---|
224 | break;
|
---|
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 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | // In case of compile errors, we end-up here !
|
---|
236 | mBut[8]->SetSensitive();
|
---|
237 | dap->SetReady();
|
---|
238 | return;
|
---|
239 | }
|
---|
240 |
|
---|
241 | /* --Methode-- */
|
---|
242 | void CxxExecWind::filefrstring(string filename,string& code)
|
---|
243 | {
|
---|
244 | if(filename.size()<1) return;
|
---|
245 | if(code.size()<1) return;
|
---|
246 | ofstream os(filename.c_str(),ios::out);
|
---|
247 | if(!os)
|
---|
248 | {cout<<"CxxExecWind::filefrstring: unable to open "<<filename<<endl;
|
---|
249 | return;}
|
---|
250 | os<<code<<endl;
|
---|
251 | }
|
---|
252 |
|
---|
253 | /* --Methode-- */
|
---|
254 | string CxxExecWind::stringfrfile(string filename)
|
---|
255 | {
|
---|
256 | string code = "";
|
---|
257 | if(filename.size()<1) return code;
|
---|
258 | ifstream is(filename.c_str(),ios::in);
|
---|
259 | if(!is)
|
---|
260 | {cout<<"CxxExecWind::stringfrfile: unable to open "<<filename<<endl;
|
---|
261 | return code;}
|
---|
262 | char c;
|
---|
263 | while(is.get(c)) code += c;
|
---|
264 | return code;
|
---|
265 | }
|
---|
266 |
|
---|
267 | // --------------------------------------------------------------------
|
---|
268 | // --------------------------------------------------------------------
|
---|
269 | // --------------- Fenetre d'option pour le CxxExecutor ---------------
|
---|
270 | // --------------------------------------------------------------------
|
---|
271 | // --------------------------------------------------------------------
|
---|
272 |
|
---|
273 | /* --Methode-- */
|
---|
274 | CxxOptionWind::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;
|
---|
283 | int xtext;
|
---|
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
|
---|
287 | spx = bsx/12; if(spx<2) spx=2;
|
---|
288 | spy = bsy/6;
|
---|
289 | xtext = 7*bsx;
|
---|
290 | szx = (int)(xtext+1.5*bsx+3*spx);
|
---|
291 | szy = 6*bsy+7*spy;
|
---|
292 | SetSize(szx, szy);
|
---|
293 |
|
---|
294 | // Creation de champs "labels"
|
---|
295 | px = (szx-xtext)/2;
|
---|
296 | py = spy;
|
---|
297 | mTit = new PILabel(this,"CxxExecutor Options",xtext,bsy,px,py);
|
---|
298 | mTit->SetBorderWidth(1);
|
---|
299 |
|
---|
300 | // Creation des labels et des champs texte
|
---|
301 | px = spx;
|
---|
302 | py += spy+bsy;
|
---|
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("");
|
---|
307 |
|
---|
308 | px = spx;
|
---|
309 | py += spy+bsy;
|
---|
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);
|
---|
313 | mText[1]->SetText("");
|
---|
314 |
|
---|
315 | px = spx;
|
---|
316 | py += spy+bsy;
|
---|
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);
|
---|
320 | mText[2]->SetText("");
|
---|
321 |
|
---|
322 | px = spx;
|
---|
323 | py += spy+bsy;
|
---|
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);
|
---|
327 | mText[3]->SetText("");
|
---|
328 |
|
---|
329 | // Creation de bouton d'action
|
---|
330 |
|
---|
331 | px = (int)(szx/2 - 1.5*bsx - spx - 1.5*bsx/2.);
|
---|
332 | py += spy+bsy;
|
---|
333 | mBut[0] = new PIButton(this,"Set Options",500,1.5*bsx,bsy,px,py);
|
---|
334 | px += (int)(1.5*bsx+spx);
|
---|
335 | mBut[1] = new PIButton(this,"Get Options",600,1.5*bsx,bsy,px,py);
|
---|
336 | px += (int)(1.5*bsx+spx);
|
---|
337 | mBut[2] = new PIButton(this,"Dismiss",700,1.5*bsx, bsy,px,py);
|
---|
338 |
|
---|
339 | // Taille et position proportionnelles a la taille de la fenetre pour les elements
|
---|
340 | mTit->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
|
---|
341 | int i;
|
---|
342 | for(i=0; i<4; i++)
|
---|
343 | mLab[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
|
---|
344 | for(i=0; i<4; i++)
|
---|
345 | mText[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
|
---|
346 | for(i=0; i<3; i++)
|
---|
347 | mBut[i]->SetBinding(PIBK_elastic , PIBK_elastic , PIBK_elastic , PIBK_elastic);
|
---|
348 | }
|
---|
349 |
|
---|
350 | /* --Methode-- */
|
---|
351 | CxxOptionWind::~CxxOptionWind()
|
---|
352 | {
|
---|
353 | delete mTit;
|
---|
354 | int i;
|
---|
355 | for(i=0; i<4; i++) delete mLab[i];
|
---|
356 | for(i=0; i<3; i++) delete mBut[i];
|
---|
357 | for(i=0; i<4; i++) delete mText[i];
|
---|
358 | }
|
---|
359 |
|
---|
360 | /* --Methode-- */
|
---|
361 | void CxxOptionWind::Show()
|
---|
362 | {
|
---|
363 | mText[0]->SetText(cxxex->GetInclude());
|
---|
364 | mText[1]->SetText(cxxex->GetCompileOpt());
|
---|
365 | mText[2]->SetText(cxxex->GetLinkOpt());
|
---|
366 | mText[3]->SetText(cxxex->GetLinkLibs());
|
---|
367 | PIWindow::Show();
|
---|
368 | }
|
---|
369 |
|
---|
370 | /* --Methode-- */
|
---|
371 | void CxxOptionWind::Process(PIMessage msg, PIMsgHandler* /*sender*/, void* /*data*/)
|
---|
372 | {
|
---|
373 | string opt;
|
---|
374 | switch (UserMsg(msg)) {
|
---|
375 | case 500: // Bouton Set Options
|
---|
376 | opt = mText[0]->GetText();
|
---|
377 | cxxex->FillInclude(opt);
|
---|
378 | opt = mText[1]->GetText();
|
---|
379 | cxxex->FillCompileOpt(opt);
|
---|
380 | opt = mText[2]->GetText();
|
---|
381 | cxxex->FillLinkOpt(opt);
|
---|
382 | opt = mText[3]->GetText();
|
---|
383 | cxxex->FillLinkLibs(opt);
|
---|
384 | break;
|
---|
385 | case 600: // Bouton Get Options
|
---|
386 | mText[0]->SetText(cxxex->GetInclude());
|
---|
387 | mText[1]->SetText(cxxex->GetCompileOpt());
|
---|
388 | mText[2]->SetText(cxxex->GetLinkOpt());
|
---|
389 | mText[3]->SetText(cxxex->GetLinkLibs());
|
---|
390 | break;
|
---|
391 | case 700: // Bouton Dismiss - On cache la fenetre
|
---|
392 | this->Hide();
|
---|
393 | break;
|
---|
394 | }
|
---|
395 | return;
|
---|
396 | }
|
---|