UltraScan III
us_fds_filemanager.cpp
Go to the documentation of this file.
1 
3 #include <QApplication>
4 #include <QDomDocument>
5 
6 #include "us_fds_filemanager.h"
7 #include "us_license_t.h"
8 #include "us_license.h"
9 #include "us_settings.h"
10 #include "us_gui_settings.h"
11 #include "us_util.h"
12 #include "us_passwd.h"
13 #include "us_db2.h"
14 
15 #ifndef DbgLv
16 #define DbgLv(a) if(dbg_level>=a)qDebug()
17 #endif
18 
20 //user to filter useful files from FDS runs where multiple gains and speeds were collected.
21 
22 int main( int argc, char* argv[] )
23 {
24  QApplication application( argc, argv );
25 
26  #include "main1.inc"
27 
28  // License is OK. Start up.
29 
31  w.show();
32  return application.exec();
33 }
34 
35 // Constructor
37 {
38  setWindowTitle( tr( "Fluorescence Data File Manager" ) );
39  setPalette( US_GuiSettings::frameColor() );
40 
41  QVBoxLayout* top = new QVBoxLayout( this );
42  top->setSpacing ( 2 );
43  top->setContentsMargins ( 2, 2, 2, 2 );
44 
45  // Put the Run Info across the entire window
46  QHBoxLayout* runInfo = new QHBoxLayout();
47  QLabel* lb_info = us_label( tr( "Dataset Info:" ), -1 );
48  runInfo->addWidget( lb_info );
49 
50  le_info = us_lineedit( "", 1, true );
51  le_info->setReadOnly(true);
52  runInfo->addWidget( le_info );
53 
54  top->addLayout( runInfo );
55 
56  QHBoxLayout* main = new QHBoxLayout();
57  QVBoxLayout* left = new QVBoxLayout;
58 
59  // Start of Grid Layout
60  QGridLayout* specs = new QGridLayout;
61  int s_row = 0;
62 
63  // Row 1
64  // Investigator
65 
66  QPushButton* pb_load = us_pushbutton( tr( "Load Data" ) );
67  connect( pb_load, SIGNAL( clicked() ), SLOT( load() ) );
68  specs->addWidget( pb_load, s_row, 0, 1, 1 );
69 
70  le_directory = us_lineedit( "" );
71  le_directory->setReadOnly(true);
72  specs->addWidget( le_directory, s_row++, 1, 1, 3 );
73 
74  QLabel* lbl_progress = us_label( tr( "Progress:" ), -1 );
75  lbl_progress->setAlignment( Qt::AlignLeft );
76  specs->addWidget( lbl_progress, s_row, 0, 1, 1 );
77 
78  progress = us_progressBar( 0, 100, 0 );
79  specs->addWidget( progress, s_row++, 1, 1, 3 );
80 
81  QLabel* lb_triple = us_label( tr( "Cell / Channel / Wavelength:" ), -1 );
82  specs->addWidget( lb_triple, s_row, 0, 1, 2 );
83 
85  specs->addWidget( cb_triple, s_row++, 2, 1, 2 );
86 
87  lbl_rpms = us_label( tr( "Speed Step (RPM) of triple:" ), -1 );
88  specs->addWidget( lbl_rpms, s_row, 0, 1, 2 );
89 
90  cb_rpms = us_comboBox();
91  specs->addWidget( cb_rpms, s_row++, 2, 1, 2 );
92 
93  lbl_gains = us_label( tr( "Gain Setting:" ), -1 );
94  specs->addWidget( lbl_gains, s_row, 0, 1, 2 );
95 
97  specs->addWidget( cb_gains, s_row++, 2, 1, 2 );
98 
99  lbl_scans = us_label( tr( "Scans in active Selection:" ), -1 );
100  specs->addWidget( lbl_scans, s_row, 0, 1, 2 );
101 
102  le_scans = us_lineedit( "" );
103  le_scans->setReadOnly(true);
104  specs->addWidget( le_scans, s_row++, 2, 1, 2 );
105 
106  // Scans focus from:
107  lbl_from = us_label( tr( "Scan Focus from:" ), -1 );
108  //lbl_from->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
109  specs->addWidget( lbl_from, s_row, 0, 1, 2 );
110 
111  ct_from = us_counter ( 3, 0.0, 0.0 ); // Update range upon load
112  ct_from->setStep( 1 );
113  specs->addWidget( ct_from, s_row++, 2, 1, 2 );
114  connect( ct_from, SIGNAL( valueChanged ( double ) ),
115  SLOT ( focus_from ( double ) ) );
116 
117  // Scan focus to
118  lbl_to = us_label( tr( "Scan Focus to:" ), -1 );
119  //lbl_to->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
120  specs->addWidget( lbl_to, s_row, 0, 1, 2 );
121 
122  ct_to = us_counter ( 3, 0.0, 0.0 ); // Update range upon load
123  ct_to->setStep( 1 );
124  specs->addWidget( ct_to, s_row++, 2, 1, 2 );
125  connect( ct_to , SIGNAL( valueChanged ( double ) ),
126  SLOT ( focus_to ( double ) ) );
127 
128  // Exclude and Include pushbuttons
129  pb_exclude = us_pushbutton( tr( "Delete marked Scan(s)" ), false );
130  specs->addWidget( pb_exclude, s_row, 0, 1, 2 );
131  connect( pb_exclude, SIGNAL( clicked() ),
132  SLOT( exclude_scans() ) );
133 
134  pb_delete_all = us_pushbutton( tr( "Delete all Scans" ), false );
135  specs->addWidget( pb_delete_all, s_row++, 2, 1, 2 );
136  connect( pb_delete_all, SIGNAL( clicked() ),
137  SLOT( delete_all() ) );
138 
139  pb_save_first = us_pushbutton( tr( "Save first Scan" ), false );
140  specs->addWidget( pb_save_first, s_row, 0, 1, 2 );
141  pb_save_first ->setEnabled( false );
142  connect( pb_save_first, SIGNAL( clicked() ),
143  SLOT( save_first() ) );
144 
145  pb_save_last = us_pushbutton( tr( "Save last Scan" ), false );
146  specs->addWidget( pb_save_last, s_row++, 2, 1, 2 );
147  pb_save_last ->setEnabled( false );
148  connect( pb_save_last, SIGNAL( clicked() ),
149  SLOT( save_last() ) );
150 
151  pb_save_first_and_last = us_pushbutton( tr( "Save first and last Scan" ), false );
152  specs->addWidget( pb_save_first_and_last, s_row, 0, 1, 2 );
153  pb_save_first_and_last ->setEnabled( false );
154  connect( pb_save_first_and_last, SIGNAL( clicked() ),
155  SLOT( save_first_and_last() ) );
156 
157  pb_delete_triple = us_pushbutton( tr( "Delete Triple" ), false );
158  specs->addWidget( pb_delete_triple, s_row++, 2, 1, 2 );
159  pb_delete_triple ->setEnabled( false );
160  connect( pb_delete_triple, SIGNAL( clicked() ),
161  SLOT( delete_triple() ) );
162 
163  pb_undo = us_pushbutton( tr( "Undo last Delete" ), false );
164  specs->addWidget( pb_undo, s_row, 0, 1, 2 );
165  pb_undo ->setEnabled( false );
166  connect( pb_undo, SIGNAL( clicked() ),
167  SLOT( undo() ) );
168 
169  pb_write = us_pushbutton( tr( "Export File Selection" ), false );
170  connect( pb_write, SIGNAL( clicked() ), SLOT( write() ) );
171  specs->addWidget( pb_write, s_row++, 2, 1, 2 );
172 
173  // Modify export prefix:
174  lbl_prefix = us_label( tr( "Prefix for export Filename:" ), -1 );
175  //lbl_prefix->setAlignment( Qt::AlignVCenter | Qt::AlignLeft );
176  specs->addWidget( lbl_prefix, s_row, 0, 1, 2 );
177 
178  ct_prefix = us_counter ( 3, 0.0, 10000.0 );
179  ct_prefix->setStep( 1 );
180  specs->addWidget( ct_prefix, s_row++, 2, 1, 2 );
181  connect( ct_prefix, SIGNAL( valueChanged ( double ) ),
182  SLOT ( update_prefix( double ) ) );
183 
184  // Button rows
185  QBoxLayout* buttons = new QHBoxLayout;
186 
187  QPushButton* pb_reset = us_pushbutton( tr( "Reset" ) );
188  connect( pb_reset, SIGNAL( clicked() ), SLOT( reset() ) );
189  buttons->addWidget( pb_reset );
190 
191  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
192  connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
193  buttons->addWidget( pb_help );
194 
195  QPushButton* pb_accept = us_pushbutton( tr( "Close" ) );
196  connect( pb_accept, SIGNAL( clicked() ), SLOT( close() ) );
197  buttons->addWidget( pb_accept );
198 
199  // Plot layout on right side of window
200  plot = new US_Plot( data_plot,
201  tr( "Fluorescence Data" ),
202  tr( "Radius (in cm)" ), tr( "Fluorescence Intensity" ) );
203 
204  data_plot->setMinimumSize( 600, 400 );
205  data_plot->enableAxis( QwtPlot::xBottom, true );
206  data_plot->enableAxis( QwtPlot::yLeft , true );
207 
208  left->addLayout( specs );
209  left->addStretch();
210  left->addLayout( buttons );
211 
212  main->addLayout( left );
213  main->addLayout( plot );
214  main->setStretchFactor( plot, 3 );
215  top ->addLayout( main );
216 
217  reset();
218 }
219 
220 // Load an AUC data set
222 {
223  reset();
224  QFileDialog fd;
225  fd.setFileMode(QFileDialog::Directory);
226  source_dir = fd.getExistingDirectory( this,
227  tr( "Raw Data Directory" ),
229  QFileDialog::DontResolveSymlinks);
230 
231  source_dir.replace( "\\", "/" );
232 
233  if ( source_dir.isEmpty() ) // If no directory chosen, return now
234  {
235  return;
236  }
237  else
238  {
239  le_directory->setText(source_dir);
240  }
241 
242  QDir readDir( source_dir, "*.[F,f][I,i][1-8]", QDir::Name, QDir::Files | QDir::Readable );
243  readDir.makeAbsolute();
244  if ( source_dir.right( 1 ) != "/" ) source_dir += "/"; // Ensure trailing "/"
245  files = QDir( readDir ).entryList(
246  QDir::Files | QDir::NoDotAndDotDot, QDir::Name );
247  parse_files();
248 }
249 
250 // parse all selected files into scaninfo
252 {
253  cb_triple->disconnect();
254  cb_triple->clear();
255  scaninfo.clear();
256  QString line, str, str1, str2;
257  QStringList tokens, triplelist;
258  int i;
259  triplelist.clear();
260  for ( i=0; i<files.size(); i++)
261  {
262  tmp_scaninfo.filename = files.at(i);
263  if ( files.at(i).contains( "A", Qt::CaseInsensitive ) )
264  {
265  tmp_scaninfo.channel = "A";
266  }
267  else
268  {
269  tmp_scaninfo.channel = "B";
270  }
271  QFile f(source_dir + tmp_scaninfo.filename);
272  if ( f.open( QFile::ReadOnly ) )
273  {
274  QTextStream ts(&f);
275  line = ts.readLine();
276  tokens = line.split(" ", QString::SkipEmptyParts);
277  tmp_scaninfo.date = tokens.at(0);
278  tmp_scaninfo.time = tokens.at(1) + " " + tokens.at(2);
279  tmp_scaninfo.voltage = tokens.at(4).toInt();
280  tmp_scaninfo.gain = tokens.at(6).toInt();
281  tmp_scaninfo.range = tokens.at(8).toInt();
282  tmp_scaninfo.include = true;
283  tokens.clear();
284  line = ts.readLine();
285  tokens = line.split(" ", QString::SkipEmptyParts);
286  tmp_scaninfo.cell = tokens.at(1).toInt();
287  tmp_scaninfo.rpm = tokens.at(3).toInt();
288  tmp_scaninfo.seconds = tokens.at(4).toDouble();
289  tmp_scaninfo.omega_s = tokens.at(4).toDouble();
290  tmp_scaninfo.lambda = tokens.at(6).toInt();
291  tmp_scaninfo.triple = str1.setNum(tmp_scaninfo.cell) + " / " +
292  tmp_scaninfo.channel + " / " +
293  str2.setNum(tmp_scaninfo.lambda);
294  tmp_scaninfo.gainset = "V: " + str1.setNum(tmp_scaninfo.voltage) + ", G: " +
295  str.setNum(tmp_scaninfo.gain) + ", R: " +
296  str2.setNum(tmp_scaninfo.range);
297  tmp_scaninfo.include = true;
298  tmp_scaninfo.x.clear();
299  tmp_scaninfo.y.clear();
300  while (!ts.atEnd())
301  {
302  line = ts.readLine();
303  tokens.clear();
304  tokens = line.split(" ", QString::SkipEmptyParts);
305  tmp_scaninfo.x.append(tokens.at(0).toDouble() );
306  tmp_scaninfo.y.append(tokens.at(1).toDouble() );
307  }
308  }
309  triplelist.append(tmp_scaninfo.triple);
310  progress->setValue( 100 * ( i+1.0 )/files.size() );
311  scaninfo.append(tmp_scaninfo);
312  }
313  if (scaninfo.size() == 0)
314  {
315  QMessageBox::warning (this, tr( "Attention:" ),
316  tr( "The selected directory does not contain fluorescence files...\n"
317  "Please try again." ),
318  QMessageBox::Ok );
319  return;
320  }
321  triplelist.removeDuplicates();
322  triplelist.sort();
323  cb_triple->addItems( triplelist );
324  connect( cb_triple, SIGNAL( currentIndexChanged( int ) ),
325  SLOT ( select_triple ( int ) ) );
326  select_triple(cb_triple->currentIndex());
327 }
328 
329 // Select a new triple
331 {
332  cb_rpms->disconnect();
333  cb_rpms->clear();
334  current_triple = index;
335  QStringList rpmlist;
336  rpmlist.clear();
337  QString str;
338  for (int i=0; i<scaninfo.size(); i++)
339  {
340  if(scaninfo[i].triple == cb_triple->currentText() && scaninfo[i].include )
341  {
342  rpmlist.append(str.setNum(scaninfo[i].rpm));
343  }
344  }
345  rpmlist.removeDuplicates();
346  rpmlist.sort();
347  cb_rpms->addItems(rpmlist);
348  connect( cb_rpms, SIGNAL( currentIndexChanged( int ) ),
349  SLOT ( select_rpm ( int ) ) );
350  select_rpm(cb_rpms->currentIndex());
351 }
352 
353 // Select a new speed within a triple
355 {
356  cb_gains->disconnect();
357  cb_gains->clear();
358  current_rpm = index;
359  QStringList gainlist;
360  gainlist.clear();
361  QString str1;
362  gainlist.clear();
363  for (int i=0; i<scaninfo.size(); i++)
364  {
365  if(scaninfo[i].triple == cb_triple->currentText()
366  && str1.setNum( scaninfo[i].rpm ) == cb_rpms->currentText()
367  && scaninfo[i].include )
368  {
369  gainlist.append(scaninfo[i].gainset);
370  }
371  }
372  gainlist.removeDuplicates();
373  gainlist.sort();
374  cb_gains->addItems(gainlist);
375  connect( cb_gains, SIGNAL( currentIndexChanged( int ) ),
376  SLOT ( select_gain ( int ) ) );
377  select_gain(cb_gains->currentIndex());
378 }
379 
381 {
382  QString str, str1, str2, str3;
383  current_gain = index;
384  ct_from->disconnect();
385  ct_to->disconnect();
386  to = 0;
387  from = 0;
388  ct_from->setValue(0.0);
389  ct_to ->setValue(0.0);
390  connect( ct_from, SIGNAL( valueChanged ( double ) ),
391  SLOT ( focus_from ( double ) ) );
392  connect( ct_to, SIGNAL( valueChanged ( double ) ),
393  SLOT ( focus_to ( double ) ) );
394  le_info->setText( "Loaded " + str.setNum(scaninfo.size()) + " scans containing "
395  + str1.setNum(cb_triple->count())
396  + " triples. The current triple (" + cb_triple->currentText() + ") contains "
397  + str2.setNum(cb_rpms->count()) + " speed(s) and "
398  + str3.setNum(cb_gains->count()) + " gain setting(s)." );
399  plot_scans();
400 }
401 
402 // Plot a single scan curve
404 {
405  QString str1;
406  QList < QwtPlotCurve * > c;
407  c.clear();
408  scanindex.clear();
409  data_plot->clear();
410  for (int i=0; i<scaninfo.size(); i++)
411  {
412  if ( scaninfo[i].triple == cb_triple->currentText()
413  && scaninfo[i].rpm == cb_rpms ->currentText().toInt()
414  && scaninfo[i].gainset == cb_gains ->currentText()
415  && scaninfo[i].include )
416  {
417  scanindex.append(i);
418  }
419  }
420  ct_from->setMaxValue( scanindex.size() );
421  ct_to->setMaxValue( scanindex.size() );
422  int npts;
423  QwtPlotCurve *curve;
424  c.clear();
425  if (scanindex.size() == 1)
426  {
427  le_scans->setText( "1 scan" );
428  }
429  else
430  {
431  le_scans->setText( str1.setNum( scanindex.size() ) + " scans" );
432  }
433  for (int i=0; i<scanindex.size(); i++)
434  {
435  npts = scaninfo[scanindex[i]].x.size();
436  double x[npts], y[npts];
437  for (int j=0; j<npts; j++)
438  {
439  x[j] = scaninfo[scanindex[i]].x.at(j);
440  y[j] = scaninfo[scanindex[i]].y.at(j);
441  }
442  str1.setNum( i+1 );
443  curve = us_curve( data_plot, "Scan " + str1 );
444  curve->setData( x, y, npts );
445  c.append( curve );
446  if ( from == 0 && to == 0 )
447  { // all scans are yellow
448  curve->setPen( QPen( Qt::yellow ) );
449  }
450  else if (i >= from-1 && i <= to-1 )
451  {
452  curve->setPen( QPen( Qt::red ) );
453  }
454  else
455  {
456  curve->setPen( QPen( Qt::yellow ) );
457  }
458  data_plot->setAxisAutoScale( QwtPlot::yLeft );
459  data_plot->setAxisAutoScale( QwtPlot::xBottom );
460  }
461  data_plot->replot();
462  if (c.size() > 1)
463  {
464  pb_delete_all ->setEnabled ( true );
465  pb_save_first ->setEnabled ( true );
466  pb_save_last ->setEnabled ( true );
467  pb_save_first_and_last->setEnabled ( true );
468  pb_delete_triple ->setEnabled ( true );
469  }
470  else if (c.size() == 1)
471  {
472  pb_delete_all ->setEnabled ( true );
473  pb_save_first ->setEnabled ( false );
474  pb_save_last ->setEnabled ( false );
475  pb_save_first_and_last->setEnabled ( false );
476  pb_delete_triple ->setEnabled ( true );
477  }
478  else if (c.size() == 0)
479  {
480  pb_delete_all ->setEnabled ( false );
481  pb_save_first ->setEnabled ( false );
482  pb_save_last ->setEnabled ( false );
483  pb_save_first_and_last->setEnabled ( false );
484  pb_delete_triple ->setEnabled ( true );
485  }
486  pb_write->setEnabled ( true );
487 }
488 
489 // Reset parameters to their defaults
491 {
492  data_plot->setAxisScale( QwtPlot::xBottom, 5.7, 7.3 );
493  data_plot->setAxisScale( QwtPlot::yLeft , 0.0, 1.5 );
494  data_plot->clear();
495  data_plot->replot();
496 
497  ct_from ->setMinValue( 0 );
498  ct_from ->setMaxValue( 0 );
499  ct_from ->setValue ( 0 );
500  ct_to ->setMinValue( 0 );
501  ct_to ->setMaxValue( 0 );
502  ct_to ->setValue ( 0 );
503  ct_prefix->setValue ( 0 );
504 
505  prefix = "";
506 
507  progress ->setValue(0);
508  cb_triple ->clear();
509  cb_rpms ->clear();
510  cb_gains ->clear();
511  scaninfo .clear();
512  scanindex .clear();
513  tmp_scanindex.clear();
514 
515  pb_delete_all ->setEnabled ( false );
516  pb_save_first ->setEnabled ( false );
517  pb_save_last ->setEnabled ( false );
518  pb_save_first_and_last->setEnabled ( false );
519  pb_write ->setEnabled ( false );
520  pb_undo ->setEnabled ( false );
521 
522  le_scans ->setText( "" );
523  le_directory->setText( "" );
524  le_info ->setText( "" );
525 }
526 
527 // undo the latest delete action
529 {
530  if (undo_triple == "")
531  {
532  for (int i=0; i<tmp_scanindex.size(); i++)
533  {
534  scaninfo[tmp_scanindex[i]].include = true;
535  }
536  pb_undo->setEnabled( false );
537  tmp_scanindex.clear();
538  for (int i=0; i<scanindex.size(); i++)
539  {
540  tmp_scanindex.append( scanindex.at(i) );
541  }
542  }
543  else
544  {// add back entire triple:
545  for (int i=0; i<scaninfo.size(); i++)
546  {
547  if (scaninfo.at(i).triple == undo_triple)
548  {
549  scaninfo[i].include = true;
550  }
551  }
552  }
553  plot_scans();
554 }
555 
556 // activate the undo button once a delete action was performed
558 {
559  pb_undo->setEnabled( true );
560  undo_triple = ""; // reset when delete other than delete_triple was performed.
562  plot_scans();
563 }
564 
565 void US_FDS_FileManager::activate_undo( QString triple )
566 {
567  pb_undo->setEnabled( true );
568  undo_triple = triple;
569  plot_scans();
570 }
571 
572 // delete all scans shown in the plot area
574 {
575  for (int i=0; i<scanindex.size(); i++)
576  {
577  scaninfo[scanindex[i]].include = false;
578  }
579  activate_undo();
580 }
581 
582 // only save the first scan, delete all others shown (for initial meniscus)
584 {
585  for (int i=1; i<scanindex.size(); i++)
586  {
587  scaninfo[scanindex[i]].include = false;
588  }
589  activate_undo();
590 }
591 
592 // save the last scan only, delete all others shown on screen (last one is at equilibrium)
594 {
595  for (int i=0; i<scanindex.size() - 1; i++)
596  {
597  scaninfo[scanindex[i]].include = false;
598  }
599  activate_undo();
600 }
601 
602 // for first speed, the first scan is useful for meniscus, the last is at equilibrium
604 {
605  for (int i=1; i<scanindex.size()-1; i++)
606  {
607  scaninfo[scanindex[i]].include = false;
608  }
609  activate_undo();
610 }
611 
612 // Delete all scans belonging to a particular triple
614 {
615  for (int i=0; i<scaninfo.size(); i++)
616  {
617  if (scaninfo.at(i).triple == cb_triple->currentText())
618  {
619  scaninfo[i].include = false;
620  }
621  }
622  activate_undo(cb_triple->currentText());
623 }
624 
625 // exclude only the visually selected (highlighted) scans
627 {
628  for (int i=0; i<scanindex.size(); i++)
629  {
630  if ( from == 0 && to == 0 )
631  { // include all scans (should never happen)
632  scaninfo[scanindex[i]].include = true;
633  }
634  else if (i >= from-1 && i <= to-1 )
635  {
636  scaninfo[scanindex[i]].include = false;
637  }
638  else
639  {
640  scaninfo[scanindex[i]].include = true;
641  }
642  }
643 
644  from = 0;
645  to = 0;
646 
647  ct_from->disconnect();
648  ct_from->setValue( 0.0 );
649  ct_to ->disconnect();
650  ct_to ->setValue( 0.0 );
651 
652  connect( ct_from, SIGNAL( valueChanged ( double ) ),
653  SLOT ( focus_from ( double ) ) );
654  connect( ct_to, SIGNAL( valueChanged ( double ) ),
655  SLOT ( focus_to ( double ) ) );
656  pb_exclude->setEnabled( false );
657  activate_undo();
658 }
659 
660 // sets the scan focus for the start of the excluded scan range
662 {
663  from = (int) scan;
664  to = (int) ct_to->value();
665 
666  if ( from > to )
667  {
668  ct_to->disconnect();
669  ct_to->setValue( scan );
670  to = from;
671  connect( ct_to, SIGNAL( valueChanged ( double ) ),
672  SLOT ( focus_to ( double ) ) );
673  }
674  focus( from, to );
675 }
676 
677 // sets the scan focus for the end of the excluded scan range
678 void US_FDS_FileManager::focus_to( double scan )
679 {
680  to = (int) scan;
681  from = (int) ct_from->value();
682 
683  if ( from > to )
684  {
685  ct_from->disconnect();
686  ct_from->setValue( scan );
687  from = to;
688 
689  connect( ct_from, SIGNAL( valueChanged ( double ) ),
690  SLOT ( focus_from ( double ) ) );
691  }
692  focus( from, to );
693 }
694 
695 // function for activating the exclude button
696 void US_FDS_FileManager::focus( int from, int to )
697 {
698  if ( from == 0 && to == 0 )
699  {
700  pb_exclude->setEnabled( false );
701  }
702  else
703  {
704  pb_exclude->setEnabled( true );
705  }
706  plot_scans();
707 }
708 
709 // function for updating the prefix for export filenames:
711 {
712  QString str;
713  prefix = str.setNum( val );
714  if ( prefix == "0" )
715  {
716  prefix = "";
717  }
718  else
719  {
720  prefix = prefix + "_";
721  }
722 }
723 
724 // write all remaining files to a new directory with successive filenames
726 {
727  int i, j;
728  QFileDialog fd;
729  QString target_dir;
730  fd.setFileMode(QFileDialog::Directory);
731  target_dir = fd.getExistingDirectory( this,
732  tr( "Please select or create an output directory for the ordered fluorescence data (ANY EXISITNG DATA WILL BE DELETED!!):" ),
734  QFileDialog::DontResolveSymlinks);
735 
736  target_dir.replace( "\\", "/" );
737 
738  if ( target_dir.isEmpty() ) // If no directory chosen, return now
739  {
740  return;
741  }
742  else
743  {
744  le_info->setText( "Writing all files to " + target_dir);
745  QDir target(target_dir);
746  target.remove("*");
747  }
748  if ( target_dir.right( 1 ) != "/" ) target_dir += "/"; // Ensure trailing "/"
749  QStringList triples;
750  QString filename, str1, str2;
751  TripleIndex tmp_tripleCounts;
752  triples.clear();
753  tripleCounts.clear();
754  for ( i=0; i<scaninfo.size(); i++ )
755  {
756  if ( scaninfo[i].include )
757  { // filter out the triples that are not excluded
758  triples << scaninfo[i].triple;
759  }
760  }
761  triples.removeDuplicates(); // get a simple list
762  for ( i=0; i<triples.size(); i++ )
763  {
764  tmp_tripleCounts.name = triples.at(i);
765  tmp_tripleCounts.index = 0;
766  tripleCounts.append( tmp_tripleCounts );
767  }
768  progress->setValue(0);
769  QFile f;
770  for ( i=0; i<scaninfo.size(); i++)
771  {
772  if ( scaninfo[i].include )
773  {// increment filename and write to new location
774  j = 0;
775  while ( scaninfo[i].triple != tripleCounts[j].name ) j++;
776  tripleCounts[j].index ++;
777  if (tripleCounts[j].index < 10)
778  {
779  filename = target_dir + prefix + scaninfo.at(i).channel + "0000"
780  + str1.setNum(tripleCounts[j].index) + ".FI" + str2.setNum( scaninfo.at(i).cell );
781  }
782  else if (tripleCounts[j].index > 9 && tripleCounts[j].index < 100)
783  {
784  filename = target_dir + prefix + scaninfo.at(i).channel + "000"
785  + str1.setNum(tripleCounts[j].index) + ".FI" + str2.setNum( scaninfo.at(i).cell );
786  }
787  else if (tripleCounts[j].index > 99 && tripleCounts[j].index < 1000)
788  {
789  filename = target_dir + prefix + scaninfo.at(i).channel + "00"
790  + str1.setNum(tripleCounts[j].index) + ".FI" + str2.setNum( scaninfo.at(i).cell );
791  }
792  else if (tripleCounts[j].index > 999 && tripleCounts[j].index < 10000)
793  {
794  filename = target_dir + prefix + scaninfo.at(i).channel + "0"
795  + str1.setNum(tripleCounts[j].index) + ".FI" + str2.setNum( scaninfo.at(i).cell );
796  }
797  else if (tripleCounts[j].index > 9999 && tripleCounts[j].index < 100000)
798  {
799  filename = target_dir + prefix + scaninfo.at(i).channel
800  + str1.setNum(tripleCounts[j].index) + ".FI" + str2.setNum( scaninfo.at(i).cell );
801  }
802  if ( !f.copy( source_dir + scaninfo.at(i).filename, filename ) )
803  {
804  str1 = tr("The file:\n\n ") + filename + tr("\n\nalready exists in:\n\n ") + target_dir + "\n\n"
805  + tr("Please use a different directory or prefix, or create a new directory and try again.");
806  QMessageBox::warning (this, tr( "Attention:" ), str1, QMessageBox::Ok );
807  return;
808  }
809  }
810  progress->setValue(100 * (i+1)/scaninfo.size());
811  }
812 }