UltraScan III
us_ramp_gui.cpp
Go to the documentation of this file.
1 #include <QApplication>
2 
3 #include "us_license_t.h"
4 #include "us_license.h"
5 #include "us_util.h"
6 #include "us_settings.h"
7 #include "us_gui_settings.h"
8 #include "us_run_details2.h"
9 #include "us_plot.h"
10 #include "us_math2.h"
11 #include "us_ramp_gui.h"
12 #include "us_experiment_gui_ra.h"
13 #include "us_select_triples_ra.h"
14 #include "us_solution_gui.h"
15 #include "us_db2.h"
16 #include "us_passwd.h"
17 #include "us_intensity_ra.h"
18 #include "us_get_dbrun_ra.h"
19 #include "us_investigator.h"
20 #include "us_constants.h"
21 #include "us_report.h"
22 #include "us_gui_util.h"
23 #include "us_util.h"
24 #include "us_images.h"
25 #include "us_rotor_gui.h"
26 #include "qwt_scale_engine.h"
27 
28 #ifdef WIN32
29 #include <float.h>
30 #ifndef isnan
31 #define isnan _isnan
32 #endif
33 #endif
34 
35 
36 
37 int main( int argc, char* argv[] )
38 {
39  QApplication application( argc, argv );
40 
41  #include "main1.inc"
42 
43  // License is OK. Start up.
44 
45  US_RampGui w;
46  w.show();
47  return application.exec();
48 }
49 
51 {
53 
54  // Ensure data directories are there
55  QDir dir;
56  dir.mkpath( US_Settings::workBaseDir() );
57  dir.mkpath( US_Settings::importDir() );
58  dir.mkpath( US_Settings::tmpDir() );
59  dir.mkpath( US_Settings::dataDir() );
60  dir.mkpath( US_Settings::archiveDir() );
61  dir.mkpath( US_Settings::resultDir() );
62  dir.mkpath( US_Settings::reportDir() );
63  dir.mkpath( US_Settings::etcDir() );
64 
65  setWindowTitle( tr( "Import Ramp Data (Lechner, OpenAUC Multiwavelength)" ) );
66  setPalette( US_GuiSettings::frameColor() );
67 
68  isMwl = false;
70 DbgLv(0) << "CGui: dbg_level" << dbg_level;
71 
72  QGridLayout* settings = new QGridLayout;
73 
74  int row = 0;
75 
76  // First row
77  QStringList DB = US_Settings::defaultDB();
78  if ( DB.isEmpty() ) DB << "Undefined";
79  QLabel* lb_DB = us_banner( tr( "Database: " ) + DB.at( 0 ) );
80  lb_DB->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
81 
82  // Investigator
83  bool isadmin = ( US_Settings::us_inv_level() > 2 );
84  QWidget* wg_investigator;
85  QPushButton* pb_investigator = us_pushbutton( tr( "Select Investigator"));
86 
87  if ( isadmin )
88  { // Admin gets investigator button
89  wg_investigator = (QWidget*)pb_investigator;
90  }
91  else
92  { // Non-admin gets only investigator label
93  QLabel* lb_investigator = us_label( tr( "Investigator:" ) );
94  wg_investigator = (QWidget*)lb_investigator;
95  pb_investigator->setVisible( false );
96  }
97 
98  le_investigator = us_lineedit( tr( "Not Selected" ), 0, true );
99 
100  // Radio buttons
103 
104  // Display status
105  QLabel* lb_status = us_banner( tr( "Status:" ) );
106  le_status = us_lineedit( tr( "(no data loaded)" ), 1, true );
107  QPalette stpal;
108  stpal.setColor( QPalette::Text, Qt::blue );
109  le_status->setPalette( stpal );
110 
111  // Display Run ID
112  QLabel* lb_runID = us_label( tr( "Run ID:" ) );
113  // Add this later, after tabs:settings->addWidget( lb_runID, row, 0 );
114  lb_runID->setVisible( false ); // for now
115 
116  le_runID = us_lineedit( "", 1, true );
117  //le_runID ->setMinimumWidth( 280 );
118  // Add this later, after tabs: settings->addWidget( le_runID, row++, 1 );
119  le_runID ->setVisible ( false ); // for now
120 
121  // Load the run
122  QLabel* lb_run = us_banner( tr( "Load the Run" ) );
123 
124  // Pushbuttons to load and reload data
125  pb_importlechner = us_pushbutton( tr( "Import Lechner Ramp Data from HD" ) );
126 
127  // External program to enter experiment information
128  pb_editRuninfo = us_pushbutton( tr( "Edit Run Information" ) );
129  pb_editRuninfo->setEnabled( false );
130 
131  // load US3 data ( that perhaps has been done offline )
132  pb_loadUS3 = us_pushbutton( tr( "Load US3 Ramp Data" ), true );
133 
134 // // Run details
135 // pb_details = us_pushbutton( tr( "Run Details" ), false );
136 
137  // Load MWL data
138  pb_importmwlramp = us_pushbutton( tr( "Import MWL Ramp Data from HD" ) );
139  le_lambraw = us_lineedit( tr( "" ), 0, true );
140 
141 // // Set the wavelength tolerance for c/c/w determination
142 // QLabel* lb_tolerance = us_label( tr( "Separation Tolerance:" ) );
143 // ct_tolerance = us_counter ( 2, 0.0, 100.0, 5.0 );
144 // ct_tolerance->setStep( 1 );
145 // //ct_tolerance->setMinimumWidth( 80 );
146 
147  // Set up MWL controls
149  QFontMetrics fmet( font );
150  //ct_tolerance->adjustSize();
151  //int fwid = fmet.maxWidth();
152  //int swid = fwid * 5;
153  static QChar clambda( 955 ); // Lambda character
154 
155  lb_mwlctrl = us_banner ( tr( "Multi-Wavelength Lambda Controls" ) );
156  lb_lambstrt = us_label ( tr( "%1 Start:" ).arg( clambda ) );
157  lb_lambstop = us_label ( tr( "%1 End:" ).arg( clambda ) );
158  lb_lambplot = us_label ( tr( "Plot %1:" ).arg( clambda ) );
162  pb_lambprev = us_pushbutton( "previous", true, -2 );
163  pb_lambnext = us_pushbutton( "next", true, -2 );
166  //lb_lambstrt->setMinimumWidth( swid );
167  //cb_lambstrt->setMinimumWidth( swid );
168  //lb_lambstop->setMinimumWidth( swid );
169  //cb_lambstop->setMinimumWidth( swid );
170  // MWL Controls
171  QGridLayout* mwl_controls = new QGridLayout();
172 
173  QLabel* lb_runinfo = us_banner( tr( "Run Information" ) );
174 
175  // Change Run ID
176  QLabel* lb_runID2 = us_label( tr( "Run ID:" ) );
177  le_runID2 = us_lineedit( "", 1 );
178  //le_runID2 ->setMinimumWidth( 225 );
179 
180  // Directory
181  QLabel* lb_dir = us_label( tr( "Directory:" ) );
182  le_dir = us_lineedit( "", 1, true );
183 
184  // Description
185  lb_description = us_label( tr( "Description:" ), 0 );
186  //lb_description ->setMaximumWidth( 175 );
187  le_description = us_lineedit( "", 1 );
188 
189 
190  // Cell / Channel / Wavelength
191  QGridLayout* ccw = new QGridLayout();
192 
193  // Meniscus
194  lb_Meniscus = us_label( tr( "Meniscus:" ), 0 );
195  le_Meniscus = us_lineedit( "", 1, true );
196 
197  // Bottom
198  lb_Bottom = us_label( tr( "Bottom:" ), 0 );
199  le_Bottom = us_lineedit( "", 1, true );
200 
201  // Radius
202  lb_Radius = us_label( tr( "Radius:" ), 0 );
203  le_Radius = us_lineedit( "", 1, true );
204 
205 
206 
208  tr( "Cell / Channel / Wavelength" ), -1 );
210 // lw_triple->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
211  lw_triple->setMaximumWidth ( 150 );
212  QLabel* lb_ccwinfo = us_label(
213  tr( "Enter Associated Triple (c/c/w) Info:" ) );
214  lb_ccwinfo->setMaximumHeight(25);
215 
216  // Set up centerpiece drop-down
217  cb_centerpiece = new US_SelectBoxRa( this );
218  centerpieceInfo();
219  cb_centerpiece -> load();
220 
221  // External program to enter solution information
222  pb_solution = us_pushbutton( tr( "Manage Solutions" ), false );
223  pb_applyAll = us_pushbutton( tr( "Apply to All" ), false );
224  // Choosing reference channel
225  pb_reference = us_pushbutton( tr( "Referencing" ), false );
226  pb_cancelref = us_pushbutton( tr( "Undo Referencing" ), false );
227  // Drop scan
228  pb_dropScan = us_pushbutton( tr( "Drop Channel?" ), false );
229  le_dropScan = us_lineedit( "Keep Channel", 1);
230  QLabel* lb_solution = us_label( tr( "Solution:" ) );
231  le_solutionDesc = us_lineedit( "", 1, true );
232 
233  // Standard pushbuttons
234  QPushButton* pb_reset = us_pushbutton( tr( "Reset" ) );
235  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
236  pb_saveUS3 = us_pushbutton( tr( "Save" ), false );
237  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
238 
239  // Add widgets to layouts
240  settings ->addWidget( lb_DB, row++, 0, 1, 4 );
241  settings ->addWidget( wg_investigator, row, 0, 1, 2 );
242  settings ->addWidget( le_investigator, row++, 2, 1, 2 );
243  settings ->addLayout( disk_controls, row++, 0, 1, 4 );
244  settings ->addWidget( lb_run, row++, 0, 1, 4 );
245  settings ->addWidget( pb_importlechner, row, 0, 1, 2 );
246  settings ->addWidget( pb_editRuninfo, row++, 2, 1, 2 );
247  settings ->addWidget( pb_importmwlramp, row, 0, 1, 2 );
248 
249  settings ->addWidget( pb_loadUS3, row++, 2, 1, 2 );
250 // settings ->addWidget( pb_details, row++, 2, 1, 2 );
251 // settings ->addWidget( lb_tolerance, row, 0, 1, 2 );
252 // settings ->addWidget( ct_tolerance, row++, 2, 1, 2 );
253 
254 
255  ccw ->addWidget( lb_runinfo, row++, 0, 1, 12 );
256  ccw ->addWidget( lb_runID2, row, 0, 1, 3 );
257  ccw ->addWidget( le_runID2, row++, 3, 1, 9 );
258  ccw ->addWidget( lb_dir, row, 0, 1, 3 );
259  ccw ->addWidget( le_dir, row++, 3, 1, 9 );
260  ccw ->addWidget( lb_triple, row++, 0, 1, 12 );
261  ccw ->addWidget( lb_description, row, 0, 1, 3 );
262  ccw ->addWidget( le_description, row++, 3, 1, 9 );
263 
264  ccw ->addWidget( lw_triple, row, 0, 8, 4 );
265 
266  ccw ->addWidget( lb_Meniscus, row, 4, 1, 4 );
267  ccw ->addWidget( le_Meniscus, row++, 8, 1, 4 );
268  ccw ->addWidget( lb_Bottom, row, 4, 1, 4 );
269  ccw ->addWidget( le_Bottom, row++, 8, 1, 4 );
270  ccw ->addWidget( lb_Radius, row, 4, 1, 4 );
271  ccw ->addWidget( le_Radius, row++, 8, 1, 4 );
272 
273  ccw ->addWidget( lb_ccwinfo, row++, 4, 1, 8 );
274  ccw ->addWidget( cb_centerpiece, row++, 4, 1, 8 );
275  ccw ->addWidget( pb_solution, row, 4, 1, 4 );
276  ccw ->addWidget( pb_applyAll, row++, 8, 1, 4 );
277  ccw ->addWidget( pb_reference, row, 4, 1, 4 );
278  ccw ->addWidget( pb_cancelref, row++, 8, 1, 4 );
279  ccw ->addWidget( pb_dropScan, row, 4, 1, 4 );
280  ccw ->addWidget( le_dropScan, row++, 8, 1, 4 );
281  ccw ->addWidget( lb_solution, row, 0, 1, 3 );
282  ccw ->addWidget( le_solutionDesc, row++, 3, 1, 9 );
283  mwl_controls ->addWidget( lb_mwlctrl, row++, 0, 1, 4 );
284  mwl_controls ->addWidget( le_lambraw, row++, 0, 1, 4 );
285  mwl_controls ->addWidget( lb_lambstrt, row, 0, 1, 1 );
286  mwl_controls ->addWidget( cb_lambstrt, row, 1, 1, 1 );
287  mwl_controls ->addWidget( lb_lambstop, row, 2, 1, 1 );
288  mwl_controls ->addWidget( cb_lambstop, row++, 3, 1, 1 );
289  mwl_controls ->addWidget( lb_lambplot, row, 0, 1, 1 );
290  mwl_controls ->addWidget( cb_lambplot, row, 1, 1, 1 );
291  mwl_controls ->addWidget( pb_lambprev, row, 2, 1, 1 );
292  mwl_controls ->addWidget( pb_lambnext, row++, 3, 1, 1 );
293 // ccw -> addLayout ( mwl_controls, row++, 0, 1, 12);
294  ccw ->addWidget( lb_status, row++, 0, 1, 12 );
295  ccw ->addWidget( le_status, row++, 0, 1, 12 );
296 
297  settings ->addLayout( ccw, row++, 0, 1, 4 );
298 
299  settings ->addWidget( pb_reset, row, 0, 1, 1 );
300  settings ->addWidget( pb_help, row, 1, 1, 1 );
301  settings ->addWidget( pb_saveUS3, row, 2, 1, 1 );
302  settings ->addWidget( pb_close, row++, 3, 1, 1 );
303 
304  // Plot layout for the right side of window
305  QBoxLayout* plot = new US_Plot( data_plot,
306  tr( "Ramp Data" ),
307  tr( "w²t (/ s¯¹)" ),
308  tr( "Intensity (/AU)" ) );
309 
310  data_plot->setMinimumSize( 500, 300 );
311 
312  data_plot->enableAxis( QwtPlot::xBottom, true );
313  data_plot->enableAxis( QwtPlot::yLeft , true );
314 
315  data_plot->setAxisScale( QwtPlot::xBottom, 5.7, 7.3 );
316  data_plot->setAxisScale( QwtPlot::yLeft , 0.0, 1.5 );
317 
318  picker = new US_PlotPicker( data_plot );
319  picker ->setRubberBand ( QwtPicker::VLineRubberBand );
320  picker->setMousePattern ( QwtEventPattern::MouseSelect1,
321  Qt::LeftButton, Qt::ControlModifier );
322 
323  QGridLayout* todo = new QGridLayout();
324 
325  // Instructions ( missing to do items )
326  QLabel* lb_todoinfo = us_banner( tr( "Instructions ( to do list )" ), 0 );
328  lw_todoinfo->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
329  lw_todoinfo->setMaximumHeight ( 90 );
330  lw_todoinfo->setSelectionMode( QAbstractItemView::NoSelection );
331 
332 // Scan controls:
333  todo->addWidget( lb_todoinfo, row++, 0, 1, 4 );
334  todo->addWidget( lw_todoinfo, row++, 0, 1, 4 );
335 
336  // Connect signals and slots
337  if ( isadmin )
338  connect( pb_investigator, SIGNAL( clicked() ),
339  SLOT( sel_investigator() ) );
340 // connect( disk_controls, SIGNAL( changed ( bool ) ),
341 // SLOT ( source_changed( bool ) ) );
342 // connect( pb_importlechner, SIGNAL( clicked() ),
343 // SLOT( import() ) );
344  connect( pb_editRuninfo, SIGNAL( clicked() ),
345  SLOT( editRuninfo(void) ) );
346  connect( pb_loadUS3, SIGNAL( clicked() ),
347  SLOT( loadUS3() ) );
348 // connect( pb_details, SIGNAL( clicked() ),
349 // SLOT( runDetails() ) );
350  connect( pb_importmwlramp, SIGNAL( clicked() ),
351  SLOT( importMWL(void) ) );
352 // connect( ct_tolerance, SIGNAL( valueChanged ( double ) ),
353 // SLOT ( toleranceValueChanged( double ) ) );
354  connect( le_description, SIGNAL( textEdited( QString ) ),
355  SLOT ( changeDescription() ) );
356  connect( lw_triple, SIGNAL( itemSelectionChanged() ),
357  SLOT ( changeCellchan() ) );
358  connect( cb_centerpiece, SIGNAL( activated ( int ) ),
359  SLOT ( getCenterpieceIndex( int ) ) );
360  connect( pb_solution, SIGNAL( clicked() ),
361  SLOT( getSolutionInfo() ) );
362  connect( pb_applyAll, SIGNAL( clicked() ),
363  SLOT( tripleApplyAll() ) );
364  connect( pb_reference, SIGNAL( clicked() ),
365  SLOT( define_reference() ) );
366 // connect( pb_cancelref, SIGNAL( clicked() ),
367 // SLOT( cancel_reference() ) );
368  connect( pb_dropScan, SIGNAL( clicked() ),
369  SLOT( drop_reference() ) );
370  connect( pb_reset, SIGNAL( clicked() ),
371  SLOT( resetAll() ) );
372  connect( pb_help, SIGNAL( clicked() ),
373  SLOT( help() ) );
374  connect( pb_saveUS3, SIGNAL( clicked() ),
375  SLOT( saveUS3() ) );
376  connect( pb_close, SIGNAL( clicked() ),
377  SLOT( close() ) );
378 
379  // Now let's assemble the page
380 
381  QVBoxLayout* left = new QVBoxLayout;
382 
383  left->addLayout( settings );
384 
385  QVBoxLayout* right = new QVBoxLayout;
386 
387  right->addLayout( mwl_controls );
388  right->addLayout( plot );
389  right->addLayout( todo );
390 
391  QHBoxLayout* main = new QHBoxLayout( this );
392  main->setSpacing ( 2 );
393  main->setContentsMargins ( 2, 2, 2, 2 );
394 
395  main->addLayout( left );
396  main->addLayout( right );
397  main->setStretchFactor( left, 3 );
398  main->setStretchFactor( right, 5 );
399 
400 DbgLv(1) << "CGui: GUI setup complete";
401 // reset();
402 DbgLv(1) << "CGui: reset complete";
403 }
404 
405 // User pressed the import ramp data button KL
407 {
408  // Ask for data directory
409  QString dir = QFileDialog::getExistingDirectory( this,
410  tr( "Raw MWL Data Directory" ),
412  QFileDialog::DontResolveSymlinks );
413  qDebug() << dir;
414 // QString dir = "/root/ultrascan/imports/mw_speedramp_test_runID";
415 
416  // Restore area beneath dialog
417  qApp->processEvents();
418 
419  if ( dir.isEmpty() ) return;
420 
421  dir.replace( "\\", "/" ); // WIN32 issue
422 
423  currentDir = QString( dir );
424  runID = currentDir.section( "/", -1, -1 );
425 
426  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
427 
428  // Read the data
429  le_status->setText( tr( "Importing MWL Ramp data ..." ) );
430  qApp->processEvents();
431 
432  QString runID_xml_mwl;
433  ramp.import_data(currentDir, le_status, allData, runID_xml_mwl);
434 
436 // runType = "rampI";
437 
438  ExpData.runID = runID_xml_mwl;
439 
440  le_runID2->setText( ExpData.runID );
441  le_runID ->setText( ExpData.runID );
442  le_dir ->setText( currentDir );
443 
444  if ( runID != runID_xml_mwl )
445  { // Output warning when resetting (but only if we have data)
446  int status = QMessageBox::information( this,
447  tr( "Information" ),
448  tr( "The runID from xml-file doesn't match directory name." ),
449  tr( "&OK" ), tr( "&Cancel" ),
450  0, 0, 1 );
451 
452  if ( status != 0 )
453  {
454  reset();
455  QApplication::restoreOverrideCursor();
456  return;
457  }
458  }
459  runID = runID_xml_mwl;
460 
461 
462 
463 
464 
465 
467 // For the future implementation of wl-averaging and reduction of wl-span
468 // //////////////////////////////////////////////////////////////////////
469 // // Define default tolerances before converting
470 // scanTolerance = ( runType == "WA" ) ? 0.1 : 5.0; // No idea what
471 // qDebug()<< "scanTolerance" << scanTolerance; // that's for..
472 // ct_tolerance->setValue( scanTolerance ); // -still not working?
473 //
474 // show_mwl_control( true );
475 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
476 //
477 // // Set initial lambda range; build the output data
478 // le_status->setText( tr( "Duplicating wavelengths ..." ) );
479 // qApp->processEvents();
480 // slambda = mwl_data.countOf( "slambda" );
481 // elambda = mwl_data.countOf( "elambda" );
482 // ramp.set_lambdas ( slambda, elambda );
483 // //////////////////////////////////////////////////////
484 
485 
487 
488  setTripleInfo();
489 
490  // Initialize some lineedits and plot graph for selected cellchan..
491  changeCellchan();
492  QApplication::restoreOverrideCursor();
493 
494  pb_editRuninfo->setEnabled( true );
496  enableControls();
497  le_status->setText( tr( "Finished Import of MWL Ramp data" ));
498 }
499 
500 
501 void US_RampGui::reset( void )
502 {
503  lw_triple ->clear();
504 
505  le_dir ->setText( "" );
506 
507  le_description ->setText( "" );
508  le_runID ->setText( "" );
509  le_runID2 ->setText( "" );
510  le_Bottom ->setText( "" );
511  le_Meniscus ->setText( "" );
512  le_Radius ->setText( "" );
513 
514 
515  pb_importlechner ->setEnabled( true );
516  pb_loadUS3 ->setEnabled( true );
517  pb_importmwlramp ->setEnabled( true );
518  pb_cancelref ->setEnabled( false );
519  pb_dropScan ->setEnabled( false );
520  pb_solution ->setEnabled( false );
521  pb_editRuninfo ->setEnabled( false );
522  pb_applyAll ->setEnabled( false );
523  pb_saveUS3 ->setEnabled( false );
524  le_lambraw ->clear();
525 
526 
527  cb_centerpiece->setEnabled( false );
528 
529  // Clear any data structures
530  all_chaninfo.clear();
531 // out_chaninfo.clear();
532  allData .clear();
533  outData .clear();
534  ExpData .clear();
535  if ( isMwl )
536  ramp.clear();
537 // show_plot_progress = true;
538 
539  // Erase the todo list
540  lw_todoinfo->clear();
541  lw_todoinfo->addItem( "Load or import some AUC data" );
542 
543  data_plot ->detachItems();
544  picker ->disconnect();
545  data_plot ->setAxisScale( QwtPlot::xBottom, 0, 1e10 );
546  data_plot ->setAxisScale( QwtPlot::yLeft , 0.0, 1.5 );
547  grid = us_grid( data_plot );
548  data_plot ->replot();
549 
550  enableRunIDControl( true );
551 
552  toleranceChanged = false;
554  isPseudo = false;
555  isMwl = false;
556 
557  pb_reference ->setEnabled( false );
558  referenceDefined = false;
559 DbgLv(1) << "CGui: (1)referDef=" << referenceDefined;
560 
561  // Display investigator
563 
564  QString number = ( ExpData.invID > 0 )
565  ? QString::number( ExpData.invID ) + ": "
566  : "";
567 
568  le_investigator->setText( number + US_Settings::us_inv_name() );
569  show_mwl_control( true );
570 }
571 
573 {
574  if ( allData.size() > 0 )
575  { // Output warning when resetting (but only if we have data)
576  int status = QMessageBox::information( this,
577  tr( "New Data Warning" ),
578  tr( "This will erase all data currently on the screen, and "
579  "reset the program to its starting condition. No hard-drive "
580  "data or database information will be affected. Proceed? " ),
581  tr( "&OK" ), tr( "&Cancel" ),
582  0, 0, 1 );
583 
584  if ( status != 0 ) return;
585  }
586 
587  reset();
588 
589  le_status->setText( tr( "(no data loaded)" ) );
590 
591  runID = "";
592  data_plot->setTitle( tr( "Ramp Data" ) );
593 }
594 
595 // Function to select the current investigator
597 {
598  US_Investigator* inv_dialog = new US_Investigator( true, ExpData.invID );
599 
600  connect( inv_dialog,
601  SIGNAL( investigator_accepted( int ) ),
602  SLOT ( assign_investigator ( int ) ) );
603 
604  inv_dialog->exec();
605 }
606 
607 // Function to assign the selected investigator as current
609 {
610  ExpData.invID = invID;
611 
612  QString number = ( invID > 0 )
613  ? QString::number( invID ) + ": "
614  : "";
615 
616  le_investigator->setText( number + US_Settings::us_inv_name() );
617 
618 }
619 //
620 // // Function to change the data source (disk/db)
621 // void US_ConvertGui::source_changed( bool )
622 // {
623 // QStringList DB = US_Settings::defaultDB();
624 //
625 // if ( DB.size() < 5 )
626 // {
627 // QMessageBox::warning( this,
628 // tr( "Attention" ),
629 // tr( "There is no default database set." ) );
630 // }
631 //
632 // // Did we switch from disk to db?
633 // if ( disk_controls->db() && ! save_diskDB )
634 // {
635 // // Make sure these are explicitly chosen
636 // ExpData.operatorID = 0;
637 // ExpData.rotorID = 0;
638 // ExpData.calibrationID = 0;
639 // }
640 //
641 // save_diskDB = disk_controls->db();
642 //
643 // // Reinvestigate whether to enable the buttons
644 // enableControls();
645 // }
646 //
647 // void US_ConvertGui::update_disk_db( bool db )
648 // {
649 // save_diskDB = disk_controls->db();
650 //
651 // ( db ) ? disk_controls->set_db() : disk_controls->set_disk();
652 // }
653 //
654 // // User changed the dataset separation tolerance
655 // void US_ConvertGui::toleranceValueChanged( double )
656 // {
657 // toleranceChanged = true;
658 // scanTolerance = ct_tolerance->value();
659 // reimport();
660 // }
661 //
662 
663 // Enable the common dialog controls when there is data
665 {
666  if ( allData.size() == 0 )
667  reset();
668 
669  else
670  {
671 DbgLv(1) << "CGui: enabCtl: have-data";
672  // Ok to enable some buttons now
673  pb_solution ->setEnabled( true );
674  cb_centerpiece ->setEnabled( true );
675  pb_editRuninfo ->setEnabled( true );
676 
677  pb_dropScan ->setEnabled( true );
678 
679 // if ( runType == "RI" )
680  pb_reference->setEnabled( true );
681 // qDebug()<<"_________________enablecontrols"<<referenceDefined;
682 
683 
684  // Disable load buttons if there is data
685  pb_importlechner ->setEnabled( false );
686  pb_loadUS3->setEnabled( false );
687  pb_importmwlramp ->setEnabled( false );
688 
689  // Cell Channel Details
690  lb_triple ->setText( tr( "Cell / Channel" ) );
691 // ct_tolerance->setMinimumWidth( 160 );
692 // ct_tolerance->setNumButtons ( 2 );
693 // ct_tolerance->setRange ( 0.0, 100.0 );
694 // ct_tolerance->setStep ( 1.0 );
695 // ct_tolerance->setValue ( scanTolerance );
696 
697  // Let's calculate if we're eligible to copy this triple info to all
698  // or to save it
699  // We have to check against GUID's, because solutions won't have
700  // solutionID's yet if they are created as needed offline
701  QRegExp rx( "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
702 
703  pb_applyAll -> setEnabled( false );
704 
705  if ( all_chaninfo.size() > 1 &&
706  rx.exactMatch( all_chaninfo[ cellchan ].solution.solutionGUID ) )
707  {
708  pb_applyAll -> setEnabled( true );
709  }
710 
712 DbgLv(1) << "CGui: enabCtl: enabRunID complete";
713 DbgLv(1) << "CGui: tLx infsz" << cellchan << all_chaninfo.count();
714 
715  enableSaveBtn();
716 DbgLv(1) << "CGui: enabCtl: enabSvBtn complete";
717  }
718 }
719 //
720 // Enable or disable the runID control
721 void US_RampGui::enableRunIDControl( bool setEnable )
722 {
723  if ( setEnable )
724  {
725  us_setReadOnly( le_runID2, false );
726  connect( le_runID2, SIGNAL( textEdited( QString ) ),
727  SLOT ( runIDChanged( ) ) );
728  }
729 
730  else
731  {
732  le_runID2->disconnect();
733  us_setReadOnly( le_runID2, true );
734  }
735 
736 }
737 
738 
739 // Enable the "save" button, if appropriate
740 // Let's use the same logic to populate the todo list too
742 {
743  lw_todoinfo->clear();
744  int count = 0;
745  bool completed = true;
746 DbgLv(1) << " enabCtl: tLx infsz" << cellchan << all_chaninfo.count();
748 
749  if ( allData.size() == 0 )
750  {
751  count++;
752  lw_todoinfo->addItem( QString::number( count )
753  + tr( ": Load or import some AUC data" ) );
754  completed = false;
755  }
756 
757  // Do we have any triples?
758  if ( all_chaninfo.size() == 0 )
759  {
760  count++;
761  lw_todoinfo->addItem( QString::number( count )
762  + tr( ": Load or import some AUC data" ) );
763  completed = false;
764  }
765 
766  // Is the run info defined?
767  QRegExp rx( "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
768 
769  // Not checking operator on disk -- defined as "Local"
770  if ( ( ExpData.rotorID == 0 ) ||
771  ( ExpData.calibrationID == 0 ) ||
772  ( ExpData.labID == 0 ) ||
773  ( ExpData.instrumentID == 0 ) ||
774  ( ExpData.label.isEmpty() ) ||
775  ( ! rx.exactMatch( ExpData.project.projectGUID ) ) )
776  {
777  count++;
778  lw_todoinfo->addItem( QString::number( count )
779  + tr( ": Edit run information" ) );
780  completed = false;
781  }
782 
783  // Have we filled out all the c/c/w info?
784  // Check GUIDs, because solutionID's may not be present yet.
785  foreach ( US_Ramp::TripleInfo tripinfo, all_chaninfo )
786  {
787  if ( ! rx.exactMatch( tripinfo.solution.solutionGUID ) )
788  {
789  count++;
790  lw_todoinfo->addItem( QString::number( count ) +
791  tr( ": Select solution for triple " ) +
792  tripinfo.tripleDesc );
793  completed = false;
794  }
795  }
796 
797  foreach ( US_Ramp::TripleInfo tripinfo, all_chaninfo )
798  {
799  if ( tripinfo.centerpiece == 0 )
800  {
801  count++;
802  lw_todoinfo->addItem( QString::number( count ) +
803  tr( ": Select centerpiece for triple " ) +
804  tripinfo.tripleDesc );
805  completed = false;
806  }
807  }
808 
809  if ( disk_controls->db() )
810  {
811  // Verify connectivity
812  US_Passwd pw;
813  QString masterPW = pw.getPasswd();
814  US_DB2 db( masterPW );
815 
816  if ( db.lastErrno() != US_DB2::OK )
817  {
818  count++;
819  lw_todoinfo->addItem( QString::number( count ) +
820  tr( ": Verify database connectivity" ) );
821  completed = false;
822  }
823 
824  // Information is there, but we need to see if the runID exists in the
825  // DB. If we didn't load it from there, then we shouldn't be able to sync
826  int recStatus = ExpData.checkRunID( &db );
827 
828  // if a record is found but saveStatus==BOTH,
829  // then we are editing that record
830  if ( ( recStatus == US_DB2::OK ) && ( saveStatus != BOTH ) ) // ||
831  // ( ! ExpData.syncOK ) )
832  {
833  count++;
834  lw_todoinfo->addItem( QString::number( count ) +
835  tr( ": Select a different runID" ) );
836  completed = false;
837  }
838 
839  // Not checking operator on disk -- defined as "Local"
840  if ( ExpData.operatorID == 0 )
841  {
842  count++;
843  lw_todoinfo->addItem( QString::number( count )
844  + tr( ": Select operator in run information" ) );
845  completed = false;
846  }
847 
848  }
849 
850  // This can go on the todo list, but should not prevent user from saving
851  if ( ( runType == "rampI" ) && ( ! referenceDefined ) )
852  {
853  count++;
854  lw_todoinfo->addItem( QString::number( count ) +
855  tr( ": Define reference scans" ) );
856  }
857 
858  // If we made it here, user can save
859  pb_saveUS3 ->setEnabled( completed );
860 }
861 
862 // Process when the user changes the runID
864 {
865  // See if we need to update the runID
866  QRegExp rx( "^[A-Za-z0-9_-]{1,80}$" );
867  QString new_runID = le_runID2->text();
868 
869  if ( rx.indexIn( new_runID ) >= 0 )
870  {
871  runID = new_runID;
872  if ( runID.length() > 50 )
873  {
874  QMessageBox::warning( this,
875  tr( "RunID Name Too Long" ),
876  tr( "The runID name may be at most\n"
877  "50 characters in length." ) );
878  runID = runID.left( 50 );
879  }
880 // plot_titles();
881  }
882 
883  // If the runID has changed, a number of other things need to change too,
884  // for instance GUID's.
885  ExpData.clear();
886  foreach( US_Ramp::TripleInfo tripinfo, all_chaninfo )
887  tripinfo.clear();
888  le_runID2->setText( runID );
889  le_runID ->setText( runID );
890 
892 
893  // Set the directory too
894  QDir resultDir( US_Settings::resultDir() );
895  currentDir = resultDir.absolutePath() + "/" + runID + "/";
896  le_dir ->setText( currentDir );
897 }
898 
899 
900 
901 // Function to generate a new guid for experiment, and associate with DB
903 {
904 DbgLv(1) << "CGui: edRuninfo: IN";
905 qDebug()<<"___________________savestatus"<<saveStatus;
906  if ( saveStatus == NOT_SAVED )
907  {
908  ExpData.show();
909  // Create a new GUID for the experiment as a whole
911 
912  }
913 
914  getExpInfo( );
915 DbgLv(1) << "CGui: edRuninfo: getExpInfo complete";
916 ExpData.show();
917 }
918 
919 // Function to load US3 data
920 void US_RampGui::loadUS3( QString dir )
921 {
922 DbgLv(1) << "CGui: ldUS3: IN";
923 // dir = "/root/ultrascan/results/mw_speedramp_test_runID/";
924  /* if ( disk_controls->db() )
925 // loadUS3DB();
926 
927  else*/ if ( dir.isEmpty() )
928  loadUS3Disk();
929 
930  else
931  loadUS3Disk( dir );
932 
933 // checkTemperature(); // Check to see if temperature varied too much
934 DbgLv(1) << "CGui: ldUS3: RTN";
935 
936 }
937 
939 {
940  // Ask for data directory
941  QString dir = QFileDialog::getExistingDirectory( this,
942  tr("US3 Raw Data Directory"),
944  QFileDialog::DontResolveSymlinks );
945 
946  // Restore area beneath dialog
947  qApp->processEvents();
948 
949  if ( dir.isEmpty() ) return;
950 
951  dir.replace( "\\", "/" ); // WIN32 issue
952  if ( dir.right( 1 ) != "/" ) dir += "/"; // Ensure trailing /
953 
954  loadUS3Disk( dir );
955 }
956 
957 void US_RampGui::loadUS3Disk( QString dir )
958 {
959 // resetAll();
960  le_status->setText( tr( "Loading data from local disk ..." ) );
961  qApp->processEvents();
962 
963  // Check the runID
964  QStringList components = dir.split( "/", QString::SkipEmptyParts );
965  QString new_runID = components.last();
966 
967  QRegExp rx( "^[A-Za-z0-9_-]{1,80}$" );
968  if ( rx.indexIn( new_runID ) < 0 )
969  {
970  QMessageBox::warning( this,
971  tr( "Bad runID Name" ),
972  tr( "The runID name may consist only of alphanumeric\n"
973  "characters, the underscore, and the hyphen." ) );
974  return;
975  }
976 
977  // Set the runID and directory
978  runID = new_runID;
979  le_runID ->setText( runID );
980  le_runID2->setText( runID );
981  le_dir ->setText( dir );
982  currentDir = QString( dir );
983 
984  // Reload the AUC data
985  le_status->setText( tr( "Loading data from Disk (raw data) ..." ) );
986  qApp->processEvents();
987 DbgLv(1) << "CGui: ldUS3Dk: call read";
988  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
989  int status = US_Ramp::readUS3Disk( dir, allData, all_chaninfo, runType );
990  QApplication::restoreOverrideCursor();
991 // return;
992 
993  if ( status == US_Ramp::NODATA )
994  {
995  QMessageBox::warning( this,
996  tr( "No Files Found" ),
997  tr( "There were no files of the form *.auc\n"
998  "found in the specified directory." ) );
999  return;
1000  }
1001 
1002  if ( status == US_Ramp::NOAUC )
1003  {
1004  QMessageBox::warning( this,
1005  tr( "UltraScan Error" ),
1006  tr( "Could not read data file.\n" ) );
1007  return;
1008  }
1009 
1010  all_chaninfo[0].show();
1011  // Initialize export data pointers vector
1012  init_output_data();
1013  qDebug()<<"____________after_init_out";
1014  all_chaninfo[0].show();
1015 
1016  // Now try to read the xml file
1017 DbgLv(1) << "CGui: ldUS3Dk: call rdExp sz(trinfo)" << all_chaninfo.count();
1018  le_status->setText( tr( "Loading data from Disk (experiment) ..." ) );
1019  qApp->processEvents();
1020  ExpData.clear();
1021 
1022  status = ExpData.readFromDisk( all_chaninfo, runType, runID, dir );
1023 // qDebug() << "all_chaninfo_size" << all_chaninfo.size();
1024 
1025 
1026  if ( status == US_Ramp::CANTOPEN )
1027  {
1028  QString readFile = runID + "."
1029  + runType + ".xml";
1030  QMessageBox::information( this,
1031  tr( "Error" ),
1032  tr( "US3 run data ok, but unable to assocate run with DB.\n " ) +
1033  tr( "Cannot open read file: " ) + dir + readFile );
1034  }
1035 
1036  else if ( status == US_Ramp::BADXML )
1037  {
1038  QString readFile = runID + "."
1039  + runType + ".xml";
1040  QMessageBox::information( this,
1041  tr( "Error" ),
1042  tr( "US3 run data ok, but there is an error in association with DB.\n"
1043  "Improper XML in read file: " ) + dir + readFile );
1044  }
1045 
1046  else if ( status != US_Ramp::OK )
1047  {
1048  QMessageBox::information( this,
1049  tr( "Error" ),
1050  tr( "Unknown error: " ) + status );
1051  }
1052 
1053  // Now that we have the experiment, let's read the rest of the
1054  // solution and project information
1055  le_status->setText( tr( "Loading data from Disk (project) ..." ) );
1056  qApp->processEvents();
1057 DbgLv(1) << "CGui: ldUS3Dk: call prj-rDk";
1059 
1060  // Error reporting
1061  if ( status == US_DB2::NO_PROJECT )
1062  {
1063  QMessageBox::information( this,
1064  tr( "Attention" ),
1065  tr( "The project was not found.\n"
1066  "Please select an existing project and try again.\n" ) );
1067  }
1068 
1069  else if ( status != US_DB2::OK )
1070  {
1071  QMessageBox::information( this,
1072  tr( "Disk Read Problem" ),
1073  tr( "Could not read data from the disk.\n"
1074  "Disk status: " ) + QString::number( status ) );
1075  }
1076 
1077  // and clear it out
1078  if ( status != US_DB2::OK )
1079  ExpData.project.clear();
1080 
1081  le_status->setText( tr( "Project and experiment are loaded." ) );
1082  qApp->processEvents();
1083  QString psolGUID = "";
1084 DbgLv(1) << "CGui: SOLCHK:loop";
1086  // Now the solutions
1087  for ( int ii = 0; ii < all_chaninfo.size(); ii++ )
1088  {
1089  QString csolGUID = all_chaninfo[ ii ].solution.solutionGUID;
1090  qDebug()<<"___________-sol"<<csolGUID;
1091 
1092  if ( csolGUID == psolGUID )
1093  {
1094  qDebug()<<"bla";
1095  all_chaninfo[ ii ].solution = all_chaninfo[ ii - 1 ].solution;
1096  status = US_DB2::OK;
1097  continue;
1098  }
1099  else
1100  {
1101  if ( csolGUID.isEmpty() )
1102  {
1103  qDebug()<<"bla";
1104 DbgLv(1) << "SOLCHK: ii csolGUID EMPTY" << ii << csolGUID;
1105  if ( ii > 0 )
1106  {
1107  csolGUID = psolGUID;
1108  all_chaninfo[ ii ].solution.solutionGUID = csolGUID;
1109  }
1110  }
1111  status = all_chaninfo[ ii ].solution.readFromDisk( csolGUID );
1112  qDebug()<<"buffer"<<all_chaninfo[ ii ].solution.solutionDesc;
1113 // qDebug()<<"buffer"<<all_chaninfo[ ii].solution.buffer;
1114  psolGUID = csolGUID;
1115  qDebug()<<"____status"<<status;
1116  }
1117 
1118  // Error reporting
1119  if ( status == US_DB2::NO_SOLUTION )
1120  {
1121  QMessageBox::information( this,
1122  tr( "Attention" ),
1123  tr( "A solution this run refers to was not found,"
1124  " or could not be read.\n"
1125  "Please select an existing solution and try again.\n" ) );
1126 DbgLv(1) << "SOLERR: ii psolGUID csolGUI" << ii << psolGUID << csolGUID;
1127  }
1128 
1129  else if ( status == US_DB2::NO_BUFFER )
1130  {
1131  QMessageBox::information( this,
1132  tr( "Attention" ),
1133  tr( "The buffer this solution refers to was not found.\n"
1134  "Please restore and try again.\n" ) );
1135  }
1136 
1137  else if ( status == US_DB2::NO_ANALYTE )
1138  {
1139  QMessageBox::information( this,
1140  tr( "Attention" ),
1141  tr( "One of the analytes this solution refers to was not found.\n"
1142  "Please restore and try again.\n" ) );
1143  }
1144 
1145  else if ( status != US_DB2::OK )
1146  {
1147  QMessageBox::information( this,
1148  tr( "Disk Read Problem" ),
1149  tr( "Could not read data from the disk.\n"
1150  "Disk status: " ) + QString::number( status ) );
1151  }
1152  qDebug()<<"all_chaninfo[ ii ].solutionDesc0"<<all_chaninfo[ ii ].solution.solutionDesc;
1153  // Just clear it out
1154  if ( status != US_DB2::OK )
1155  all_chaninfo[ ii ].solution.clear();
1156  qDebug()<<"all_chaninfo[ ii ].solutionDesc1"<<all_chaninfo[ ii ].solution.solutionDesc;
1157  }
1158 DbgLv(1) << "CGui: SOLCHK:loop-END";
1159 
1160  le_status->setText( tr( "Solutions are now loaded." ) );
1161  qApp->processEvents();
1162 // /////////////////////////////////////////////////////////////////////////
1163 
1164  referenceDefined = true;
1165  isPseudo = true;
1166 DbgLv(1) << "CGui: (5)referDef=" << referenceDefined;
1167  pb_reference->setEnabled( false );
1168  pb_cancelref->setEnabled( true );
1169 
1170 
1171  if ( allData.size() == 0 ) return;
1172 
1173  le_status->setText( tr( "%1 data triples are now loaded." )
1174  .arg( allData.size() ) );
1175  qApp->processEvents();
1176 
1177 
1178 DbgLv(1) << "CGui: call setTripleInfo";
1179  // Update triple information on screen
1180 cellchan = 0;
1181 // qDebug()<<"_________size_allchaninfo ______size_alldata_____cellchan"<< all_chaninfo.size()<<allData.size()<<cellchan;
1182 // qDebug()<<"___meniscus___size_wl____size_alldata[2].intarray0.size"<<allData[cellchan].meniscus<<allData[0].wl_array.size()<<allData[2].intarray.size()<<allData[2].intarray[0].size();
1183 
1184  setTripleInfo();
1185 
1186 
1187 DbgLv(1) << "CGui: setDesc trLx" << cellchan << all_chaninfo.size();
1188  le_solutionDesc->setText( all_chaninfo[ cellchan ].solution.solutionDesc );
1189 
1190  // Restore description
1191  le_description->setText( allData[cellchan].description );
1192  saveDescription = QString( ExpData.runID );
1193 
1194  // The centerpiece combo box
1195  cb_centerpiece->setLogicalIndex( all_chaninfo[ cellchan ].centerpiece );
1196 
1197  // Redo plot
1198 DbgLv(1) << "CGui: call plot_current";
1199  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1200  plot_current();
1201  QApplication::restoreOverrideCursor();
1202 
1203  // Ok to enable some buttons now
1204  enableControls();
1205 // if ( ! disk_controls->db() )
1206 // pb_saveUS3 ->setEnabled( true );
1207 
1208 // pb_details ->setEnabled( true );
1209 // pb_solution ->setEnabled( true );
1210 // cb_centerpiece ->setEnabled( true );
1211 // pb_editRuninfo ->setEnabled( true );
1212 
1213 // // some things one can't do from here
1214 // ct_tolerance ->setEnabled( false );
1215 
1216  enableRunIDControl( false );
1217 
1218  saveStatus = ( ExpData.expID == 0 ) ? HD_ONLY : BOTH;
1219  pb_editRuninfo ->setEnabled ( saveStatus == HD_ONLY );
1220 
1221 // // Read it in ok, so ok to sync with DB
1222 // ExpData.syncOK = true;
1223 
1224 // enableSaveBtn();
1225  le_status->setText( tr( "Local disk data load is complete." ) );
1226  qApp->processEvents();
1227 DbgLv(1) << "CGui: ldUS3Dk: RTN";
1228 }
1229 //
1230 // // Function to load an experiment from the DB
1231 // void US_ConvertGui:: loadUS3DB( void )
1232 // {
1233 // DbgLv(1) << "CGui: ldUS3DB: IN";
1234 // le_status->setText( tr( "Loading data from DB ..." ) );
1235 // qApp->processEvents();
1236 //
1237 // // Verify connectivity
1238 // US_Passwd pw;
1239 // QString masterPW = pw.getPasswd();
1240 // US_DB2 db( masterPW );
1241 //
1242 // if ( db.lastErrno() != US_DB2::OK )
1243 // {
1244 // QMessageBox::information( this,
1245 // tr( "Error" ),
1246 // tr( "Error making the DB connection.\n" ) );
1247 // return;
1248 // }
1249 //
1250 // // Present a dialog to ask user which experiment to load
1251 // QString runID;
1252 // DbgLv(1) << "CGui: ldUS3DB: call GetDBRun";
1253 // US_GetDBRun dialog( runID );
1254 //
1255 // if ( dialog.exec() == QDialog::Rejected )
1256 // return;
1257 //
1258 // if ( runID == QString( "" ) )
1259 // return;
1260 //
1261 // // Restore area beneath dialog
1262 // qApp->processEvents();
1263 //
1264 // // Now that we have the runID, let's copy the DB info to HD
1265 // QDir readDir( US_Settings::resultDir() );
1266 // QString dirname = readDir.absolutePath() + "/" + runID + "/";
1267 //
1268 // DbgLv(1) << "CGui: ldUS3DB: call rdDBExp";
1269 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1270 // le_status->setText( tr( "Loading data from DB (Experiment) ..." ) );
1271 // qApp->processEvents();
1272 // QString status = US_ConvertIO::readDBExperiment( runID, dirname, &db );
1273 // QApplication::restoreOverrideCursor();
1274 //
1275 // if ( status != QString( "" ) )
1276 // {
1277 // QMessageBox::information( this, tr( "Error" ), status + "\n" );
1278 // return;
1279 // }
1280 //
1281 // // and load it
1282 // DbgLv(1) << "CGui: ldUS3DB: call ldUS3Dk";
1283 // le_status->setText( tr( "Loading data from DB (Disk data) ..." ) );
1284 // qApp->processEvents();
1285 // loadUS3Disk( dirname );
1286 //
1287 // saveStatus = BOTH; // override from loadUS3Disk()
1288 // ExpData.syncOK = true; // since we just read it from there
1289 //
1290 // enableControls();
1291 //
1292 // le_status->setText( tr( "%1 data triples are now loaded from DB." )
1293 // .arg( allData.size() ) );
1294 // qApp->processEvents();
1295 //
1296 // DbgLv(1) << "CGui: ldUS3DB: RTN";
1297 // }
1298 //
1300 {
1301 DbgLv(1) << "CGui: gExpInf: IN";
1302  ExpData.runID = le_runID -> text();
1303  ExpData.runTemp = QString::number(allData[0].temperature);
1304 
1305  if ( disk_controls->db() )
1306  {
1307  // Then we're working in DB, so verify connectivity
1308  US_Passwd pw;
1309  QString masterPW = pw.getPasswd();
1310  US_DB2 db( masterPW );
1311 
1312  if ( db.lastErrno() != US_DB2::OK )
1313  {
1314  QMessageBox::information( this,
1315  tr( "Error" ),
1316  tr( "Error making the DB connection.\n" ) );
1317  return;
1318  }
1319 
1320  // Check if the run ID already exists in the DB
1321  int recStatus = ExpData.checkRunID( &db );
1322 
1323  // if saveStatus == BOTH, then we are editing the record from the database
1324  if ( ( recStatus == US_DB2::OK ) && ( saveStatus != BOTH ) )
1325  {
1326  QMessageBox::information( this,
1327  tr( "Error" ),
1328  tr( "The current runID already exists in the database.\n"
1329  "To edit that information, load it from the database\n"
1330  "to start with." ) );
1331  return;
1332  }
1333  }
1334 
1335  // OK, proceed
1336 
1337 // // Calculate average temperature
1339 // // ramp: our mwl-machine is not capable
1340 // // of measuring the temperature
1342 // double sum = 0.0;
1343 // double count = 0.0;
1344 // for ( int i = 0; i < allData.size(); i++ )
1345 // {
1346 // US_DataIO::RawData raw = allData[ i ];
1347 // for ( int j = 0; j < raw.scanData.size(); j++ )
1348 // sum += raw.scanData[ j ].temperature;
1349 //
1350 // count += raw.scanData.size();
1351 // }
1352 
1353 
1354 
1355  int dbdisk = ( disk_controls->db() ) ? US_Disk_DB_Controls::DB
1357 
1358  US_ExperimentGuiRa* expInfo = new US_ExperimentGuiRa( true, // signal_wanted
1359  ExpData,
1360  dbdisk );
1361 
1362  connect( expInfo, SIGNAL( updateExpInfoSelection( US_ExperimentRa& ) ),
1363  this , SLOT ( updateExpInfo ( US_ExperimentRa& ) ) );
1364 
1365  connect( expInfo, SIGNAL( cancelExpInfoSelection() ),
1366  this , SLOT ( cancelExpInfo () ) );
1367 
1368  connect( expInfo, SIGNAL( use_db ( bool ) ),
1369  SLOT ( update_disk_db( bool ) ) );
1370 
1371  expInfo->exec();
1372 DbgLv(1) << "CGui: gExpInf: RTN";
1373 }
1374 
1375 // Updating after user has selected info from experiment dialog
1377 {
1378  // Update local copy
1379  ExpData = d;
1380 
1381  if ( this->saveStatus == NOT_SAVED )
1382  this->saveStatus = EDITING; // don't delete the data!
1383 
1384  enableControls();
1385 }
1386 
1388 {
1389  // Don't clear out the data, just don't save anything new
1390 
1391  enableControls();
1392 }
1393 
1395 {
1396  const int chanID = 1;
1397 
1398  cellchan = lw_triple->currentRow();
1399  ExpData.runID = le_runID -> text();
1400 
1401  int dbdisk = ( disk_controls->db() ) ? US_Disk_DB_Controls::DB
1403 
1404  US_Solution solution = all_chaninfo[ cellchan ].solution;
1405 
1406  US_SolutionGui* solutionInfo = new US_SolutionGui(
1407  ExpData.expID,
1408  chanID, // channelID
1409  true, // signal wanted
1410  dbdisk, // data source
1411  solution );
1412 
1413  connect( solutionInfo, SIGNAL( updateSolutionGuiSelection( US_Solution ) ),
1414  this, SLOT ( updateSolutionInfo ( US_Solution ) ) );
1415 
1416  connect( solutionInfo, SIGNAL( cancelSolutionGuiSelection() ),
1417  this, SLOT ( cancelSolutionInfo () ) );
1418 
1419  connect( solutionInfo, SIGNAL( use_db ( bool ) ),
1420  SLOT ( update_disk_db( bool ) ) );
1421 
1422  solutionInfo->exec();
1423 }
1424 
1425 // Updating after user has selected info from experiment dialog
1427 {
1428  cellchan = lw_triple->currentRow();
1429 
1430  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1431 
1432  // Update local copy
1433  all_chaninfo[ cellchan ].solution = s;
1434 
1435  le_solutionDesc->setText( all_chaninfo[ cellchan ].solution.solutionDesc );
1436 
1437 
1438  // Re-plot
1439  plot_current();
1440 
1441  QApplication::restoreOverrideCursor();
1442 
1443  enableControls();
1444 }
1445 
1447 {
1448  enableControls();
1449 }
1450 
1451 // Function to copy the current triple's data to all triples
1453 {
1455 
1456  // Copy selected fields only
1457 
1458  for ( int ii = 0; ii < all_chaninfo.size(); ii++ )
1459  {
1460  all_chaninfo[ ii ].centerpiece = tripinfo.centerpiece;
1461  all_chaninfo[ ii ].solution = tripinfo.solution;
1462  }
1463 
1464 
1465  le_status->setText( tr( "The current c/c/w information has been"
1466  " copied to all." ) );
1467  qApp->processEvents();
1468 
1469  plot_current();
1470 
1471  enableControls();
1472 }
1473 //
1474 // void US_ConvertGui::runDetails( void )
1475 // {
1476 // // Create data structures for US_RunDetails2
1477 // QStringList tripleDescriptions;
1478 // QVector< US_DataIO::RawData > currentData;
1479 // if ( isMwl )
1480 // { // For MWL, only pass the 1st data set of each cell/channel
1481 // for ( int ii = 0; ii < all_chaninfo.size(); ii++ )
1482 // {
1483 // currentData << *outData[ out_chandatx[ ii ] ];
1484 // tripleDescriptions << all_chaninfo[ ii ].tripleDesc;
1485 // }
1486 // }
1487 //
1488 // else
1489 // { // For most data, pass all (non-excluded) triples
1490 // for ( int ii = 0; ii < out_tripinfo.size(); ii++ )
1491 // {
1492 // currentData << *outData[ ii ];
1493 // tripleDescriptions << out_tripinfo[ ii ].tripleDesc;
1494 // }
1495 // }
1496 //
1497 // US_RunDetails2* dialog = new US_RunDetails2( currentData, runID, currentDir,
1498 // tripleDescriptions );
1499 // dialog->exec();
1500 // qApp->processEvents();
1501 // delete dialog;
1502 // }
1503 //
1505 {
1506  if ( le_description->text().size() < 1 )
1507  le_description->setText( allData[ tripDatax ].description );
1508 
1509  else
1510  {
1511  allData[ tripDatax ].description = le_description->text().trimmed();
1512  }
1513 }
1514 
1516 {
1517  // If a new triple is selected several widgets get updated:
1518  cellchan = lw_triple->currentRow();
1519  le_dir ->setText( currentDir );
1520  le_description ->setText( allData[ cellchan ].description );
1521  le_solutionDesc ->setText( all_chaninfo[ cellchan ].solution.solutionDesc );
1522  QString bottom = QString::number ( allData[ cellchan ].bottom);
1523  QString meniscus = QString::number ( allData[ cellchan ].meniscus);
1524  QString radius = QString::number ( allData[ cellchan ].radius);
1525  le_Bottom ->setText( bottom );
1526  le_Meniscus ->setText( meniscus );
1527  le_Radius ->setText( radius );
1528  // The centerpiece combo box
1529  cb_centerpiece ->setLogicalIndex( all_chaninfo[ cellchan ].centerpiece );
1530 
1531  // chan excluded?
1532  if (all_chaninfo[cellchan].excluded)
1533  {
1534  le_dropScan->setText("Drop Channel");
1535  }
1536  else if (!all_chaninfo[cellchan].excluded)
1537  {
1538  le_dropScan->setText("Keep Channel");
1539  }
1540 
1541  // Redo plot
1542  plot_current();
1543 }
1544 //
1545 // Reset triple controls after a change
1547 {
1548  exp_lambdas = allData[0].wl_array;
1549  all_lambdas = allData[0].wl_array;
1550  // Load them into the list box
1551  int trListSave = lw_triple->currentRow();
1552 
1553  lw_triple->disconnect();
1554  lw_triple->clear();
1555 
1556 
1557  int nchans = allData.size();
1558  qDebug()<<"__________nchans"<<nchans;
1559  for (int iii = 0; iii<nchans; iii++)
1560  {
1561  lw_triple->addItem( all_chaninfo[iii].tripleDesc);
1562  }
1563 
1564  cellchan = qMax( 0, qMin( trListSave, ( nchans - 1 ) ) );
1565 
1566 
1567  qDebug()<<"____triplistx"<<cellchan;
1568  // Get wavelengths for the currently selected cell/channel
1569  nlambda = allData[cellchan].wl_array.size();
1570  slambda = exp_lambdas[ 0 ];
1571  elambda = exp_lambdas[ nlambda - 1 ];
1572  int plambda = cb_lambplot->currentText().toInt();
1573  lambda = nlambda / 2;
1574 
1575 DbgLv(1) << " sTI: lambda" << lambda << "nlambda" << nlambda;
1576 
1577  mwl_connect( false );
1578  cb_lambplot->clear();
1579 
1580  for ( int wvx = 0; wvx < nlambda; wvx++ )
1581  { // Rebuild the plot lambda list
1582  int ilamb = exp_lambdas[ wvx ];
1583  cb_lambplot->addItem( QString::number( ilamb ) );
1584 
1585  if ( ilamb == plambda ) lambda = wvx;
1586  }
1587 
1588  // Re-do selections for lambda start,stop,plot
1589  cb_lambstrt->setCurrentIndex( all_lambdas.indexOf( slambda ) );
1590  cb_lambstop->setCurrentIndex( all_lambdas.indexOf( elambda ) );
1591  cb_lambplot->setCurrentIndex( lambda );
1592 
1593  mwl_connect(true);
1594  lw_triple->setCurrentRow( cellchan );
1595  connect( lw_triple, SIGNAL( itemSelectionChanged() ),
1596  SLOT ( changeCellchan () ) );
1597 }
1599 // Makes no sense for MWL-Erlangen due to lack of temperature measurement
1600 // Maybe later..
1602 // void US_ConvertGui::checkTemperature( void )
1603 // {
1604 // // Temperature check
1605 // double dt = 0.0;
1606 //
1607 // foreach( US_DataIO::RawData triple, allData )
1608 // {
1609 // double temp_spread = triple.temperature_spread();
1610 // dt = ( temp_spread > dt ) ? temp_spread : dt;
1611 // }
1612 //
1613 // if ( dt > US_Settings::tempTolerance() )
1614 // {
1615 // QMessageBox::warning( this,
1616 // tr( "Temperature Problem" ),
1617 // tr( "The temperature in this run varied over the course\n"
1618 // "of the run to a larger extent than allowed by the\n"
1619 // "current threshold (" )
1620 // + QString::number( US_Settings::tempTolerance(), 'f', 1 )
1621 // + " " + DEGC + tr( "). The accuracy of experimental\n"
1622 // "results may be affected significantly." ) );
1623 // }
1624 // }
1625 //
1627 {
1628  qDebug()<<"all_chaninfo.size();_____________"<<all_chaninfo.size();
1629  cellchan = lw_triple->currentRow();
1630  int cpID = cb_centerpiece->getLogicalID();
1631  all_chaninfo[ cellchan ].centerpiece = cpID;
1632 // DbgLv(1) << "getCenterpieceIndex " << all_chaninfo[cellchan].centerpiece;
1633 
1634  enableSaveBtn();
1635 }
1636 //
1637 // User pressed the Define reference button while analyzing intensity data
1639 {
1640  // identify reference cellchan
1641  reference_cellchan = lw_triple->currentRow();
1642 
1643  // reference point by point through all triples, except the reference cellchan
1644  for (int cc = 0; cc < allData.size(); cc++)
1645  {
1646  if (cc != reference_cellchan)
1647  {// cycle through all wavelengths
1648  for (int wl = 0; wl < allData[cc].intarray.size(); wl++)
1649  {// cycle through all measurement points for one wl
1650  for (int w2t = 0; w2t < allData[cc].intarray[wl].size(); w2t++)
1651  {
1652  double old = allData[cc].intarray[wl][w2t];
1653  double temp = (allData[reference_cellchan].intarray[wl][w2t]/old);
1654  allData[cc].intarray[wl][w2t] = log10(temp);
1655 // old = log10(10);
1656  }
1657  }
1658  }
1659  }
1660  referenceDefined = true;
1661  enableSaveBtn();
1662 
1663 }
1665 // Makes not too much sense for Ramp data
1666 // Example code from US_Convert left here, if functionality is needed later
1668 // // Select starting point of reference scan in intensity data
1669 // void US_ConvertGui::start_reference( const QwtDoublePoint& p )
1670 // {
1671 // reference_start = p.x();
1672 //
1673 // draw_vline( reference_start );
1674 // data_plot->replot();
1675 // }
1676 //
1677 // // Select end point of reference scan in intensity data
1678 // void US_ConvertGui::process_reference( const QwtDoublePoint& p )
1679 // {
1680 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1681 //
1682 // // Just in case we get a second click message right away
1683 // if ( fabs( p.x() - reference_start ) < 0.005 ) return;
1684 //
1685 // reference_end = p.x();
1686 // draw_vline( reference_end );
1687 // data_plot->replot();
1688 // picker ->disconnect();
1689 //
1690 // // Double check if min < max
1691 // if ( reference_start > reference_end )
1692 // {
1693 // double temp = reference_start;
1694 // reference_start = reference_end;
1695 // reference_end = temp;
1696 // }
1697 //
1698 // // Calculate the averages for all triples
1699 // PseudoCalcAvg();
1700 //
1701 // // Now that we have the averages, let's replot
1702 // Pseudo_reference_triple = cellchan;
1703 //
1704 // // Default to displaying the first non-reference triple
1705 // for ( int trx = 0; trx < outData.size(); trx++ )
1706 // {
1707 // if ( trx != Pseudo_reference_triple )
1708 // {
1709 // cellchan = trx;
1710 // break;
1711 // }
1712 // }
1713 //
1714 // lw_triple->setCurrentRow( cellchan );
1715 // plot_current();
1716 // QApplication::restoreOverrideCursor();
1717 //
1718 // pb_reference ->setEnabled( false );
1719 // referenceDefined = true;
1720 // DbgLv(1) << "CGui: (6)referDef=" << referenceDefined;
1721 // enableSaveBtn();
1722 // le_status->setText( tr( "The reference scans have been defined." ) );
1723 // qApp->processEvents();
1724 // }
1725 //
1726 // // Process a control-click on the plot window
1727 // void US_ConvertGui::cClick( const QwtDoublePoint& p )
1728 // {
1729 // switch ( step )
1730 // {
1731 // case SPLIT :
1732 // if ( countSubsets < 4 )
1733 // {
1734 // // process equil-abs data
1735 // draw_vline( p.x() );
1736 // subsets << p.x();
1737 // countSubsets++;
1738 // }
1739 //
1740 // break;
1741 //
1742 // case REFERENCE :
1743 // // process reference scan
1744 // if ( reference_start == 0.0 )
1745 // start_reference( p );
1746 //
1747 // else
1748 // process_reference( p );
1749 //
1750 // default :
1751 // break;
1752 //
1753 // }
1754 // }
1755 //
1756 // // Reference calculation for pseudo-absorbance
1757 // void US_ConvertGui::PseudoCalcAvg( void )
1758 // {
1759 // if ( referenceDefined ) return; // Average calculation has already been done
1760 //
1761 // if ( isMwl )
1762 // { // Do calculations for each wavelength, if MWL
1763 // PseudoCalcAvgMWL();
1764 // return;
1765 // }
1766 //
1767 // US_DataIO::RawData* referenceData = outData[ tripDatax ];
1768 // int ref_size = referenceData->xvalues.size();
1769 //
1770 // for ( int ss = 0; ss < referenceData->scanData.size(); ss++ )
1771 // {
1772 // US_DataIO::Scan* scan = &referenceData->scanData[ ss ];
1773 //
1774 // int rr = 0;
1775 // int count = 0;
1776 // double sum = 0.0;
1777 //
1778 // while ( referenceData->radius( rr ) < reference_start &&
1779 // rr < ref_size )
1780 // rr++;
1781 //
1782 // while ( referenceData->radius( rr ) < reference_end &&
1783 // rr < ref_size )
1784 // {
1785 // sum += scan->rvalues[ rr ];
1786 // count++;
1787 // rr++;
1788 // }
1789 //
1790 // if ( count > 0 )
1791 // ExpData.RIProfile << sum / count;
1792 //
1793 // else
1794 // ExpData.RIProfile << 1.0; // See the log10 function, later
1795 //
1796 // }
1797 //
1798 // // Now average around excluded values
1799 // int lastGood = 0;
1800 // int countBad = 0;
1801 // for ( int ss = 0; ss < ExpData.RIProfile.size(); ss++ )
1802 // {
1803 // // In case there are adjacent excluded scans...
1804 // if ( allExcludes[ tripDatax ].contains( ss ) )
1805 // countBad++;
1806 //
1807 // // Calculate average of before and after for intervening values
1808 // else if ( countBad > 0 )
1809 // {
1810 // double newAvg = ( ExpData.RIProfile[ lastGood ]
1811 // + ExpData.RIProfile[ ss ] ) / 2.0;
1812 //
1813 // for ( int rr = lastGood + 1; rr < ss; rr++ )
1814 // ExpData.RIProfile[ rr ] = newAvg;
1815 //
1816 // countBad = 0;
1817 // }
1818 //
1819 // // Normal situation -- value is not excluded
1820 // else
1821 // lastGood = ss;
1822 //
1823 // }
1824 //
1825 // // Now calculate the pseudo-absorbance
1826 // for ( int trx = 0; trx < outData.size(); trx++ )
1827 // {
1828 // US_DataIO::RawData* currentData = outData[ trx ];
1829 //
1830 // for ( int ss = 0; ss < currentData->scanData.size(); ss++ )
1831 // {
1832 // US_DataIO::Scan* scan = &currentData->scanData[ ss ];
1833 //
1834 // for ( int rr = 0; rr < scan->rvalues.size(); rr++ )
1835 // {
1836 // double rvalue = scan->rvalues[ rr ];
1837 //
1838 // // Protect against possible inf's and nan's, if a reading
1839 // // evaluates to 0 or wherever log function is undefined or -inf
1840 // if ( rvalue < 1.0 ) rvalue = 1.0;
1841 //
1842 // // Check for boundary condition
1843 // int ndx = ( ss < ExpData.RIProfile.size() )
1844 // ? ss : ExpData.RIProfile.size() - 1;
1845 // scan->rvalues[ rr ] = log10( ExpData.RIProfile[ ndx ] / rvalue );
1846 // }
1847 // }
1848 //
1849 // // Let's mark pseudo-absorbance as different from RI data,
1850 // // since it needs some different processing in some places
1851 // isPseudo = true;
1852 // }
1853 //
1854 // // Enable intensity plot
1855 // referenceDefined = true;
1856 // DbgLv(1) << "CGui: (7)referDef=" << referenceDefined;
1857 // pb_reference->setEnabled( false );
1858 // pb_cancelref->setEnabled( true );
1859 // }
1860 //
1861 // // Un-do reference scans apply
1862 // void US_ConvertGui::cancel_reference( void )
1863 // {
1864 // int wvoff = 0;
1865 // int rscans = ExpData.RI_nscans;
1866 //
1867 // // Do the inverse operation and retrieve raw intensity data
1868 // for ( int ii = 0; ii < outData.size(); ii++ )
1869 // {
1870 // US_DataIO::RawData* currentData = outData[ ii ];
1871 //
1872 // if ( isMwl )
1873 // { // For MWL, profile is offset by wavelength
1874 // int iwavl = out_triples[ ii ].section( " / ", 2, 2 ).toInt();
1875 // wvoff = ExpData.RIwvlns.indexOf( iwavl );
1876 //
1877 // if ( wvoff < 0 )
1878 // {
1879 // qDebug() << "Triple " << out_triples[ ii ]
1880 // << "has NO CORRESPONDING RI PROFILE POINT!!!";
1881 // wvoff = 0;
1882 // QMessageBox::information( this,
1883 // tr( "Error" ),
1884 // tr( "Triple %1 has NO CORRESPONDING RI PROFILE POINT!!!" )
1885 // .arg( out_triples[ ii ] ) );
1886 // int kwavl = 99999;
1887 //
1888 // for ( int jj = 0; jj < ExpData.RI_nwvlns; jj++ )
1889 // { // Find index of nearest wavelength
1890 // int jwavl = qAbs( ExpData.RIwvlns[ jj ] - iwavl );
1891 //
1892 // if ( jwavl < kwavl )
1893 // {
1894 // kwavl = jwavl;
1895 // wvoff = jj;
1896 // }
1897 // }
1898 // }
1899 // }
1900 //
1901 // wvoff *= rscans;
1902 //
1903 // for ( int jj = 0; jj < currentData->scanData.size(); jj++ )
1904 // {
1905 // US_DataIO::Scan* scan = &currentData->scanData[ jj ];
1906 // double rppro = ExpData.RIProfile[ jj + wvoff ];
1907 //
1908 // for ( int kk = 0; kk < scan->rvalues.size(); kk++ )
1909 // {
1910 // double rvalue = scan->rvalues[ kk ];
1911 //
1912 // scan->rvalues[ kk ] = rppro / pow( 10, rvalue );
1913 // }
1914 // }
1915 // }
1916 //
1917 // referenceDefined = false;
1918 // isPseudo = false;
1919 // ExpData.RIProfile.clear();
1920 // reference_start = 0.0;
1921 // reference_end = 0.0;
1922 // DbgLv(1) << "CGui: (8)referDef=" << referenceDefined;
1923 //
1924 // for ( int ii = 0; ii < all_tripinfo.size(); ii++ )
1925 // all_tripinfo[ ii ].excluded = false;
1926 //
1927 // setTripleInfo();
1928 //
1929 // pb_reference ->setEnabled( true );
1930 // pb_cancelref ->setEnabled( false );
1931 // cellchan = 0;
1932 // lw_triple->setCurrentRow( cellchan );
1933 //
1934 // plot_current();
1935 //
1936 // enableSaveBtn();
1937 //
1938 // le_status->setText( tr( "The reference scans have been canceled." ) );
1939 // qApp->processEvents();
1940 // }
1942 
1943 
1944 // Drop selected triples
1946 {
1947  cellchan = lw_triple->currentRow();
1948  all_chaninfo[cellchan].excluded = !all_chaninfo[cellchan].excluded;
1949  if (all_chaninfo[cellchan].excluded)
1950  {
1951  le_dropScan->setText("Drop Channel");
1952  }
1953  else if (!all_chaninfo[cellchan].excluded)
1954  {
1955  le_dropScan->setText("Keep Channel");
1956  }
1957 }
1958 
1959 
1960 // Function to save US3 data
1962 {
1963  if ( disk_controls->db() )
1964  saveUS3DB(); // Save AUCs to disk then DB
1965 
1966  else
1967  saveUS3Disk(); // Save AUCs to disk
1968 }
1969 
1970 // Save to disk (default directory)
1972 {
1973  QDir writeDir( US_Settings::resultDir() );
1974  QString dirname = writeDir.absolutePath() + "/" + runID + "/";
1975 // if ( saveStatus == NOT_SAVED &&
1976 // writeDir.exists( runID ) )
1977 // {
1978 // QMessageBox::information( this,
1979 // tr( "Error" ),
1980 // tr( "The write directory, " ) + dirname +
1981 // tr( " already exists. Please change run ID to a unique value." ) );
1982 // return US_Ramp::DUP_RUNID;
1983 // }
1984 
1985  if ( ! writeDir.exists( runID ) )
1986  {
1987  if ( ! writeDir.mkpath( dirname ) )
1988  {
1989  QMessageBox::information( this,
1990  tr( "Error" ),
1991  tr( "Cannot write to " ) + writeDir.absolutePath() );
1992  return US_Ramp::CANTOPEN;
1993  }
1994  }
1995  qDebug()<<"i size_allchaninfo size_alldata"<<all_chaninfo.size()<<allData.size();
1996 
1998 
1999  // Now try to write the xml file
2000  int status;
2001  status = ExpData.saveToDisk( outData, all_chaninfo, runType, runID, dirname );
2002 
2003  // How many files should have been written?
2004  int fileCount = 0;
2005  for ( int i = 0; i < all_chaninfo.size(); i++ )
2006  if ( ! all_chaninfo[ i ].excluded ) fileCount++;
2007 DbgLv(1) << "SV: fileCount" << fileCount;
2008 
2009  // Now try to communicate status
2010  if ( status == US_Ramp::CANTOPEN )
2011  {
2012  QString writeFile = runID + "."
2013  + runType + ".xml";
2014  QMessageBox::information( this,
2015  tr( "Error" ),
2016  tr( "Cannot open write file: " ) + dirname + writeFile );
2017  }
2018 
2019  else if ( status == US_Ramp::NOXML )
2020  {
2021  // Main xml data is missing
2022  QMessageBox::information( this,
2023  tr( "Warning" ),
2024  tr( "The run information file was not written. "
2025  "Please click on the "
2026  "'Associate Run with DB' button \n\n " ) +
2027  QString::number( fileCount ) + " " +
2028  runID + tr( " files written." ) );
2029  return( status );
2030  }
2031 
2032  else if ( status == US_Ramp::PARTIAL_XML )
2033  {
2034  // xml data is missing for one or more triples
2035  QMessageBox::information( this,
2036  tr( "Warning" ),
2037  tr( "Solution information is incomplete. Please click on the "
2038  "'Manage Solutions' button for each "
2039  "cell, channel, and wavelength combination \n\n " ) +
2040  QString::number( fileCount ) + " " +
2041  runID + tr( " files written." ) );
2042  return( status );
2043  }
2044 
2045  else if ( status != US_Ramp::OK )
2046  {
2047  QMessageBox::information( this,
2048  tr( "Error" ),
2049  tr( "Error: " ) + status );
2050  return( status );
2051  }
2052  qDebug()<<"_________________savestatus___status"<<saveStatus<<status;
2053  // Status is OK
2054  le_status->setText( tr( "%1 %2 files were written to disk." )
2055  .arg( fileCount ).arg( runID ) );
2056  qApp->processEvents();
2057 
2058  if ( saveStatus == NOT_SAVED )
2059  saveStatus = HD_ONLY;
2060 }
2061 
2063 // // // Check to see if we have all the data to write
2064 // // if ( ! ExpData.syncOK )
2065 // // {
2066 // // status = QMessageBox::information( this,
2067 // // tr( "Warning" ),
2068 // // tr( "The run has not yet been associated with the database."
2069 // // " Click 'OK' to proceed anyway, or click 'Cancel'"
2070 // // " and then click on the 'Edit Run Information'"
2071 // // " button to enter this information first.\n" ),
2072 // // tr( "&OK" ), tr( "&Cancel" ),
2073 // // 0, 0, 1 );
2074 // // if ( status != 0 ) return US_Convert::NOT_WRITTEN;
2075 // // }
2076 //
2077 
2078 //
2079 // // // If we are here, it's ok to sync with DB
2080 // // ExpData.syncOK = true;
2081 //
2082 // // enableRunIDControl( false );
2083 //
2084 // // if ( isMwl )
2085 // // { // Where triples were expanded for MWL, skip plot save
2086 // // return( US_Convert::OK );
2087 // // }
2089 
2090 
2091 // Save to Database
2093 {
2094 // // Verify connectivity
2095 // US_Passwd pw;
2096 // QString masterPW = pw.getPasswd();
2097 // US_DB2 db( masterPW );
2098 //
2099 // if ( db.lastErrno() != US_DB2::OK )
2100 // {
2101 // QMessageBox::information( this,
2102 // tr( "Error" ),
2103 // tr( "Database connectivity error" ) );
2104 //
2105 // return;
2106 // }
2107 // DbgLv(1) << "DBSv: (1)trip0tripFilename" << out_tripinfo[0].tripleFilename;
2108 //
2109 // // Ok, let's make sure they know what'll happen
2110 // if ( saveStatus == BOTH )
2111 // {
2112 // int status = QMessageBox::information( this,
2113 // tr( "Warning" ),
2114 // tr( "This will overwrite the raw data currently in the " ) +
2115 // tr( "database, and all existing edit profiles, models " ) +
2116 // tr( "and noise data will be deleted too. Proceed? " ),
2117 // tr( "&OK" ), tr( "&Cancel" ),
2118 // 0, 0, 1 );
2119 // if ( status != 0 ) return;
2120 // }
2121 //
2122 // else
2123 // {
2124 // int status = QMessageBox::information( this,
2125 // tr( "Warning" ),
2126 // tr( "Once this data is written to the DB you will not " ) +
2127 // tr( "be able to make changes to it without erasing the " ) +
2128 // tr( "edit profiles, models and noise files too. Proceed? " ),
2129 // tr( "&OK" ), tr( "&Cancel" ),
2130 // 0, 0, 1 );
2131 // if ( status != 0 ) return;
2132 // }
2133 //
2134 // // First check some of the data with the DB
2135 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2136 // le_status->setText( tr( "Preparing Save with DB check ..." ) );
2137 // qApp->processEvents();
2138 //
2139 // int status = US_ConvertIO::checkDiskData( ExpData, out_tripinfo, &db );
2140 //
2141 // QApplication::restoreOverrideCursor();
2142 // DbgLv(1) << "DBSv: (2)trip0tripFilename" << out_tripinfo[0].tripleFilename;
2143 //
2144 // if ( status == US_DB2::NO_PERSON ) // Investigator or operator doesn't exist
2145 // {
2146 // QMessageBox::information( this,
2147 // tr( "Error" ),
2148 // tr( "This investigator or instrument operator was not found\n"
2149 // "in the database.\n" ) );
2150 // return;
2151 // }
2152 //
2153 // if ( status == US_DB2::BADGUID )
2154 // {
2155 // QMessageBox::information( this,
2156 // tr( "Error" ),
2157 // tr( "Bad GUID format.\n"
2158 // "Please click on Edit Run Information"
2159 // " and re-select hardware.\n" ) );
2160 // return;
2161 // }
2162 //
2163 // if ( status == US_DB2::NO_ROTOR )
2164 // {
2165 // QMessageBox::information( this,
2166 // tr( "Error" ),
2167 // tr( "Don't recognize the rotor configuration.\n"
2168 // "Please click on Edit Run Information"
2169 // " and re-select hardware.\n") );
2170 // return;
2171 // }
2172 //
2173 // if ( status != US_DB2::OK && status != US_DB2::NO_RAWDATA )
2174 // {
2175 // // US_DB2::OK means we're updating; US_DB2::NO_RAWDATA means it's new
2176 // QMessageBox::information( this,
2177 // tr( "Error" ),
2178 // db.lastError() + " (" + db.lastErrno() + ")\n" );
2179 // return;
2180 // }
2181 //
2182 // // Save updated files and prepare to transfer to DB
2183 // le_status->setText( tr( "Preparing Save with Disk write ..." ) );
2184 // qApp->processEvents();
2185 // status = saveUS3Disk();
2186 // if ( status != US_Convert::OK )
2187 // return;
2188 // DbgLv(1) << "DBSv: local files saved";
2189 //
2190 // QString error = QString( "" );
2191 //
2192 // // Get the directory where the auc files are
2193 // QDir resultDir( US_Settings::resultDir() );
2194 // QString dir = resultDir.absolutePath() + "/" + ExpData.runID + "/";
2195 //
2196 // if ( ! resultDir.exists( ExpData.runID ) )
2197 // {
2198 // QMessageBox::information( this,
2199 // tr( "Error" ),
2200 // tr( "Cannot read from " ) + dir ); // aucDir.absolutePath() );
2201 // return;
2202 // }
2203 //
2204 // QStringList nameFilters = QStringList( "*.auc" );
2205 //
2206 // QDir readDir( dir );
2207 //
2208 // QStringList files = readDir.entryList( nameFilters,
2209 // QDir::Files | QDir::Readable, QDir::Name );
2210 // DbgLv(1) << "DBSv: files count" << files.size();
2211 //
2212 // if ( files.size() == 0 )
2213 // {
2214 // QMessageBox::warning( this,
2215 // tr( "No Files Found" ),
2216 // tr( "There were no files of the form *.auc\n"
2217 // "found in the specified directory." ) );
2218 // return;
2219 // }
2220 //
2221 // if ( ExpData.checkRunID( &db ) == US_DB2::OK && ( saveStatus != BOTH ) )
2222 // {
2223 // // Then the user is trying to overwrite a runID that is already in the DB
2224 // QMessageBox::warning( this,
2225 // tr( "Duplicate runID" ),
2226 // tr( "This runID already exists in the database. To edit that "
2227 // "run information, load it from there to begin with.\n" ) );
2228 // return;
2229 // }
2230 //
2231 // // If saveStatus == BOTH already, then it came from the db to begin with
2232 // // and it should be updated. Otherwise, there shouldn't be any database
2233 // // records with this runID found
2234 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2235 // le_status->setText( tr( "Saving Experiment to DB ..." ) );
2236 // qApp->processEvents();
2237 // status = ExpData.saveToDB( ( saveStatus == BOTH ), &db );
2238 // QApplication::restoreOverrideCursor();
2239 //
2240 // if ( status == US_DB2::NO_PROJECT )
2241 // {
2242 // QMessageBox::warning( this,
2243 // tr( "Project missing" ),
2244 // tr( "The project associated with this experiment could not be "
2245 // "updated or added to the database.\n" ) );
2246 // return;
2247 // }
2248 //
2249 // else if ( status == US_DB2::DUPFIELD )
2250 // {
2251 // QMessageBox::warning( this,
2252 // tr( "Duplicate runID" ),
2253 // tr( "The runID already exists in the database.\n" ) );
2254 // return;
2255 // }
2256 //
2257 // else if ( status == US_DB2::ERROR )
2258 // {
2259 // // This is what happens in the case of RI data, and the xml is bad
2260 // QMessageBox::warning( this,
2261 // tr( "Bad RI XML" ),
2262 // tr( "There was a problem with the xml data"
2263 // " read from the database.\n" ) );
2264 // }
2265 //
2266 // else if ( status != US_DB2::OK )
2267 // {
2268 // QMessageBox::warning( this,
2269 // tr( "Problem saving experiment information" ),
2270 // tr( "MySQL Error : " ) + db.lastError() + " ("
2271 // + QString::number( status ) + ")" );
2272 // return;
2273 // }
2274 //
2275 // // If the data came from the database in the first place,
2276 // // then this function erases all the edit profiles, models
2277 // // and noise files in the database too. However, if one
2278 // // changes most of the things here ( solution, rotor, etc. )
2279 // // it would invalidate the data anyway.
2280 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2281 // le_status->setText( tr( "Writing raw data to DB ..." ) );
2282 // qApp->processEvents();
2283 // QString writeStatus = US_ConvertIO::writeRawDataToDB( ExpData, out_tripinfo,
2284 // dir, &db );
2285 // QApplication::restoreOverrideCursor();
2286 //
2287 // if ( ! writeStatus.isEmpty() )
2288 // {
2289 // QMessageBox::warning( this,
2290 // tr( "Problem saving experiment" ),
2291 // tr( "Unspecified database error: " ) + writeStatus );
2292 // le_status->setText( tr( "*ERROR* Problem saving experiment." ) );
2293 // return;
2294 // }
2295 //
2296 // le_status->setText( tr( "DB data save complete. Saving reports..." ) );
2297 // qApp->processEvents();
2298 // saveStatus = BOTH;
2299 // enableRunIDControl( false );
2300 //
2301 // saveReportsToDB();
2302 //
2303 // le_status->setText( tr( "DB data and reports save is complete." ) );
2304 // qApp->processEvents();
2305 }
2306 //
2307 // void US_ConvertGui::saveReportsToDB( void )
2308 // {
2309 // if ( isMwl )
2310 // return;
2311 //
2312 // // Verify connectivity
2313 // US_Passwd pw;
2314 // QString masterPW = pw.getPasswd();
2315 // US_DB2 db( masterPW );
2316 //
2317 // if ( db.lastErrno() != US_DB2::OK )
2318 // {
2319 // QMessageBox::information( this,
2320 // tr( "Error" ),
2321 // tr( "Database connectivity error" ) );
2322 //
2323 // return;
2324 // }
2325 //
2326 // // Get a list of report files produced by us_convert
2327 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2328 // QString dir = US_Settings::reportDir() + "/" + runID;
2329 // QDir d( dir, "cnvt*", QDir::Name, QDir::Files | QDir::Readable );
2330 // d.makeAbsolute();
2331 // QStringList files = d.entryList( QDir::Files );
2332 //
2333 // // Add any run details files to it
2334 // QDir d2( dir, "rundetail*", QDir::Name, QDir::Files | QDir::Readable );
2335 // d2.makeAbsolute();
2336 // files << d2.entryList( QDir::Files );
2337 //
2338 // // Create US_Report object
2339 // QString now = QDateTime::currentDateTime().toString();
2340 // US_Report myReport;
2341 // myReport.reset();
2342 // myReport.runID = runID;
2343 // myReport.title = runID + " Report";
2344 // myReport.html = "<p>Report created " + now + "</p>";
2345 //
2346 // // Save all us_convert report files to the DB
2347 // QString errorMsg = "";
2348 // foreach( QString file, files )
2349 // {
2350 // // Get description info for the correct triple
2351 // QStringList parts = file.split( "." );
2352 // QString fileTriple = US_Util::expanded_triple( parts[ 1 ], true );
2353 //
2354 // // Match the triple to find the correct description in memory
2355 // QString description = QString( "" );
2356 // for ( int ii = 0; ii < out_tripinfo.size(); ii++ )
2357 // {
2358 // if ( fileTriple == out_tripinfo[ ii ].tripleDesc )
2359 // {
2360 // description = outData[ ii ]->description;
2361 // break;
2362 // }
2363 // }
2364 //
2365 // // Edit data ID is not known yet, so use 1. It goes in the report document
2366 // // table itself, so we're not overwriting anything.
2367 // US_Report::Status status = myReport.saveDocumentFromFile(
2368 // dir, file, &db, 1, description );
2369 // if ( status != US_Report::REPORT_OK )
2370 // {
2371 // errorMsg += file + " was not saved to report database; error code: "
2372 // + QString::number( status ) + "\n";
2373 // qDebug() << "US_ConvertGui.saveDocumentFromFile error: "
2374 // << db.lastError() << db.lastErrno();
2375 // }
2376 // }
2377 // QApplication::restoreOverrideCursor();
2378 //
2379 // if ( ! errorMsg.isEmpty() )
2380 // {
2381 // QMessageBox::warning( this,
2382 // tr( "Problem saving reports to DB" ),
2383 // errorMsg );
2384 // }
2385 //
2386 // }
2387 //
2388 // bool US_ConvertGui::read( void )
2389 // {
2390 // // Ask for data directory
2391 // QString dir = QFileDialog::getExistingDirectory( this,
2392 // tr( "Raw Data Directory" ),
2393 // US_Settings::importDir(),
2394 // QFileDialog::DontResolveSymlinks );
2395 //
2396 // // Restore area beneath dialog
2397 // qApp->processEvents();
2398 //
2399 // if ( dir.isEmpty() ) return( false );
2400 //
2401 // dir.replace( "\\", "/" ); // WIN32 issue
2402 //
2403 // return( read( dir ) );
2404 // }
2405 //
2406 
2407 
2409 {
2410 DbgLv(1) << "CGui: centpInfo: db" << disk_controls->db();
2411 // if ( disk_controls->db() )
2412 // return centerpieceInfoDB();
2413 
2414 // else
2415  return centerpieceInfoDisk();
2416 }
2417 
2418 // Function to get abstractCenterpiece names from DB
2420 {
2421  // Verify connectivity
2422  US_Passwd pw;
2423  QString masterPW = pw.getPasswd();
2424  US_DB2 db( masterPW );
2425 
2426  if ( db.lastErrno() != US_DB2::OK )
2427  {
2428  QMessageBox::information( this,
2429  tr( "Error" ),
2430  tr( "Database connectivity error" ) );
2431 
2432  return( false );
2433  }
2434 
2435  QStringList q( "get_abstractCenterpiece_names" );
2436  db.query( q );
2437 
2438  QList<listInfo> options;
2439  while ( db.next() )
2440  {
2441  struct listInfo option;
2442  option.ID = db.value( 0 ).toString();
2443  option.text = db.value( 1 ).toString();
2444  options << option;
2445  }
2446 
2447  cb_centerpiece->clear();
2448  if ( options.size() > 0 )
2449  cb_centerpiece->addOptions( options );
2450 
2451 DbgLv(1) << "CGui: centpInfoDB RTN";
2452  return true;
2453 }
2454 
2455 // Function to get abstractCenterpiece names from disk
2457 {
2458  // First figure out the xml file name, and try to open it
2459  QFile f( US_Settings::appBaseDir() + "/etc/abstractCenterpieces.xml" );
2460 
2461  if ( ! f.open( QIODevice::ReadOnly ) ) return false;
2462 
2463  QList<listInfo> options;
2464  QXmlStreamReader xml( &f );
2465  while ( ! xml.atEnd() )
2466  {
2467  xml.readNext();
2468 
2469  if ( xml.isStartElement() )
2470  {
2471  if ( xml.name() == "abstractCenterpiece" )
2472  {
2473  struct listInfo option;
2474  QXmlStreamAttributes a = xml.attributes();
2475  option.ID = a.value("id").toString();
2476  option.text = a.value("name").toString();
2477  options << option;
2478  }
2479  }
2480  }
2481 
2482  bool error = xml.hasError();
2483  f.close();
2484 
2485  if ( error ) return false;
2486 
2487  cb_centerpiece->clear();
2488  if ( options.size() > 0 )
2489  {
2490  // Let's sort them so they come up like the DB
2491  for ( int i = 0; i < options.size() - 1; i++ )
2492  for ( int j = i + 1; j < options.size(); j++ )
2493  if ( options[ i ].text > options[ j ].text )
2494  options.swap( i, j );
2495 
2496  cb_centerpiece->addOptions( options );
2497  }
2498 
2499 DbgLv(1) << "CGui: centpInfoDk RTN";
2500  return true;
2501 }
2502 
2504 {
2505  cellchan = lw_triple->currentRow();
2506 
2507  US_mwlRamp::RampRawData currentData = allData[ cellchan ];
2508 
2509 // if ( currentData.scanData.empty() ) return;
2510 //
2511 // plot_titles();
2512 // DbgLv(1) << " PlCur: PlTit RTN";
2513 //
2514 // // Plot current data for cell / channel / wavelength triple
2515 // plot_all();
2516 // DbgLv(1) << " PlCur: PlAll RTN";
2517 //
2518 // // Set the Scan spin boxes
2519 // enableScanControls();
2520 
2521  data_plot->detachItems();
2522  grid = us_grid( data_plot );
2523 
2524  int n_wl = currentData.intarray.size();
2525  int n = currentData.intarray[0].size();
2526 // qDebug() << "_________________________________n_n_wl"<<n<<n_wl;
2527 
2528  QVector< double > w2tv( currentData.intarray[0].size() ); // initialize plot vectors
2529  QVector< double > intarrayv( currentData.intarray[0].size() );
2530 
2531 
2532 
2533  double* w2t = w2tv.data(); // pointer to initialized plot vectors
2534  double* intarray = intarrayv.data();
2535 
2536 
2537 
2538  for ( int ii = 0; ii < n; ii++)
2539  {
2540  w2t [ii] = currentData.w2t[ii];
2541  intarray [ii] = currentData.intarray[lambda][ii];
2542  }
2543 
2544 // for (int i = 0; i < intarrayv.size(); i++)
2545 // {
2546 // qDebug()<<"w2t int"<<w2tv.at(i)<<intarrayv.at(i);
2547 // }
2548 
2549 
2550  QwtPlotCurve *c = us_curve (data_plot, "RawData at fist WaveLength");
2551 
2552  c->setData( w2t, intarray, (int)n );
2553  double minw2t = w2t[0];
2554  double maxw2t = w2t[n-1];
2555  // min and max indexes for the meas data change after
2556  // referencing --> sorting is required!!
2557  // from http://www.qcustomplot.com/index.php/support/forum/17
2558  QVector<double>::iterator maxY = std::max_element(intarrayv.begin(), intarrayv.end());
2559  QVector<double>::iterator minY = std::min_element(intarrayv.begin(), intarrayv.end());
2560 
2561  double minint = *minY;
2562  double maxint = *maxY;
2563 
2564  // Reset the scan curves within the new limits
2565  double padw2t = ( maxw2t - minw2t ) / 30.0;
2566  double padint = ( maxint - minint ) / 10.0;
2567  qDebug() << minint << maxint << padint;
2568  qDebug() << minw2t << maxw2t << padw2t << minw2t-padw2t<<maxw2t+padw2t;
2569 
2570  qDebug()<<QwtPlot::xBottom<<QwtPlot::yLeft;
2571  data_plot->setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine);
2572  data_plot->setAxisScale( QwtPlot::xBottom , 100, maxw2t + padw2t );
2573  data_plot->setAxisScale( QwtPlot::yLeft, minint - padint, maxint + padint );
2574 // data_plot->setAxisTitle( 2, "w2t");
2575  if (referenceDefined)
2576  {
2577  data_plot->setAxisTitle( 0, "Absorbance / AU");
2578  }
2579  else
2580  {
2581  data_plot->setAxisTitle(0, "Intensity / AU");
2582  }
2583 // data_plot->setTitle("Speed Ramp Experiment");
2584  data_plot->replot();
2585 
2586 }
2588 // void US_ConvertGui::plot_titles( void )
2589 // {
2590 // DbgLv(1) << " PlTit: tDx outsz otrisz" << tripDatax << outData.size()
2591 // << out_tripinfo.size();
2592 // char chtype[ 3 ] = { 'R', 'A', '\0' };
2593 //
2594 // strncpy( chtype, outData[ tripDatax ]->type, 2 );
2595 // QString dataType = QString( chtype ).left( 2 );
2596 // QString triple = out_tripinfo[ tripDatax ].tripleDesc;
2597 // QStringList parts = triple.split(" / ");
2598 // DbgLv(1) << " PlTit: triple" << triple << "parts" << parts;
2599 //
2600 // QString cell = parts[ 0 ];
2601 // QString channel = parts[ 1 ];
2602 // QString wavelen = isMwl ? cb_lambplot->currentText() : parts[ 2 ];
2603 //
2604 // // Plot Title and legends
2605 // QString title;
2606 // QString xLegend = tr( "Radius (in cm)" );
2607 // QString yLegend = tr( "Absorbance" );
2608 // QString ccwlong = runID + tr( "\nCell: " ) + cell
2609 // + tr( " Channel: " ) + channel
2610 // + tr( " Wavelength: " ) + wavelen;
2611 // DbgLv(1) << " PlTit: dataType" << dataType;
2612 //
2613 // if ( dataType == "RA" )
2614 // {
2615 // title = tr( "Radial Absorbance Data\nRun ID: " ) + ccwlong;
2616 // }
2617 //
2618 // else if ( dataType == "RI" && isPseudo )
2619 // {
2620 // title = tr( "Pseudo Absorbance Data\nRun ID: " ) + ccwlong;
2621 // }
2622 //
2623 // else if ( dataType == "RI" )
2624 // {
2625 // title = tr( "Radial Intensity Data\nRun ID: " ) + ccwlong;
2626 // yLegend = tr( "Radial Intensity at " ) + wavelen + " nm";
2627 // }
2628 //
2629 // else if ( dataType == "IP" )
2630 // {
2631 // title = tr( "Interference Data\nRun ID: " ) + ccwlong;
2632 // yLegend = tr( "Fringes" );
2633 // }
2634 //
2635 // else if ( dataType == "FI" )
2636 // {
2637 // title = tr( "Fluorescence Intensity Data\nRun ID: " ) + ccwlong;
2638 // yLegend = tr( "Fluorescence Intensity" );
2639 // }
2640 //
2641 // else if ( dataType == "WA" )
2642 // {
2643 // title = tr( "Wavelength Data\nRun ID: " ) + ccwlong;
2644 // xLegend = tr( "Wavelength" );
2645 // yLegend = tr( "Value" );
2646 // }
2647 //
2648 // else if ( dataType == "WI" )
2649 // {
2650 // title = tr( "Wavelength Intensity Data\nRun ID: " ) + ccwlong;
2651 // xLegend = tr( "Wavelength" );
2652 // yLegend = tr( "Value" );
2653 // }
2654 //
2655 // else
2656 // title = tr( "File type not recognized" );
2657 //
2658 // data_plot->setTitle( title );
2659 // data_plot->setAxisTitle( QwtPlot::yLeft, yLegend );
2660 // data_plot->setAxisTitle( QwtPlot::xBottom, xLegend );
2661 //
2662 // }
2664 
2665 // void US_ConvertGui::db_error( const QString& error )
2666 // {
2667 // QMessageBox::warning( this, tr( "Database Problem" ),
2668 // tr( "Database returned the following error: \n" ) + error );
2669 // }
2670 //
2671 // // User changed the Lambda Start value
2672 // void US_ConvertGui::lambdaStartChanged( int value )
2673 // {
2674 // DbgLv(1) << "lambdaStartChanged" << value;
2675 // slambda = cb_lambstrt->itemText( value ).toInt();
2676 // elambda = cb_lambstop->currentText() .toInt();
2677 // cellchan = lw_triple->currentRow();
2678 // int currChan = all_chaninfo[ cellchan ].channelID;
2679 // DbgLv(1) << "lambdaStartChanged" << value << "sl el tLx cCh"
2680 // << slambda << elambda << cellchan << currChan;
2681 //
2682 // for ( int trx = 0; trx < all_tripinfo.count(); trx++ )
2683 // {
2684 // int iwavl = all_tripinfo[ trx ]
2685 // .tripleDesc.section( " / ", 2, 2 ).toInt();
2686 //
2687 // if ( all_tripinfo[ trx ].channelID == currChan )
2688 // all_tripinfo[ trx ].excluded = ( iwavl < slambda );
2689 // DbgLv(1) << "lStChg: trx iwavl chnID excl" << trx << iwavl
2690 // << all_tripinfo[trx].channelID << all_tripinfo[trx].excluded;
2691 // }
2692 //
2693 // build_output_data();
2694 // DbgLv(1) << "lStChg: BlOutDa RTN";
2695 // reset_lambdas();
2696 // DbgLv(1) << "lStChg: RsLambd RTN";
2697 // }
2698 //
2700 // // User changed the Lambda End value
2701 // void US_ConvertGui::lambdaEndChanged( int value )
2702 // {
2703 // DbgLv(1) << "lambdaEndChanged" << value;
2704 // slambda = cb_lambstrt->currentText() .toInt();
2705 // elambda = cb_lambstop->itemText( value ).toInt();
2706 // cellchan = lw_triple->currentRow();
2707 // int currChan = all_chaninfo[ cellchan ].channelID;
2708 // DbgLv(1) << "lEnChg: val" << value << "sl el tLx cCh"
2709 // << slambda << elambda << cellchan << currChan;
2710 //
2711 // for ( int trx = 0; trx < all_tripinfo.count(); trx++ )
2712 // {
2713 // int iwavl = all_tripinfo[ trx ]
2714 // .tripleDesc.section( " / ", 2, 2 ).toInt();
2715 //
2716 // if ( all_tripinfo[ trx ].channelID == currChan && iwavl > elambda )
2717 // all_tripinfo[ trx ].excluded = ( iwavl > elambda );
2718 // }
2719 //
2720 // build_output_data();
2721 // DbgLv(1) << "lEnChg: BlOutDa RTN";
2722 // reset_lambdas();
2723 // DbgLv(1) << "lEnChg: RsLambd RTN";
2724 // }
2726 
2727 
2728 // // User changed the Lambda Plot value
2730 {
2731  cellchan = lw_triple->currentRow();
2732  lambda = cb_lambplot->currentIndex();
2733 
2734  plot_current();
2735  pb_lambprev->setEnabled( value > 0 );
2736  pb_lambnext->setEnabled( ( value + 1 ) < cb_lambplot->count() );
2737 
2738  qDebug()<< "____________123"<<allData[cellchan].intarray[0][1];
2739 }
2740 
2741 // User clicked the Previous Lambda Plot button
2743 {
2744  int wvx = qMax( 0, cb_lambplot->currentIndex() - 1 );
2745 
2746  cb_lambplot->setCurrentIndex( wvx );
2747 }
2748 
2749 // User clicked the Next Lambda Plot button
2751 {
2752  int wvxmax = cb_lambplot->count() - 1;
2753  int wvx = qMin( wvxmax, cb_lambplot->currentIndex() + 1 );
2754 
2755  cb_lambplot->setCurrentIndex( wvx );
2756 }
2757 
2758 // Show or hide MWL controls
2760 {
2761  lb_mwlctrl ->setVisible( show );
2762  lb_lambstrt->setVisible( show );
2763  cb_lambstrt->setVisible( show );
2764  lb_lambstop->setVisible( show );
2765  cb_lambstop->setVisible( show );
2766  lb_lambplot->setVisible( show );
2767  cb_lambplot->setVisible( show );
2768  pb_lambprev->setVisible( show );
2769  pb_lambnext->setVisible( show );
2770 
2771 
2772  adjustSize();
2773 }
2774 
2775 
2776 // Turn MWL connections on or off
2777 void US_RampGui::mwl_connect( bool connect_on )
2778 {
2779  if ( connect_on )
2780  {
2781 // connect( cb_lambstrt, SIGNAL( currentIndexChanged( int ) ),
2782 // this, SLOT ( lambdaStartChanged ( int ) ) );
2783 // connect( cb_lambstop, SIGNAL( currentIndexChanged( int ) ),
2784 // this, SLOT ( lambdaEndChanged ( int ) ) );
2785  connect( cb_lambplot, SIGNAL( currentIndexChanged( int ) ),
2786  this, SLOT ( lambdaPlotChanged ( int ) ) );
2787  connect( pb_lambprev, SIGNAL( clicked ( ) ),
2788  this, SLOT ( lambdaPrevClicked ( ) ) );
2789  connect( pb_lambnext, SIGNAL( clicked ( ) ),
2790  this, SLOT ( lambdaNextClicked ( ) ) );
2791  }
2792 
2793  else
2794  {
2795  cb_lambstrt->disconnect();
2796  cb_lambstop->disconnect();
2797  cb_lambplot->disconnect();
2798  pb_lambprev->disconnect();
2799  pb_lambnext->disconnect();
2800  }
2801 }
2802 
2804 // // Reset with lambda delta,range changes
2805 // void US_ConvertGui::reset_lambdas()
2806 // {
2807 // if ( ! isMwl )
2808 // return;
2809 //
2810 // int plambda = cb_lambplot->currentText().toInt();
2811 // QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2812 //
2813 // DbgLv(1) << "rsL: slambda elambda" << slambda << elambda;
2814 // mwl_data.set_lambdas ( slambda, elambda, cellchan );
2815 // mwl_connect( false );
2816 //
2817 // nlambda = mwl_data.lambdas( exp_lambdas );
2818 // int plx = nlambda / 2;
2819 // cb_lambplot->clear();
2820 // DbgLv(1) << "rsL: nlambda" << nlambda;
2821 //
2822 // for ( int wvx = 0; wvx < nlambda; wvx++ )
2823 // { // Add to plot-lambda list and possibly detect old selection in new list
2824 // int ilamb = exp_lambdas[ wvx ];
2825 // cb_lambplot->addItem( QString::number( ilamb ) );
2826 //
2827 // if ( ilamb == plambda ) plx = wvx;
2828 // }
2829 //
2830 // DbgLv(1) << "rsL: plambda" << plambda << "plx" << plx;
2831 // cb_lambplot->setCurrentIndex( plx );
2832 //
2833 // // Rebuild list of triples
2834 // QStringList celchns;
2835 // QString pwvln = " / " + QString::number( exp_lambdas[ 0 ] )
2836 // + "-" + QString::number( exp_lambdas[ nlambda - 1 ] )
2837 // + " (" + QString::number( nlambda ) + ")";
2838 //
2839 // int ncelchn = mwl_data.cellchannels( celchns );
2840 // nlambda = mwl_data.countOf( "lambda" );
2841 // DbgLv(1) << "rsL: ncc nl szcc szci" << ncelchn << nlambda << celchns.count()
2842 // << all_chaninfo.count();
2843 //
2844 // for ( int ii = 0; ii < ncelchn; ii++ )
2845 // { // Redo internal channel information description field
2846 // all_chaninfo[ ii ].tripleDesc = celchns[ ii ] + pwvln;
2847 // }
2848 //
2849 // mwl_connect( true );
2850 // QApplication::restoreOverrideCursor();
2851 //
2852 // setTripleInfo();
2853 // DbgLv(1) << "rsL: sTrInf RTN";
2854 //
2855 // init_excludes();
2856 // DbgLv(1) << "rsL: InExcl RTN";
2857 //
2858 // plot_current();
2859 // DbgLv(1) << "rsL: PlCurr RTN";
2860 // }
2861 //
2862 
2863 //
2864 // Do MWL Gui setup after import or load of MWL data
2865 // void US_RampGui::mwl_setup()
2866 // {
2867 // mwl_connect( false );
2868 //
2869 // // Propagate initial lists of Lambdas
2870 // nlamb_i = all_lambdas.size();
2871 // int rlamb_s = all_lambdas[ 0 ];
2872 // int rlamb_e = all_lambdas[ nlamb_i - 1 ];
2873 // cb_lambstrt->clear();
2874 // cb_lambstop->clear();
2875 //
2876 // // for ( int ii = 0; ii < nlamb_i; ii++ )
2877 // // {
2878 // // QString clamb = QString::number( all_lambdas[ ii ] );
2879 // // cb_lambstrt->addItem( clamb );
2880 // // cb_lambstop->addItem( clamb );
2881 // // }
2882 // //
2883 // // cb_lambstrt->setCurrentIndex( 0 );
2884 // // cb_lambstop->setCurrentIndex( nlamb_i - 1 );
2885 // // nlambda = mwl_data.lambdas( exp_lambdas );
2886 // // cb_lambplot->clear();
2887 // //
2888 // // for ( int ii = 0; ii < nlambda; ii++ )
2889 // // {
2890 // // QString clamb = QString::number( exp_lambdas[ ii ] );
2891 // // cb_lambplot->addItem( clamb );
2892 // // }
2893 //
2894 // // cb_lambplot->setCurrentIndex( nlambda / 2 );
2895 // //
2896 // // show_mwl_control( true );
2897 // mwl_connect( true );
2898 //
2899 // // setTripleInfo();
2900 // // le_description -> setText( allData[ 0 ].description );
2901 // //
2902 // // // Initialize exclude list
2903 // // init_excludes();
2904 //
2905 // plot_current();
2906 //
2907 // saveStatus = NOT_SAVED;
2908 //
2909 // // // Ok to enable some buttons now
2910 // enableControls();
2911 //
2912 // static QChar clambda( 955 ); // Lambda character
2913 // QString lambmsg = tr( "%1 raw: %2 %3 to %4" )
2914 // .arg( nlamb_i ).arg( clambda ).arg( rlamb_s ).arg( rlamb_e );
2915 // le_lambraw->setText( lambmsg );
2916 // qApp->processEvents();
2917 // adjustSize();
2918 // }
2919 
2920 // Initialize output data pointers and lists
2922 {
2923 
2924  outData .clear();
2925  all_chaninfo.clear();
2926 
2927  // Set up initial export-data pointers list and all/out lists
2928  for ( int trx = 0; trx < allData.size(); trx++ )
2929  {
2930  US_mwlRamp::RampRawData* edata = &allData[ trx ];
2931 // US_Convert::TripleInfo tripinfo;
2932  US_Ramp::TripleInfo chaninfo;
2933 
2934  outData << edata;
2935 
2936  QString celchn = QString( edata->cell ) + " / "
2937  + QString( edata->chan );
2938  chaninfo.tripleID = trx + 1;
2939  chaninfo.description = edata->description;
2940  chaninfo.excluded = false;
2941  chaninfo = chaninfo;
2942  chaninfo.tripleDesc = celchn;
2943 
2944  all_chaninfo << chaninfo;
2945 
2946  }
2947 }
2948