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