Fixed text file permissions
[snark14.git] / tools / Input / execute.cpp
1 /** @file execute.cpp
2     @package snark05Input
3     @author Bruno M. Carvalho and Deniz Sarioz
4     licensed under (open-source) QPL v1.0
5     which accompanies this distribution in the file QPL
6 */
7
8 #include "execute.h"
9 #include "misc.h"
10 #include "variables.h"
11 #include <stdio.h>
12
13 #include <qbuttongroup.h>
14 #include <qframe.h>
15 #include <qlabel.h>
16 #include <qlineedit.h>
17 #include <qmultilineedit.h>
18 #include <qpushbutton.h>
19 #include <qradiobutton.h>
20 #include <qlayout.h>
21 #include <qvariant.h>
22 #include <qtooltip.h>
23 #include <qwhatsthis.h>
24 #include <qmessagebox.h>
25
26 /** 
27  *  Constructs a executewindow which is a child of 'parent', with the 
28  *  name 'name' and widget flags set to 'f' 
29  *
30  *  The dialog will by default be modeless, unless you set 'modal' to
31  *  TRUE to construct a modal dialog.
32 @param void
33 @author Bruno M. Carvalho (modified a little by deniz)
34 @version 1.0 */
35 executewindow::executewindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
36     : QDialog( parent, name, modal, fl )
37 {
38     if ( !name )
39         setName( "executewindow" );
40     resize( 400, 600 ); 
41     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
42     setMinimumSize( QSize( 400, 700 ) );
43     setMaximumSize( QSize( 400, 700 ) );
44     setCaption( tr( "Execute Window" ) );
45
46     executelabel = new QLabel( this, "executelabel" );
47     executelabel->setGeometry( QRect( 10, 10, 120, 30 ) ); 
48     executelabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, executelabel->sizePolicy().hasHeightForWidth() ) );
49     executelabel->setMinimumSize( QSize( 120, 30 ) );
50     executelabel->setMaximumSize( QSize( 120, 30 ) );
51     executelabel->setText( tr( "EXECUTE" ) );
52
53     executebuttongroup = new QButtonGroup( this, "executebuttongroup" );
54     executebuttongroup->setGeometry( QRect( 40, 40, 160, 170 ) ); 
55     executebuttongroup->setTitle( tr( "type" ) );
56     executebuttongroup->setAlignment( int( QButtonGroup::AlignHCenter ) );
57
58     zerobutton = new QRadioButton( executebuttongroup, "zerobutton" );
59     zerobutton->setGeometry( QRect( 10, 20, 130, 24 ) ); 
60     zerobutton->setText( tr( "ZERO" ) ); 
61
62     averagebutton = new QRadioButton( executebuttongroup, "averagebutton" );
63     averagebutton->setGeometry( QRect( 10, 50, 110, 24 ) ); 
64     averagebutton->setText( tr( "AVERAGE" ) ); 
65
66     continuebutton = new QRadioButton( executebuttongroup, "continuebutton" );
67     continuebutton->setGeometry( QRect( 10, 80, 110, 24 ) ); 
68     continuebutton->setText( tr( "CONTINUE" ) );
69
70     // added by deniz:
71     phantombutton = new QRadioButton( executebuttongroup, "phantombutton" );
72     phantombutton->setGeometry( QRect( 10, 110, 110, 24 ) ); 
73     phantombutton->setText( tr( "PHANTOM" ) );
74
75     nonebutton = new QRadioButton( executebuttongroup, "nonebutton" );
76     nonebutton->setGeometry( QRect( 10, 140, 80, 24 ) ); 
77     nonebutton->setText( tr( "NONE" ) ); 
78     nonebutton->setChecked(true);
79
80     algname = new QLineEdit( this, "algname" );
81     algname->setGeometry( QRect( 30, 230, 350, 28 ) );
82
83     algnamelabel = new QLabel( this, "algnamelabel" );
84     algnamelabel->setGeometry( QRect( 170, 210, 70, 20 ) ); 
85     algnamelabel->setText( tr( "algname" ) );
86
87     executebuttongroup2 = new QButtonGroup( this, "executebuttongroup2" );
88     executebuttongroup2->setGeometry( QRect( 40, 270, 160, 100 ) ); 
89     executebuttongroup2->setTitle( tr( "" ) );
90     executebuttongroup2->setAlignment( int( QButtonGroup::AlignHCenter ) );
91
92     contourbutton = new QRadioButton( executebuttongroup2, "contourbutton" );
93     contourbutton->setGeometry( QRect( 10, 10, 110, 30 ) ); 
94     contourbutton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, contourbutton->sizePolicy().hasHeightForWidth() ) );
95     contourbutton->setMinimumSize( QSize( 110, 30 ) );
96     contourbutton->setMaximumSize( QSize( 110, 30 ) );
97     contourbutton->setText( tr( "CONTOUR" ) );
98     QObject::connect(contourbutton,SIGNAL(clicked()),this,SLOT(activateContourSmoothFields()));
99
100     smoothbutton = new QRadioButton( executebuttongroup2, "smoothbutton" );
101     smoothbutton->setGeometry( QRect( 10, 40, 110, 30 ) ); 
102     smoothbutton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, smoothbutton->sizePolicy().hasHeightForWidth() ) );
103     smoothbutton->setMinimumSize( QSize( 110, 30 ) );
104     smoothbutton->setMaximumSize( QSize( 110, 30 ) );
105     smoothbutton->setText( tr( "SMOOTH" ) );
106     QObject::connect(smoothbutton,SIGNAL(clicked()),this,SLOT(activateContourSmoothFields()));
107
108     nonebutton2 = new QRadioButton( executebuttongroup2, "nonebutton2" );
109     nonebutton2->setGeometry( QRect( 10, 70, 130, 24 ) ); 
110     nonebutton2->setText( tr( "NONE" ) );
111     nonebutton2->setChecked(true);
112     QObject::connect(nonebutton2,SIGNAL(clicked()),this,SLOT(activateContourSmoothFields()));
113
114     nameoftheexecution = new QLineEdit( this, "nameoftheexecution" );
115     nameoftheexecution->setGeometry( QRect( 30, 390, 350, 28 ) ); 
116
117     nameoftheexecutionlabel = new QLabel( this, "nameoftheexecutionlabel" );
118     nameoftheexecutionlabel->setGeometry( QRect( 110, 370, 180, 20 ) ); 
119     nameoftheexecutionlabel->setText( tr( "name_of_the_execution" ) );
120
121
122
123
124
125
126
127     algvariables = new QMultiLineEdit( this, "algvariables" );
128     algvariables->setGeometry( QRect( 30, 568, 350, 60 ) );
129
130     algvariableslabel = new QLabel( this, "algvariableslabel" );
131     algvariableslabel->setGeometry( QRect( 100, 535, 220, 20 ) ); 
132     algvariableslabel->setText( tr( "algorithm specific variables" ) );
133
134
135
136
137
138
139
140     threshold = new QLineEdit( this, "threshold" );
141     threshold->setGeometry( QRect( 30, 442, 80, 28 ) ); 
142     threshold->setEnabled(FALSE);
143
144     thresholdlabel = new QLabel( this, "thresholdlabel" );
145     thresholdlabel->setGeometry( QRect( 35, 422, 70, 20 ) ); 
146     thresholdlabel->setText( tr( "threshold" ) ); 
147     thresholdlabel->setEnabled(FALSE);
148
149     weight1 = new QLineEdit( this, "weight1" );
150     weight1->setGeometry( QRect( 120, 442, 80, 28 ) ); 
151     weight1->setEnabled(FALSE);
152
153     weight1label = new QLabel( this, "weight1label" );
154     weight1label->setGeometry( QRect( 130, 422, 60, 20 ) ); 
155     weight1label->setText( tr( "weight1" ) ); 
156     weight1label->setEnabled(FALSE);
157
158     weight2 = new QLineEdit( this, "weight2" );
159     weight2->setGeometry( QRect( 210, 442, 80, 28 ) ); 
160     weight2->setEnabled(FALSE);
161
162     weight2label = new QLabel( this, "weight2label" );
163     weight2label->setGeometry( QRect( 220, 422, 60, 20 ) ); 
164     weight2label->setText( tr( "weight2" ) );
165     weight2label->setEnabled(FALSE);
166
167     weight3 = new QLineEdit( this, "weight3" );
168     weight3->setGeometry( QRect( 300, 442, 80, 28 ) ); 
169     weight3->setEnabled(FALSE);
170
171     weight3label = new QLabel( this, "weight3label" );
172     weight3label->setGeometry( QRect( 310, 422, 60, 20 ) ); 
173     weight3label->setText( tr( "weight3" ) ); 
174     weight3label->setEnabled(FALSE);
175
176     iterationflaglabel = new QLabel( this, "iterationflaglinelabel" );
177     iterationflaglabel->setGeometry( QRect( 140, 482, 150, 20 ) ); 
178     iterationflaglabel->setText( tr( "iteration_flag_line" ) );
179     iterationflaglabel->setEnabled(FALSE);
180
181     iterationflagline = new QLineEdit( this, "iterationflagline" );
182     iterationflagline->setGeometry( QRect( 30, 502, 350, 28 ) ); 
183     iterationflagline->setEnabled(FALSE);
184
185     Line5 = new QFrame( this, "Line5" );
186     Line5->setGeometry( QRect( -15, 625, 450, 16 ) ); 
187     Line5->setFrameStyle( QFrame::HLine | QFrame::Sunken );
188
189     okbutton = new QPushButton( this, "okbutton" );
190     okbutton->setGeometry( QRect( 50, 645, 100, 40 ) ); 
191     okbutton->setText( tr( "OK" ) );
192     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
193
194     cancelbutton = new QPushButton( this, "cancelbutton" );
195     cancelbutton->setGeometry( QRect( 250, 645, 100, 40 ) ); 
196     cancelbutton->setText( tr( "Cancel" ) );
197     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
198 }
199
200 /**  
201  *  Destroys the object and frees any allocated resources
202  */
203 executewindow::~executewindow()
204 {
205     // no need to delete child widgets, Qt does it all for us
206 }
207
208
209 /** Activates type, algname and other fields 
210 @param void
211 @author Bruno M. Carvalho
212 @version 1.0 */
213 /* void executewindow::activateFields()
214 {
215   if(executebutton->isChecked()) {
216     executebuttongroup->setEnabled(TRUE);
217     zerobutton->setEnabled(TRUE);
218     averagebutton->setEnabled(TRUE);
219     continuebutton->setEnabled(TRUE);
220     nonebutton->setEnabled(TRUE);
221     algname->setEnabled(TRUE);
222     algnamelabel->setEnabled(TRUE);
223     executebuttongroup2->setEnabled(TRUE);
224     contourbutton->setEnabled(TRUE);
225     smoothbutton->setEnabled(TRUE);
226     nonebutton2->setEnabled(TRUE);
227     nameoftheexecution->setEnabled(TRUE);
228     nameoftheexecutionlabel->setEnabled(TRUE);
229     algvariables->setEnabled(TRUE); 
230     algvariableslabel->setEnabled(TRUE);
231   }
232   else {
233     executebuttongroup->setEnabled(FALSE);
234     zerobutton->setEnabled(FALSE);
235     averagebutton->setEnabled(FALSE);
236     continuebutton->setEnabled(FALSE);
237     nonebutton->setEnabled(FALSE);
238     algname->setEnabled(FALSE);
239     algnamelabel->setEnabled(FALSE);
240     executebuttongroup2->setEnabled(FALSE);
241     contourbutton->setEnabled(FALSE);
242     smoothbutton->setEnabled(FALSE);
243     nonebutton2->setEnabled(FALSE);
244     nameoftheexecution->setEnabled(FALSE);
245     nameoftheexecutionlabel->setEnabled(FALSE); 
246     algvariables->setEnabled(FALSE); 
247     algvariableslabel->setEnabled(FALSE);
248     threshold->setEnabled(FALSE);
249     thresholdlabel->setEnabled(FALSE);
250     weight1->setEnabled(FALSE);
251     weight1label->setEnabled(FALSE);
252     weight2->setEnabled(FALSE);
253     weight2label->setEnabled(FALSE);
254     weight3->setEnabled(FALSE);
255     weight3label->setEnabled(FALSE);
256     iterationflagline->setEnabled(FALSE);
257     iterationflaglabel->setEnabled(FALSE);
258   }
259 }*/
260
261 /** Activates contour and smooth fields fields 
262 @param void
263 @author Bruno M. Carvalho
264 @version 1.0 */
265 void executewindow::activateContourSmoothFields()
266 {
267   if(contourbutton->isChecked() || smoothbutton->isChecked()) {
268     threshold->setEnabled(TRUE);
269     thresholdlabel->setEnabled(TRUE);
270     weight1->setEnabled(TRUE);
271     weight1label->setEnabled(TRUE);
272     weight2->setEnabled(TRUE);
273     weight2label->setEnabled(TRUE);
274     weight3->setEnabled(TRUE);
275     weight3label->setEnabled(TRUE);
276     iterationflagline->setEnabled(TRUE);
277     iterationflaglabel->setEnabled(TRUE);
278   }
279   else {
280     threshold->setEnabled(FALSE);
281     thresholdlabel->setEnabled(FALSE);
282     weight1->setEnabled(FALSE);
283     weight1label->setEnabled(FALSE);
284     weight2->setEnabled(FALSE);
285     weight2label->setEnabled(FALSE);
286     weight3->setEnabled(FALSE);
287     weight3label->setEnabled(FALSE);
288     iterationflagline->setEnabled(FALSE);
289     iterationflaglabel->setEnabled(FALSE);
290   }
291 }
292
293 /** Deactivates contour and smooth fields fields 
294 @param void
295 @author Bruno M. Carvalho
296 @version 1.0 */
297 void executewindow::deactivateContourSmoothFields()
298 {
299   if(nonebutton2->isChecked()) {
300     threshold->setEnabled(FALSE);
301     thresholdlabel->setEnabled(FALSE);
302     weight1->setEnabled(FALSE);
303     weight1label->setEnabled(FALSE);
304     weight2->setEnabled(FALSE);
305     weight2label->setEnabled(FALSE);
306     weight3->setEnabled(FALSE);
307     weight3label->setEnabled(FALSE);
308     iterationflagline->setEnabled(FALSE);
309     iterationflaglabel->setEnabled(FALSE);
310   }
311   else {
312     threshold->setEnabled(TRUE);
313     thresholdlabel->setEnabled(TRUE);
314     weight1->setEnabled(TRUE);
315     weight1label->setEnabled(TRUE);
316     weight2->setEnabled(TRUE);
317     weight2label->setEnabled(TRUE);
318     weight3->setEnabled(TRUE);
319     weight3label->setEnabled(TRUE);
320     iterationflagline->setEnabled(TRUE);
321     iterationflaglabel->setEnabled(TRUE);
322   }
323 }
324
325 /** Returns a string for EXECUTE input sequence
326 @param void
327 @return execute
328 @author Bruno M. Carvalho
329 @version 1.0 */
330 QString executewindow::getOutput()
331 {
332   QString output;
333
334   output.sprintf("EXECUTE ");
335   if(zerobutton->isChecked()) {
336     output.append("ZERO ");
337   }
338   else
339     if(averagebutton->isChecked()) {
340       output.append("AVERAGE ");
341     }
342     else
343       if(continuebutton->isChecked()) {
344         output.append("CONTINUE ");
345       }
346       else
347         if(phantombutton->isChecked()) {
348           output.append("PHANTOM ");
349         }
350   output+=algname->text();
351   output.append(" ");
352   if(contourbutton->isChecked()) {
353     output.append("CONTOUR ");
354   }
355   else
356     if(smoothbutton->isChecked()) {
357       output.append("SMOOTH ");
358     }
359   output.append("\n");
360   output+=nameoftheexecution->text();
361 //  if(strcmp(algvariables->text(),"")) {
362 //    output.append("\n");
363 //    output+=algvariables->text();
364 //  }
365   //output.append("\n");
366   if(contourbutton->isChecked() || smoothbutton->isChecked()) {
367     output.append("\n");
368     output+=threshold->text();
369     output.append(" ");
370     output+=weight1->text();
371     output.append(" ");
372     output+=weight2->text();
373     output.append(" ");
374     output+=weight3->text();
375     output.append("\n");
376     output+=iterationflagline->text();
377     //output.append("\n");
378   } 
379   
380     if(strcmp(algvariables->text(),"")) {
381     output.append("\n");
382     output+=algvariables->text();
383   }
384   return output;
385 }
386
387 void executewindow::checkValues()
388 {
389   int f=0,cmp,alg;
390   float t,w1,w2,w3;
391   const char *str;
392   char str1[5];
393
394   str=(const char *)algname->text();
395   str1[0]=stolower(str[0]);
396   str1[1]=stolower(str[1]);
397   str1[2]=stolower(str[2]);
398   str1[3]=stolower(str[3]);
399   str1[4]=0;
400         //  cmp=strcmp(str1,"alg1");
401         //cmp=strcmp(str1,"algp");     // SI bug 113 fix
402         cmp=strcmp(str1,"alp1"); // bug 267, Ran
403         if(!cmp) alg=1;
404         else {
405                 //    cmp=strcmp(str1,"alg2");
406                 //cmp=strcmp(str1,"algb");   // SI bug 113 fix
407                 cmp=strcmp(str1,"alb1"); // bug 267, Ran
408                 if(!cmp) alg=2;
409                 else {
410                         cmp=strcmp(str1,"alts");
411                         if(!cmp) alg=3;
412                         else {
413                                 cmp=strcmp(str1,"art");
414                                 if(!cmp) alg=4;
415                                 else {
416                                         cmp=strcmp(str1,"back");
417                                         if(!cmp) alg=5;
418                                         else {
419                                                 cmp=strcmp(str1,"conv");
420                                                 if(!cmp) alg=6;
421                                                 else {
422                                                         cmp=strcmp(str1,"dcon");
423                                                         if(!cmp) alg=7;
424                                                         else {
425                                                                 cmp=strcmp(str1,"emap");
426                                                                 if(!cmp) alg=8;
427                                                                 else {
428                                                                         cmp=strcmp(str1,"four");
429                                                                         if(!cmp) alg=9;
430                                                                         else {
431                                                                                 cmp=strcmp(str1,"lino");
432                                                                                 if(!cmp) alg=10;
433                                                                                 else {
434                                                                                         cmp=strcmp(str1,"mart");
435                                                                                         if(!cmp) alg=11;
436                                                                                         else {
437                                                                                                 cmp=strcmp(str1,"mspb");
438                                                                                                 if(!cmp) alg=12;
439                                                                                                 else {
440                                                                                                         cmp=strcmp(str1,"quad");
441                                                                                                         if(!cmp) alg=13;
442                                                                                                         else {
443                                                                                                                 cmp=strcmp(str1,"rfl");
444                                                                                                                 if(!cmp) alg=14;
445                                                                                                                 else {
446                                                                                                                         cmp=strcmp(str1,"sirt");
447                                                                                                                         if(!cmp) alg=15;
448                                                                                                                         else {
449                                                                                                                                 cmp=strcmp(str1,"alp2");
450                                                                                                                                 if(!cmp) alg=16;
451                                                                                                                                 else {
452                                                                                                                                         cmp=strcmp(str1,"alp3");
453                                                                                                                                         if(!cmp) alg=17;
454                                                                                                                                         else {
455                                                                                                                                                 cmp=strcmp(str1,"alp4");
456                                                                                                                                                 if(!cmp) alg=18;
457                                                                                                                                                 else {
458                                                                                                                                                         cmp=strcmp(str1,"alp5");
459                                                                                                                                                         if(!cmp) alg=19;
460                                                                                                                                                         else {
461                                                                                                                                                                 cmp=strcmp(str1,"alb2");
462                                                                                                                                                                 if(!cmp) alg=20;
463                                                                                                                                                                 else {
464                                                                                                                                                                         cmp=strcmp(str1,"alb3");
465                                                                                                                                                                         if(!cmp) alg=21;
466                                                                                                                                                                         else {
467                                                                                                                                                                                 cmp=strcmp(str1,"alb4");
468                                                                                                                                                                                 if(!cmp) alg=22;
469                                                                                                                                                                                 else {
470                                                                                                                                                                                         cmp=strcmp(str1,"alb5");
471                                                                                                                                                                                         if(!cmp) alg=23;
472                                                                                                                                                                                         else {
473                                                                                                                                                                                                 cmp=strcmp(str1,"sart");
474                                                                                                                                                                                                 if(!cmp) alg=23;
475                                                                                                                                                                                                 else f=1;
476                                                                                                                                                                                         }
477                                                                                                                                                                                 }
478                                                                                                                                                                         }
479                                                                                                                                                                 }
480                                                                                                                                                         }
481                                                                                                                                                 }
482                                                                                                                                         }
483                                                                                                                                 }
484                                                                                                                         }
485                                                                                                                 }
486                                                                                                         }
487                                                                                                 }
488                                                                                         }
489                                                                                 }
490                                                                         }
491                                                                 }
492                                                         }
493                                                 }
494                                         }
495                                 }
496                         }
497                 }
498         }
499   if(contourbutton->isChecked() || smoothbutton->isChecked()) {
500     t=strtof((const char *)threshold->text());
501     if(errnum) 
502       f=2;
503     w1=strtof((const char *)weight1->text());
504     if(errnum) 
505       f=3;
506     w2=strtof((const char *)weight2->text());
507     if(errnum) 
508       f=4;
509     w3=strtof((const char *)weight3->text());
510     if(errnum) 
511       f=5;
512     if(!isintspace(iterationflagline->text()))
513       f=6;
514   }
515
516   switch(f) {
517   case 0: accept();
518     break;
519   case 1: QMessageBox::information(this,"SnarkInput","Error!\n"
520                                    "Invalid algorithm name.Algorithm name must be one of:\n"
521   // SI bug 113 fix  alg1 -> algp ; alg2 -> algb
522                                                                    // "ALG1, ALG2, ALTSCHULER, ART, BACKPROJECTION,\n"
523   // Ran, bug 267  added ALP1 - ALP5 and ALB1 - ALB5
524                                                                    //"ALGP, ALGB, ALTSCHULER, ART, BACKPROJECTION,\n"
525                                                                    "ALP1, ALP2, ALP3, ALP4, ALP5, ALB1, ALB2, \n"
526                                                                    "ALB3, ALB4, ALB5, ALTSCHULER, ART, \n"
527                                                                    "BACKPROJECTION,CONVOLUTION, DCONV, EMAP,\n"
528                                    "FOURIER, LINO, MART, MSPB, QUAD, RFL, SART or SIRT");    break;
529   case 2: QMessageBox::information(this,"SnarkInput","Error!\n"
530                                    "Invalid threshold format.");
531           threshold->setFocus();
532     break;
533   case 3: QMessageBox::information(this,"SnarkInput","Error!\n"
534                                    "Invalid weight1 format.");
535           weight1->setFocus();
536     break;
537   case 4: QMessageBox::information(this,"SnarkInput","Error!\n"
538                                    "Invalid weight2 format.");
539           weight2->setFocus();
540     break;
541   case 5: QMessageBox::information(this,"SnarkInput","Error!\n"
542                                    "Invalid weight3 format.");
543           weight3->setFocus();
544     break;
545   case 6: QMessageBox::information(this,"SnarkInput","Error!\n"
546                                    "iteration_flag_line must contain\n"
547                                    "only 0-9 and spaces and must\n"
548                                    "be non-empty");
549           iterationflagline->setFocus();
550     break;
551   }
552 }