Fixed text file permissions
[snark14.git] / tools / Display / linesimages.cpp
1 /** @file linesimages.cpp
2     @package snark14Display
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     modification: Joanna Klukowska 1/13/2009
8             added choice of grayScale display for plot
9             in addition to color display
10 */
11
12 #include "linesimages.hpp"
13 #include "selectimages.hpp"
14 #include "variables.hpp"
15
16 #include <stdio.h>
17 #include <malloc.h>
18 #include <qcombobox.h>
19 #include <qframe.h>
20 #include <qlabel.h>
21 #include <qlineedit.h>
22 #include <q3listbox.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
25 #include <qlayout.h>
26 #include <qvariant.h>
27 #include <qtooltip.h>
28 #include <qwhatsthis.h>
29 #include <qmessagebox.h>
30
31 extern Snarkimage **imageset;
32
33 /*  "Lines" (plotting of pixel values in a row or column) dialog for multiple images
34  *  Constructs a linesimageswindow which is a child of 'parent', with the 
35  *  name 'name' and widget flags set to 'fl'
36  *
37  *  The dialog will by default be modeless, unless you set 'modal' to
38  *  TRUE to construct a modal dialog.
39  */
40 linesimageswindow::linesimageswindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
41     : QDialog( parent, name, modal, fl )
42 {    if ( !name )
43         setName( "lineswindow" );
44     resize( 340, 550 ); 
45     setMinimumSize( QSize( 340, 550 ) );
46     setMaximumSize( QSize( 340, 550 ) );
47     setCaption( tr( "Multiple Images Profile" ) );
48     selected=false;
49     minval=globalmin;
50     maxval=globalmax;
51     rowcolbox = new QListBox( this, "rowcolbox" );
52     rowcolbox->insertItem( tr( "rows" ) ); // rows first. => 0 => false  [ x-axis == columns ] [sic]
53     rowcolbox->insertItem( tr( "columns" ) );   // columns later => 1 => true [ x-axis == rows ] [sic]
54     rowcolbox->setGeometry( QRect( 20, 10, 80, 50 ) );
55     rowcolbox->setSelectionMode(QListBox::Single); 
56     rowcolbox->setSelected(0,true);
57     QObject::connect(rowcolbox,SIGNAL(highlighted(int)),this,SLOT(updateXAxis(int)));
58     imagesbutton = new QPushButton( this, "imagesbutton" );
59     imagesbutton->setGeometry( QRect( 130, 20, 140, 40 ) ); 
60     imagesbutton->setText( tr( "Select Images" ) );
61     QObject::connect(imagesbutton,SIGNAL(clicked()),this,SLOT(callSelectImages()));
62
63     line1 = new QLineEdit( this, "line1" );
64     line1->setGeometry( QRect( 20, 90, 60, 30 ) ); 
65     line2 = new QLineEdit( this, "line2" );
66     line2->setGeometry( QRect( 100, 90, 60, 30 ) ); 
67     line3 = new QLineEdit( this, "line3" );
68     line3->setGeometry( QRect( 180, 90, 60, 30 ) ); 
69     line4 = new QLineEdit( this, "line4" );
70     line4->setGeometry( QRect( 260, 90, 60, 30 ) ); 
71
72     label1 = new QLabel( this, "label1" );
73     label1->setGeometry( QRect( 33, 70, 35, 20 ) ); 
74     label1->setText( tr( "row1" ) );
75     label2 = new QLabel( this, "label2" );
76     label2->setGeometry( QRect( 113, 70, 35, 20 ) ); 
77     label2->setText( tr( "row2" ) );
78     label3 = new QLabel( this, "label3" );
79     label3->setGeometry( QRect( 193, 70, 35, 20 ) ); 
80     label3->setText( tr( "row3" ) );
81     label4 = new QLabel( this, "label4" );
82     label4->setGeometry( QRect( 273, 70, 35, 20 ) ); 
83     label4->setText( tr( "row4" ) );
84
85     title =  new QLineEdit( this, "title" );
86     title->setGeometry( QRect( 20, 150, 300, 30 ) );
87     QString nameprojQStr = nameproj;
88     title->setText(nameprojQStr.simplifyWhiteSpace());
89     titlelabel = new QLabel( this, "titlelabel" );
90     titlelabel->setGeometry( QRect( 160, 130, 60, 20 ) ); 
91     titlelabel->setText( tr( "Title" ) );
92
93 //      subtitle =  new QComboBox( this, "subtitle" );
94 //      subtitle->setGeometry( QRect( 20, 210, 140, 30 ) );
95 //      subtitle->insertItem("Column/Line #",-1);
96 //      subtitle->insertItem("Empty",-1);
97 //      subtitlelabel = new QLabel( this, "subtitlelabel" );
98 //      subtitlelabel->setGeometry( QRect( 60, 190, 100, 20 ) ); 
99 //      subtitlelabel->setText( tr( "Subtitle" ) );
100
101 //      gridstyle = new QComboBox(this,"gridstyle");
102 //      gridstyle->setGeometry( QRect( 180, 210, 140, 30 ) ); 
103 //      gridstyle->insertItem("Solid",-1);
104 //      gridstyle->insertItem("None",-1);
105 //      gridstyle->insertItem("Dash",-1);
106 //      gridstyle->insertItem("Dot",-1);
107
108 //      gridstylelabel = new QLabel( this, "gridstylelabel" );
109 //      gridstylelabel->setGeometry( QRect( 210, 190, 210, 20 ) ); 
110 //      gridstylelabel->setText( tr( "Grid Style" ) );
111
112     xaxis =  new QLineEdit( this, "xaxis" );
113     xaxis->setEnabled(false); // user doesn't change it
114     xaxis->setGeometry( QRect( 20, 240, 140, 30 ) );
115     xaxis->setText("Columns"); // default setting
116
117     yaxis =  new QLineEdit( this, "yaxis" );
118     yaxis->setEnabled(false);
119     yaxis->setGeometry( QRect( 180, 240, 140, 30 ) );
120     yaxis->setText("Pixel Values");
121
122     xaxislabel = new QLabel( this, "xaxislabel" );
123     xaxislabel->setGeometry( QRect( 70, 220, 60, 20 ) );
124     xaxislabel->setText( tr( "X Axis" ) );
125
126     yaxislabel = new QLabel( this, "yaxislabel" );
127     yaxislabel->setGeometry( QRect( 230, 220, 60, 20 ) );
128     yaxislabel->setText( tr( "Y Axis" ) );
129
130     minx = new QLineEdit( this, "minx" );
131     minx->setGeometry( QRect( 20, 300, 140, 30 ) );
132     minx->setText("0");
133
134     QString s;
135     s.setNum(Sizex-1);
136     maxx = new QLineEdit( this, "maxx" );
137     maxx->setGeometry( QRect( 180, 300, 140, 30 ) );
138     maxx->setText(s);
139
140     s.setNum(globalmin);
141     miny = new QLineEdit( this, "miny" );
142     miny->setGeometry( QRect( 20, 360, 140, 30 ) );
143     miny->setText(s);
144
145     s.setNum(globalmax);
146     maxy = new QLineEdit( this, "maxy" );
147     maxy->setGeometry( QRect( 180, 360, 140, 30 ) );
148     maxy->setText(s);
149
150     minxlabel = new QLabel( this, "minxlabel" );
151     minxlabel->setGeometry( QRect( 60, 280, 60, 20 ) );
152     minxlabel->setText( tr( "Min Col" ) ); // OK, so shoot me for hardcoding
153
154     maxxlabel = new QLabel( this, "maxxlabel" );
155     maxxlabel->setGeometry( QRect( 220, 280, 60, 20 ) );
156     maxxlabel->setText( tr( "Max Col" ) );
157
158     minylabel = new QLabel( this, "minylabel" );
159     minylabel->setGeometry( QRect( 70, 340, 60, 20 ) );
160     minylabel->setText( tr( "Min Y" ) );
161
162     maxylabel = new QLabel( this, "maxylabel" );
163     maxylabel->setGeometry( QRect( 230, 340, 60, 20 ) );
164     maxylabel->setText( tr( "Max Y" ) );
165
166
167     // jk 1/13/2009 adding grayScale option for graphs
168     // jklukowska 6/7/2009 modified to be radio button with option of either
169     // color or grayscale
170     colorbuttongroup = new QButtonGroup(this, "colorbuttongroup");
171     colorbuttongroup->setTitle(tr("Draw graphs in "));
172     colorbuttongroup->setGeometry(QRect(0, 400, 340, 75));
173     colorbuttongroup->setAlignment(int( QButtonGroup::AlignHCenter));
174     grayScaleButton = new QRadioButton(colorbuttongroup, "grayScaleButton");
175     grayScaleButton->setGeometry(QRect(30, 25, 130, 20));
176     grayScaleButton->setText(tr("  grayscale"));
177     grayScaleButton->setEnabled(true);
178     grayScaleButton->setChecked(false);
179     colorButton = new QRadioButton(colorbuttongroup, "colorButton");
180     colorButton->setGeometry(QRect(190, 25, 130, 20));
181     colorButton->setText(tr(" color"));
182     colorButton->setEnabled(true);
183     colorButton->setChecked(true);
184
185     //Line3 = new QFrame( this, "Line3" );
186     //Line3->setGeometry( QRect( 0, 485, 340, 16 ) ); 
187     //Line3->setFrameStyle( QFrame::HLine | QFrame::Sunken );
188
189     showbutton = new QPushButton( this, "showbutton" );
190     showbutton->setGeometry( QRect( 20, 490, 100, 40 ) ); 
191     showbutton->setText( tr( "Show" ) );
192     QObject::connect(showbutton,SIGNAL(clicked()),this,SLOT(checkAndAccept()));
193
194     cancelbutton = new QPushButton( this, "cancelbutton" );
195     cancelbutton->setGeometry( QRect( 220, 490, 100, 40 ) ); 
196     cancelbutton->setText( tr( "Cancel" ) );
197     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject())); 
198 } // --linesimageswindow ctor
199
200 /*  
201  *  Destroys the object and frees any allocated resources
202  */
203 linesimageswindow::~linesimageswindow()
204 {
205     // no need to delete child widgets, Qt does it all for us
206 }
207
208 /** 
209 @param void
210 @author Bruno M. Carvalho
211 @version 1.0 */ 
212 void linesimageswindow::updateXAxis(int i) // i is 1 for row, 0 for cols
213 {
214   if(i==0) { // so x axis is the other.
215     label1->setText("row1");
216     label2->setText("row2");
217     label3->setText("row3");
218     label4->setText("row4");
219     xaxis->setText("Columns");
220     minxlabel->setText("Min Col");
221     maxxlabel->setText("Max Col");
222   } else {
223     label1->setText("col1");
224     label2->setText("col2");
225     label3->setText("col3");
226     label4->setText("col4");
227     xaxis->setText("Rows");
228     minxlabel->setText("Min Row");
229     maxxlabel->setText("Max Row");
230   }
231 } // --linesimageswindow::updateXAxis()
232
233 /** Starts a window for selecting the images to be shownfor a lines command
234 @param void
235 @author Bruno M. Carvalho
236 @version 1.0 */ 
237 void linesimageswindow::callSelectImages() 
238 {
239   int i,*siarray;
240   QString s;
241
242   selectimageswindow* nw=new selectimageswindow(this,"Select Images for Line Displaying",true);
243   int c=nw->exec();
244   if(c==QDialog::Accepted) {
245     siarray=nw->getSelectedImages();
246     if(siarray[0]==0 && !phantombutton->isChecked()) 
247       QMessageBox::information(this,"SnarkDisplay","Warning!\n"
248                                "No image was selected.\n");
249     else {
250       selected=true;
251       selectedimages = (int*) malloc((unsigned) (siarray[0]+1)*sizeof(int));
252       if(!selectedimages) {
253         QMessageBox::information(this,"SnarkDisplay","Error!\n"
254                               "Allocation failure in getSelectedImages()\n");
255       }
256       else {
257         selectedimages[0]=siarray[0];
258         for(i=1;i<=siarray[0];i++) {
259           selectedimages[i]=siarray[i];
260           if(!imageset[siarray[i]]->isLoaded())
261             imageset[siarray[i]]->readImage(siarray[i],dataformat);
262         }
263       }
264     }
265     /*   s.sprintf("%f",globalmin);
266     miny->setText(s);
267     s.sprintf("%f",globalmax);
268     maxy->setText(s);  */
269   }
270 }
271
272 /** 
273 @param void
274 @author Bruno M. Carvalho
275 @version 1.0 */ 
276 int* linesimageswindow::getSelectedImages()
277 {
278   return selectedimages;
279 }
280
281 /** 
282 @param void
283 @author Bruno M. Carvalho
284 @version 1.0 */ 
285 int linesimageswindow::getLinetype()
286 {
287   return rowcolbox->currentItem();
288 }
289
290 /** 
291 @param void
292 @author Bruno M. Carvalho
293 @version 1.0 */ 
294 int linesimageswindow::getLine1()
295 {
296   int l;
297   bool ok;
298   l=line1->text().toInt(&ok,10);
299   if(ok) 
300     return l;
301   else
302     return NaI;
303 }
304
305 /** 
306 @param void
307 @author Bruno M. Carvalho
308 @version 1.0 */ 
309 int linesimageswindow::getLine2()
310 {
311   int l;
312   bool ok;
313   l=line2->text().toInt(&ok,10);
314   if(ok) 
315     return l;
316   else
317     return NaI;
318 }
319
320 /** 
321 @param void
322 @author Bruno M. Carvalho
323 @version 1.0 */ 
324 int linesimageswindow::getLine3()
325 {
326   int l;
327   bool ok;
328   l=line3->text().toInt(&ok,10);
329   if(ok) 
330     return l;
331   else
332     return NaI;
333 }
334
335 /** 
336 @param void
337 @author Bruno M. Carvalho
338 @version 1.0 */ 
339 int linesimageswindow::getLine4()
340 {
341   int l;
342   bool ok;
343   l=line4->text().toInt(&ok,10);
344   if(ok) 
345     return l;
346   else
347     return NaI;
348 }
349
350
351 /** 
352 @param void
353 @author Bruno M. Carvalho
354 @version 1.0 */ 
355 bool linesimageswindow::isPhantomChecked()
356 {
357   if(phantombutton->isChecked())
358     return true;
359   else
360     return false;
361 }
362
363 /** 
364 @param void
365 @author Bruno M. Carvalho
366 @version 1.0 */ 
367 QString linesimageswindow::getTitle()
368 {
369   return title->text();
370 }
371
372 //  /** 
373 //  @param void
374 //  @author Bruno M. Carvalho
375 //  @version 1.0 */ 
376 //  int linesimageswindow::getSubtitle()
377 //  {
378 //    return subtitle->currentItem();
379 //  }
380
381 //  /** 
382 //  @param void
383 //  @author Bruno M. Carvalho
384 //  @version 1.0 */ 
385 //  int linesimageswindow::getGridstyle()
386 //  {
387 //    return gridstyle->currentItem();
388 //  }
389
390 /** 
391 @param void
392 @author Bruno M. Carvalho
393 @version 1.0 */ 
394 QString linesimageswindow::getXAxis()
395 {
396   return xaxis->text();
397 }
398
399 /** 
400 @param void
401 @author Bruno M. Carvalho
402 @version 1.0 */ 
403 QString linesimageswindow::getYAxis()
404 {
405   return yaxis->text();
406 }
407
408
409 /** 
410 @param void
411 @author Bruno M. Carvalho
412 @version 1.0 */ 
413 int linesimageswindow::getMinX()
414 {
415   bool ok;
416   int t;
417   t=minx->text().toInt(&ok,10);
418   if(ok)
419     return t;
420   else 
421     return 0;
422 }
423
424 /** 
425 @param void
426 @author Bruno M. Carvalho
427 @version 1.0 */ 
428 int linesimageswindow::getMaxX()
429 {
430   bool ok;
431   int t;
432   t=maxx->text().toInt(&ok,10);
433   if(ok)
434     return t;
435   else 
436     return Sizex-1;
437 }
438
439
440 /** 
441 @param void
442 @author Bruno M. Carvalho
443 @version 1.0 */ 
444 double linesimageswindow::getMinY()
445 {
446   bool ok;
447   double t;
448   t=miny->text().toDouble(&ok);
449   if(ok)
450     return t;
451   else 
452     return minval;
453 }
454
455 /** 
456 @param void
457 @author Bruno M. Carvalho
458 @version 1.0 */ 
459 double linesimageswindow::getMaxY()
460 {
461   bool ok;
462   double t;
463   t=maxy->text().toDouble(&ok);
464   if(ok)
465     return t;
466   else 
467     return maxval;
468 }
469
470 void linesimageswindow::checkAndAccept()
471 {
472   if(selected) {
473     accept();
474   }
475   else {
476     QMessageBox::information(this,"SnarkDisplay","Error!\n"
477                              "No image was selected.\n");
478   }
479 }
480
481 /**
482 @param void
483 @author Joanna Klukowska (added 1/13/2009)
484 @version 1.0 */
485 bool linesimageswindow::isGrayScaleChecked() {
486     return (grayScaleButton->isChecked());
487 }