UltraScan III
us_eqmodel_control.cpp
Go to the documentation of this file.
1 
3 #include "us_eqmodel_control.h"
4 #include "us_settings.h"
5 #include "us_gui_settings.h"
6 #include "us_constants.h"
7 #include "us_math2.h"
8 #include "us_analyte_gui.h"
9 #include "us_buffer_gui.h"
10 #include "us_db2.h"
11 
12 // Main constructor with references to parameters from main GlobalEquil class
14  QVector< EqScanFit >& a_scanfits,
15  EqRunFit& a_runfit,
16  US_DataIO::EditedData* a_edata,
17  int a_modelx,
18  QStringList a_models,
19  bool& a_mWidget,
20  int& a_selscan )
21  : US_WidgetsDialog( 0, 0 ),
22  scanfits ( a_scanfits ),
23  runfit ( a_runfit ),
24  edata ( a_edata ),
25  modelx ( a_modelx ),
26  models ( a_models ),
27  mWidget ( a_mWidget ),
28  selscan ( a_selscan )
29 {
30  setAttribute ( Qt::WA_DeleteOnClose );
31  setWindowTitle( tr( "Equilibrium Model Control Window" ) );
32  setPalette ( US_GuiSettings::frameColor() );
33  setMinimumSize( 200, 100 );
34 
35  // Main layout
36  QBoxLayout* main = new QVBoxLayout( this );
37  main->setContentsMargins( 2, 2, 2, 2 );
38  main->setSpacing ( 2 );
39 
40  // Two primary layouts
41  QGridLayout* globalLayout = new QGridLayout;
42  QGridLayout* localLayout = new QGridLayout;
43 
44  // Global layout
46  QLabel* lb_grunpar = us_label(
47  tr( "Global Run Parameters for Component: " ) );
48  ct_grunpar = us_counter( 2, 1, 100, 1 );
49  QLabel* lb_param = us_label( tr( "Parameter:" ) );
50  QLabel* lb_guess = us_label( tr( "Initial Guess:" ) );
51  QLabel* lb_bounds = us_label( tr( "+/- Bounds:" ) );
52  QLabel* lb_units = us_label( tr( "Units" ) );
53  QLabel* lb_float = us_label( tr( "Float:" ) );
54  QLabel* lb_lock = us_label( tr( "Lock:" ) );
55  QLabel* lb_bound = us_label( tr( "Bound:" ) );
56  lb_molecwt = us_label( tr( "Molecular Weight" ) + " (1):" );
59  QLabel* lb_mwunits = us_label( tr( "Dalton" ) );
60  QGridLayout* lo_mwfloat = us_radiobutton( "F", rb_mwfloat, true );
61  QGridLayout* lo_mwlock = us_radiobutton( "L", rb_mwlock, false );
62  QHBoxLayout* lo_mwflbox = radiobox( lo_mwfloat, rb_mwfloat,
63  lo_mwlock, rb_mwlock );
64  QLayout* lo_mwbound = us_checkbox( "B", ck_mwbound, false );
65  pb_vbar20 = us_pushbutton( tr( "Vbar, 20" ) + DEGC + " (1):" );
68  QLabel* lb_vbunits = us_label( tr( "ccm/g" ) );
69  QGridLayout* lo_vbfloat = us_radiobutton( "F", rb_vbfloat, true );
70  QGridLayout* lo_vblock = us_radiobutton( "L", rb_vblock, false );
71  QHBoxLayout* lo_vbflbox = radiobox( lo_vbfloat, rb_vbfloat,
72  lo_vblock, rb_vblock );
73  QLayout* lo_vbbound = us_checkbox( "B", ck_vbbound, false );
74  pb_lnasc1 = us_pushbutton( tr( "ln(Assoc.Const.1):" ) );
77  QLabel* lb_l1units = us_label( tr( "" ) );
78  QGridLayout* lo_l1float = us_radiobutton( "F", rb_l1float, true );
79  QGridLayout* lo_l1lock = us_radiobutton( "L", rb_l1lock, false );
80  QHBoxLayout* lo_l1flbox = radiobox( lo_l1float, rb_l1float,
81  lo_l1lock, rb_l1lock );
82  QLayout* lo_l1bound = us_checkbox( "B", ck_l1bound, false );
83  pb_lnasc2 = us_pushbutton( tr( "ln(Assoc.Const.2):" ) );
86  QLabel* lb_l2units = us_label( tr( "" ) );
87  QGridLayout* lo_l2float = us_radiobutton( "F", rb_l2float, true );
88  QGridLayout* lo_l2lock = us_radiobutton( "L", rb_l2lock, false );
89  QHBoxLayout* lo_l2flbox = radiobox( lo_l2float, rb_l2float,
90  lo_l2lock, rb_l2lock );
91  QLayout* lo_l2bound = us_checkbox( "B", ck_l2bound, false );
92  pb_lnasc3 = us_pushbutton( tr( "ln(Assoc.Const.3):" ) );
95  QLabel* lb_l3units = us_label( tr( "" ) );
96  QGridLayout* lo_l3float = us_radiobutton( "F", rb_l3float, true );
97  QGridLayout* lo_l3lock = us_radiobutton( "L", rb_l3lock, false );
98  QHBoxLayout* lo_l3flbox = radiobox( lo_l3float, rb_l3float,
99  lo_l3lock, rb_l3lock );
100  QLayout* lo_l3bound = us_checkbox( "B", ck_l3bound, false );
101  pb_lnasc4 = us_pushbutton( tr( "ln(Assoc.Const.4):" ) );
104  QLabel* lb_l4units = us_label( tr( "" ) );
105  QGridLayout* lo_l4float = us_radiobutton( "F", rb_l4float, true );
106  QGridLayout* lo_l4lock = us_radiobutton( "L", rb_l4lock, false );
107  QHBoxLayout* lo_l4flbox = radiobox( lo_l4float, rb_l4float,
108  lo_l4lock, rb_l4lock );
109  QLayout* lo_l4bound = us_checkbox( "B", ck_l4bound, false );
110 
111  int row = 0;
112  globalLayout->addWidget( lb_gbanner, row++, 0, 1, 10 );
113  globalLayout->addWidget( lb_grunpar, row, 0, 1, 7 );
114  globalLayout->addWidget( ct_grunpar, row++, 7, 1, 3 );
115  globalLayout->addWidget( lb_param, row, 0, 1, 2 );
116  globalLayout->addWidget( lb_guess, row, 2, 1, 2 );
117  globalLayout->addWidget( lb_bounds, row, 4, 1, 2 );
118  globalLayout->addWidget( lb_units, row, 6, 1, 1 );
119  globalLayout->addWidget( lb_float, row, 7, 1, 1 );
120  globalLayout->addWidget( lb_lock, row, 8, 1, 1 );
121  globalLayout->addWidget( lb_bound, row++, 9, 1, 1 );
122  globalLayout->addWidget( lb_molecwt, row, 0, 1, 2 );
123  globalLayout->addWidget( le_mwguess, row, 2, 1, 2 );
124  globalLayout->addWidget( le_mwbound, row, 4, 1, 2 );
125  globalLayout->addWidget( lb_mwunits, row, 6, 1, 1 );
126  globalLayout->addLayout( lo_mwflbox, row, 7, 1, 2 );
127  globalLayout->addLayout( lo_mwbound, row++, 9, 1, 1 );
128  globalLayout->addWidget( pb_vbar20, row, 0, 1, 2 );
129  globalLayout->addWidget( le_vbguess, row, 2, 1, 2 );
130  globalLayout->addWidget( le_vbbound, row, 4, 1, 2 );
131  globalLayout->addWidget( lb_vbunits, row, 6, 1, 1 );
132  globalLayout->addLayout( lo_vbflbox, row, 7, 1, 2 );
133  globalLayout->addLayout( lo_vbbound, row++, 9, 1, 1 );
134  globalLayout->addWidget( pb_lnasc1, row, 0, 1, 2 );
135  globalLayout->addWidget( le_l1guess, row, 2, 1, 2 );
136  globalLayout->addWidget( le_l1bound, row, 4, 1, 2 );
137  globalLayout->addWidget( lb_l1units, row, 6, 1, 1 );
138  globalLayout->addLayout( lo_l1flbox, row, 7, 1, 2 );
139  globalLayout->addLayout( lo_l1bound, row++, 9, 1, 1 );
140  globalLayout->addWidget( pb_lnasc2, row, 0, 1, 2 );
141  globalLayout->addWidget( le_l2guess, row, 2, 1, 2 );
142  globalLayout->addWidget( le_l2bound, row, 4, 1, 2 );
143  globalLayout->addWidget( lb_l2units, row, 6, 1, 1 );
144  globalLayout->addLayout( lo_l2flbox, row, 7, 1, 2 );
145  globalLayout->addLayout( lo_l2bound, row++, 9, 1, 1 );
146  globalLayout->addWidget( pb_lnasc3, row, 0, 1, 2 );
147  globalLayout->addWidget( le_l3guess, row, 2, 1, 2 );
148  globalLayout->addWidget( le_l3bound, row, 4, 1, 2 );
149  globalLayout->addWidget( lb_l3units, row, 6, 1, 1 );
150  globalLayout->addLayout( lo_l3flbox, row, 7, 1, 2 );
151  globalLayout->addLayout( lo_l3bound, row++, 9, 1, 1 );
152  globalLayout->addWidget( pb_lnasc4, row, 0, 1, 2 );
153  globalLayout->addWidget( le_l4guess, row, 2, 1, 2 );
154  globalLayout->addWidget( le_l4bound, row, 4, 1, 2 );
155  globalLayout->addWidget( lb_l4units, row, 6, 1, 1 );
156  globalLayout->addLayout( lo_l4flbox, row, 7, 1, 2 );
157  globalLayout->addLayout( lo_l4bound, row++, 9, 1, 1 );
158 
159  pb_lnasc1 ->setEnabled( false );
160  pb_lnasc2 ->setEnabled( false );
161  pb_lnasc3 ->setEnabled( false );
162  pb_lnasc4 ->setEnabled( false );
163  ck_mwbound->setEnabled( false );
164  ck_vbbound->setEnabled( false );
165  ck_l1bound->setEnabled( false );
166  ck_l2bound->setEnabled( false );
167  ck_l3bound->setEnabled( false );
168  ck_l4bound->setEnabled( false );
169  le_mwbound->setEnabled( false );
170  le_vbbound->setEnabled( false );
171  le_l1bound->setEnabled( false );
172  le_l2bound->setEnabled( false );
173  le_l3bound->setEnabled( false );
174  le_l4bound->setEnabled( false );
175  us_setReadOnly( le_mwbound, true );
176  us_setReadOnly( le_vbbound, true );
177  us_setReadOnly( le_l1bound, true );
178  us_setReadOnly( le_l2bound, true );
179  us_setReadOnly( le_l3bound, true );
180  us_setReadOnly( le_l4bound, true );
181 
182  ct_grunpar->setRange( 1, runfit.nbr_comps, 1 );
183  ct_grunpar->setStep( 1 );
184  ct_grunpar->setValue( 1 );
185 
186  connect( ct_grunpar, SIGNAL( valueChanged( double ) ),
187  this, SLOT( global_comp_changed( double ) ) );
188  connect( pb_vbar20, SIGNAL( clicked() ),
189  this, SLOT( set_vbar() ) );
190  connect( rb_mwfloat, SIGNAL( toggled( bool ) ),
191  this, SLOT( update_floats() ) );
192  connect( rb_vbfloat, SIGNAL( toggled( bool ) ),
193  this, SLOT( update_floats() ) );
194  connect( rb_l1float, SIGNAL( toggled( bool ) ),
195  this, SLOT( update_floats() ) );
196  connect( rb_l2float, SIGNAL( toggled( bool ) ),
197  this, SLOT( update_floats() ) );
198  connect( rb_l3float, SIGNAL( toggled( bool ) ),
199  this, SLOT( update_floats() ) );
200  connect( rb_l4float, SIGNAL( toggled( bool ) ),
201  this, SLOT( update_floats() ) );
202 
203  // Local layout
205  tr( "Local Scan Parameters for Scan %1" ).arg( selscan ) );
206  QLabel* lb_cdescr = us_label( tr( "Cell Description:" ) );
207  le_cdescr = us_lineedit( "", 0, true );
208  QLabel* lb_runid = us_label( tr( "Run ID:" ) );
209  le_runid = us_lineedit( "", 0, true );
210  QLabel* lb_tempera = us_label( tr( "Temperature (" ) + DEGC + "):" );
211  le_tempera = us_lineedit( "", 0, true );
212  QLabel* lb_speed = us_label( tr( "Rotor Speed (rpm)" ) );
213  le_speed = us_lineedit( "", 0, true );
214  QLabel* lb_wavelen = us_label( tr( "Wavelength (nm)" ) );
216  QLabel* lb_pathlen = us_label( tr( "Cell Pathlength (cm)" ) );
218  pb_plenapp = us_pushbutton( tr( "Apply to:" ) );
219  QLabel* lb_plenscn = us_label( tr( "Scan(s)" ) );
221  QLabel* lb_baseln = us_label( tr( "Baseline:" ) );
224  QLabel* lb_blunits = us_label( tr( "OD" ) );
225  QGridLayout* lo_blfloat = us_radiobutton( "F", rb_blfloat, true );
226  QGridLayout* lo_bllock = us_radiobutton( "L", rb_bllock, false );
227  QHBoxLayout* lo_blflbox = radiobox( lo_blfloat, rb_blfloat,
228  lo_bllock, rb_bllock );
229  QLayout* lo_blbound = us_checkbox( "B", ck_blbound, false );
230  pb_density = us_pushbutton( tr( "Density, 20" ) + DEGC );
232  pb_densapp = us_pushbutton( tr( "Apply to:" ) );
233  QLabel* lb_densscn = us_label( tr( "Scan(s)" ) );
235  QLabel* lb_param2 = us_label( tr( "Parameter:" ) );
236  QLabel* lb_guess2 = us_label( tr( "Initial Guess:" ) );
237  QLabel* lb_bounds2 = us_label( tr( "+/- Bounds:" ) );
238  QLabel* lb_units2 = us_label( tr( "Units" ) );
239  QLabel* lb_float2 = us_label( tr( "Float:" ) );
240  QLabel* lb_lock2 = us_label( tr( "Lock:" ) );
241  QLabel* lb_bound2 = us_label( tr( "Bound:" ) );
242  QLabel* lb_lrunpar = us_label(
243  tr( "Local Scan Parameters for Component: " ) );
244  ct_lrunpar = us_counter( 2, 1, 100, 1 );
245  QLabel* lb_param3 = us_label( tr( "Parameter:" ) );
246  QLabel* lb_guess3 = us_label( tr( "Initial Guess:" ) );
247  QLabel* lb_bounds3 = us_label( tr( "+/- Bounds:" ) );
248  QLabel* lb_units3 = us_label( tr( "Units" ) );
249  QLabel* lb_float3 = us_label( tr( "Float:" ) );
250  QLabel* lb_lock3 = us_label( tr( "Lock:" ) );
251  QLabel* lb_bound3 = us_label( tr( "Bound:" ) );
252  lb_amplitu = us_label( tr( "Amplitude" ) + " (1):" );
255  QLabel* lb_amunits = us_label( tr( "OD" ) );
256  QGridLayout* lo_amfloat = us_radiobutton( "F", rb_amfloat, true );
257  QGridLayout* lo_amlock = us_radiobutton( "L", rb_amlock, false );
258  QHBoxLayout* lo_amflbox = radiobox( lo_amfloat, rb_amfloat,
259  lo_amlock, rb_amlock );
260  QLayout* lo_ambound = us_checkbox( "B", ck_ambound, false );
261  pb_extinct = us_pushbutton( tr( "Extinction" ) + " (1):" );
262  le_extinct = us_lineedit( "1.0" );
263  pb_extiapp = us_pushbutton( tr( "Apply to:" ) );
264  QLabel* lb_extiscn = us_label( tr( "Scan(s)" ) );
266  QLabel* lb_sigma = us_label( tr( "Sigma for this Scan:" ) );
267  le_sigma = us_lineedit( "0", 0, true );
268  QLayout* lo_inclfit = us_checkbox(
269  tr( "Include this Scan in the Fit:" ), ck_inclfit, false );
270  QLabel* lb_scansel = us_label( tr( "Scan Selector:" ) );
271  ct_scansel = us_counter( 3, 1, 100, 1 );
272  QString extintt = tr( "Extinction coefficient in units of"
273  " OD / (cm * mol)" );
274  pb_extinct->setToolTip( extintt );
275  le_extinct->setToolTip( extintt );
276 
277  row = 0;
278  localLayout->addWidget( lb_lbanner, row++, 0, 1, 10 );
279  localLayout->addWidget( lb_cdescr, row, 0, 1, 2 );
280  localLayout->addWidget( le_cdescr, row++, 2, 1, 8 );
281  localLayout->addWidget( lb_runid, row, 0, 1, 2 );
282  localLayout->addWidget( le_runid, row, 2, 1, 2 );
283  localLayout->addWidget( lb_tempera, row, 4, 1, 2 );
284  localLayout->addWidget( le_tempera, row++, 6, 1, 2 );
285  localLayout->addWidget( lb_speed, row, 0, 1, 2 );
286  localLayout->addWidget( le_speed, row, 2, 1, 2 );
287  localLayout->addWidget( lb_wavelen, row, 4, 1, 2 );
288  localLayout->addWidget( le_wavelen, row++, 6, 1, 2 );
289  localLayout->addWidget( lb_pathlen, row, 0, 1, 2 );
290  localLayout->addWidget( le_pathlen, row, 2, 1, 2 );
291  localLayout->addWidget( pb_plenapp, row, 4, 1, 2 );
292  localLayout->addWidget( lb_plenscn, row, 6, 1, 2 );
293  localLayout->addWidget( le_plenscn, row++, 8, 1, 2 );
294  localLayout->addWidget( lb_param2, row, 0, 1, 2 );
295  localLayout->addWidget( lb_guess2, row, 2, 1, 2 );
296  localLayout->addWidget( lb_bounds2, row, 4, 1, 2 );
297  localLayout->addWidget( lb_units2, row, 6, 1, 1 );
298  localLayout->addWidget( lb_float2, row, 7, 1, 1 );
299  localLayout->addWidget( lb_lock2, row, 8, 1, 1 );
300  localLayout->addWidget( lb_bound2, row++, 9, 1, 1 );
301  localLayout->addWidget( lb_baseln, row, 0, 1, 2 );
302  localLayout->addWidget( le_blguess, row, 2, 1, 2 );
303  localLayout->addWidget( le_blbound, row, 4, 1, 2 );
304  localLayout->addWidget( lb_blunits, row, 6, 1, 1 );
305  localLayout->addLayout( lo_blflbox, row, 7, 1, 2 );
306  localLayout->addLayout( lo_blbound, row++, 9, 1, 1 );
307  localLayout->addWidget( pb_density, row, 0, 1, 2 );
308  localLayout->addWidget( le_density, row, 2, 1, 2 );
309  localLayout->addWidget( pb_densapp, row, 4, 1, 2 );
310  localLayout->addWidget( lb_densscn, row, 6, 1, 2 );
311  localLayout->addWidget( le_densscn, row++, 8, 1, 2 );
312  localLayout->addWidget( lb_lrunpar, row, 0, 1, 7 );
313  localLayout->addWidget( ct_lrunpar, row++, 7, 1, 3 );
314  localLayout->addWidget( lb_param3, row, 0, 1, 2 );
315  localLayout->addWidget( lb_guess3, row, 2, 1, 2 );
316  localLayout->addWidget( lb_bounds3, row, 4, 1, 2 );
317  localLayout->addWidget( lb_units3, row, 6, 1, 1 );
318  localLayout->addWidget( lb_float3, row, 7, 1, 1 );
319  localLayout->addWidget( lb_lock3, row, 8, 1, 1 );
320  localLayout->addWidget( lb_bound3, row++, 9, 1, 1 );
321  localLayout->addWidget( lb_amplitu, row, 0, 1, 2 );
322  localLayout->addWidget( le_amguess, row, 2, 1, 2 );
323  localLayout->addWidget( le_ambound, row, 4, 1, 2 );
324  localLayout->addWidget( lb_amunits, row, 6, 1, 1 );
325  localLayout->addLayout( lo_amflbox, row, 7, 1, 2 );
326  localLayout->addLayout( lo_ambound, row++, 9, 1, 1 );
327  localLayout->addWidget( pb_extinct, row, 0, 1, 2 );
328  localLayout->addWidget( le_extinct, row, 2, 1, 2 );
329  localLayout->addWidget( pb_extiapp, row, 4, 1, 2 );
330  localLayout->addWidget( lb_extiscn, row, 6, 1, 2 );
331  localLayout->addWidget( le_extiscn, row++, 8, 1, 2 );
332  localLayout->addWidget( lb_sigma, row, 0, 1, 2 );
333  localLayout->addWidget( le_sigma, row++, 2, 1, 2 );
334  localLayout->addLayout( lo_inclfit, row, 0, 1, 4 );
335  localLayout->addWidget( lb_scansel, row, 4, 1, 3 );
336  localLayout->addWidget( ct_scansel, row++, 7, 1, 3 );
337 
338  ck_inclfit->setEnabled( false );
339  ck_blbound->setEnabled( false );
340  ck_blbound->setEnabled( false );
341  ck_ambound->setEnabled( false );
342  le_blbound->setEnabled( false );
343  le_ambound->setEnabled( false );
344  us_setReadOnly( le_tempera, true );
345  us_setReadOnly( le_wavelen, true );
346  us_setReadOnly( le_blbound, true );
347  us_setReadOnly( le_ambound, true );
348 
349  connect( ct_lrunpar, SIGNAL( valueChanged( double ) ),
350  this, SLOT( local_comp_changed( double ) ) );
351  connect( ct_scansel, SIGNAL( valueChanged( double ) ),
352  this, SLOT( scan_changed( double ) ) );
353  connect( rb_blfloat, SIGNAL( toggled( bool ) ),
354  this, SLOT( update_floats() ) );
355  connect( rb_amfloat, SIGNAL( toggled( bool ) ),
356  this, SLOT( update_floats() ) );
357  connect( pb_plenapp, SIGNAL( clicked() ),
358  this, SLOT( pathlen_applyto() ) );
359  connect( pb_density, SIGNAL( clicked() ),
360  this, SLOT( set_density() ) );
361  connect( pb_densapp, SIGNAL( clicked() ),
362  this, SLOT( density_applyto() ) );
363  connect( pb_extiapp, SIGNAL( clicked() ),
364  this, SLOT( extinct_applyto() ) );
365  ct_lrunpar->setRange( 1, runfit.nbr_comps, 1 );
366  ct_lrunpar->setStep( 1 );
367  ct_scansel->setRange( 1, scanfits.size(), 1 );
368  ct_scansel->setStep( 1 );
369  send_signal = false;
370  ct_scansel->setValue( selscan );
371  send_signal = true;
372  scan_changed( (double)selscan );
373 
374  // Button Row (spacer, help, close)
375  QHBoxLayout* buttons = new QHBoxLayout;
376 
377  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
378  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
379  connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
380  connect( pb_close, SIGNAL( clicked() ), SLOT( selected() ) );
381  buttons->addStretch( );
382  buttons->addWidget( pb_help );
383  buttons->addWidget( pb_close );
384  buttons->setStretch( 0, 2 );
385  buttons->setStretch( 1, 1 );
386  buttons->setStretch( 2, 1 );
387 
388  main->addLayout( globalLayout );
389  main->addLayout( localLayout );
390  main->addLayout( buttons );
391 
392  // Set values from input data
393  int scanx = selscan - 1;
394  le_cdescr ->setText( scanfits[ scanx ].descript );
395  le_runid ->setText( scanfits[ scanx ].runID );
396  le_tempera->setText( QString::number( scanfits[ scanx ].tempera ) );
397  le_speed ->setText( QString::number( scanfits[ scanx ].rpm ) );
398  le_wavelen->setText( QString::number( scanfits[ scanx ].wavelen ) );
399  le_pathlen->setText( QString::number( scanfits[ scanx ].pathlen ) );
400  le_blguess->setText( QString::number( scanfits[ scanx ].baseline ) );
401  le_blbound->setText( QString::number( scanfits[ scanx ].baseln_rng ) );
402  le_density->setText( QString::number( scanfits[ scanx ].density ) );
403  le_extinct->setText( QString::number( scanfits[ scanx ].extincts[ 0 ] ) );
404 
405  le_densscn->setText( "1" );
406  le_extiscn->setText( "1" );
407 
408  global_comp_changed( 1.0 );
409  local_comp_changed( 1.0 );
410  connect_global();
411  connect_local();
412 
413  // Resize to fit elements added
414  adjustSize();
415 
416  setMinimumSize( 600, 500 );
417 
418  chng_floats = true;
419 }
420 
421 // Public slot to reset scan number
422 void US_EqModelControl::new_scan( int scannbr )
423 {
424 qDebug() << "EMC: new_scan" << scannbr;
425  send_signal = false;
426  selscan = scannbr;
427 
428  ct_scansel->setValue( (double)selscan );
429  send_signal = true;
430 }
431 
432 // Public slot to reset general components when runfit and scanfits change
434 {
435 qDebug() << "EMC: new_components" << modelx;
436  double dscn = ct_scansel->value();
437  double dgco = ct_grunpar->value();
438  double dlco = ct_lrunpar->value();
439 
440  // To reset values, we simulate new scan and global,local component numbers
441  send_signal = false;
442  scan_changed ( dscn );
443  global_comp_changed( dgco );
444  local_comp_changed ( dlco );
445  send_signal = true;
446 }
447 
448 // Public slot to reset all floated/locked check boxes
449 void US_EqModelControl::set_float( bool floated )
450 {
451 qDebug() << "EMC: set_float" << floated;
452  chng_floats = false;
453 
454  if ( floated )
455  {
456  rb_mwfloat->setChecked( floated );
457  rb_vbfloat->setChecked( floated );
458  rb_l1float->setChecked( floated );
459  rb_l2float->setChecked( floated );
460  rb_l3float->setChecked( floated );
461  rb_l4float->setChecked( floated );
462  rb_blfloat->setChecked( floated );
463  rb_amfloat->setChecked( floated );
464  }
465 
466  else
467  {
468  rb_mwlock ->setChecked( true );
469  rb_vblock ->setChecked( true );
470  rb_l1lock ->setChecked( true );
471  rb_l2lock ->setChecked( true );
472  rb_l3lock ->setChecked( true );
473  rb_l4lock ->setChecked( true );
474  rb_bllock ->setChecked( true );
475  rb_amlock ->setChecked( true );
476  }
477 
478  chng_floats = true;
479  int gcmpn = (int)ct_grunpar->value();
480  int scann = selscan;
481  int lcmpn = (int)ct_lrunpar->value();
482 
483  for ( int compn = 1; compn <= runfit.nbr_comps; compn++ )
484  {
485  ct_grunpar->setValue( compn );
486  update_floats();
487  }
488 
489  ct_grunpar->setValue( gcmpn );
490 
491  for ( selscan = 1; selscan <= scanfits.size(); selscan++ )
492  {
493  for ( int compn = 1; compn <= runfit.nbr_comps; compn++ )
494  {
495  ct_lrunpar->setValue( compn );
496  update_floats();
497  }
498  }
499 
500  ct_lrunpar->setValue( lcmpn );
501  selscan = scann;
502 }
503 
504 // Private slot for change in scan number
506 {
507 qDebug() << "EMC: scan_changed" << value;
508  selscan = (int)value;
509  QString ltext = lb_lbanner->text();
510  int jj = ltext.lastIndexOf( " " ) + 1;
511  int nch = ltext.mid( jj ).length();
512  QString scan_s = QString::number( selscan );
513  ltext.replace( jj, nch, scan_s );
514  lb_lbanner->setText( ltext );
515  le_plenscn->setText( scan_s );
516  le_densscn->setText( scan_s );
517  le_extiscn->setText( scan_s );
518 
520 
521  int scanx = selscan - 1;
522  le_cdescr ->setText( scanfits[ scanx ].descript );
523  le_runid ->setText( scanfits[ scanx ].runID );
524  le_tempera->setText( QString::number( scanfits[ scanx ].tempera ) );
525  le_speed ->setText( QString::number( scanfits[ scanx ].rpm ) );
526  le_wavelen->setText( QString::number( scanfits[ scanx ].wavelen ) );
527  le_pathlen->setText( QString::number( scanfits[ scanx ].pathlen ) );
528  le_blguess->setText( QString::number( scanfits[ scanx ].baseline ) );
529  le_blbound->setText( QString::number( scanfits[ scanx ].baseln_rng ) );
530  bool scnFit = scanfits[ scanx ].scanFit;
531  ck_inclfit->setChecked( scnFit );
532  us_setReadOnly( le_blguess, ! scnFit );
533  us_setReadOnly( le_amguess, ! scnFit );
534  int compx = (int)ct_lrunpar->value() - 1;
535  double ampv = scanfits[ scanx ].amp_vals[ compx ];
536  double ampb = scanfits[ scanx ].amp_rngs[ compx ];
537  ampb = ( ampb == 0.0 ) ? ( ampv * 0.2 ) : ampb;
538  le_amguess->setText( QString::number( ampv ) );
539  le_ambound->setText( QString::number( ampb ) );
540  jj = min( scanfits[ scanx ].extincts.size() - 1, compx );
541  le_extinct->setText( QString::number( scanfits[ scanx ].extincts[ jj ] ) );
542  le_density->setText( QString::number( scanfits[ scanx ].density ) );
543  chng_floats = false;
544 
545  if ( scanfits[ scanx ].baseln_fit )
546  rb_blfloat->setChecked( true );
547  else
548  rb_bllock ->setChecked( true );
549 
550  if ( scanfits[ scanx ].amp_fits[ compx ] )
551  rb_amfloat->setChecked( true );
552  else
553  rb_amlock ->setChecked( true );
554 
555  chng_floats = true;
556 
557  if ( send_signal )
558  {
559  emit update_scan( selscan );
560  }
561 
562  else
563  send_signal = true;
564 
565  update_sigma();
566  connect_local();
567 }
568 
569 // Private slot for change in global component number
571 {
572 qDebug() << "EMC: global_comp_changed" << value;
573  int compn = (int)value;
574  int compx = compn - 1;
575  QString molwlb = lb_molecwt->text();
576  QString vbarpb = pb_vbar20 ->text();
577  QString comp_s = QString::number( compn );
578  int mwnx = molwlb.lastIndexOf( "(" ) + 1;
579  int lnmwr = molwlb.mid( mwnx ).lastIndexOf( ")" );
580  int vbnx = vbarpb.lastIndexOf( "(" ) + 1;
581  int lnvbr = vbarpb.mid( vbnx ).lastIndexOf( ")" );
582 
584  molwlb.replace( mwnx, lnmwr, comp_s );
585  vbarpb.replace( vbnx, lnvbr, comp_s );
586  lb_molecwt->setText( molwlb );
587  pb_vbar20 ->setText( vbarpb );
588 
589  le_mwguess->setText( QString::number( runfit.mw_vals[ compx ] ) );
590  le_mwbound->setText( QString::number( runfit.mw_rngs[ compx ] ) );
591  le_vbguess->setText( QString::number( runfit.vbar_vals[ compx ] ) );
592  le_vbbound->setText( QString::number( runfit.vbar_rngs[ compx ] ) );
593  chng_floats = false;
594 
595  if ( runfit.mw_fits [ compx ] )
596  rb_mwfloat->setChecked( true );
597  else
598  rb_mwlock ->setChecked( true );
599 
600  if ( runfit.vbar_fits[ compx ] )
601  rb_vbfloat->setChecked( true );
602  else
603  rb_vblock ->setChecked( true );
604 
605  if ( runfit.eq_fits [ 0 ] )
606  rb_l1float->setChecked( true );
607  else
608  rb_l1lock ->setChecked( true );
609 
610  if ( runfit.eq_fits [ 1 ] )
611  rb_l2float->setChecked( true );
612  else
613  rb_l2lock ->setChecked( true );
614 
615  if ( runfit.eq_fits [ 2 ] )
616  rb_l3float->setChecked( true );
617  else
618  rb_l3lock ->setChecked( true );
619 
620  if ( runfit.eq_fits [ 3 ] )
621  rb_l4float->setChecked( true );
622  else
623  rb_l4lock ->setChecked( true );
624 
625  chng_floats = true;
626 
627  update_sigma();
628  connect_global();
629 }
630 
631 // Private slot for change in local component number
633 {
634 qDebug() << "EMC: local_comp_changed" << value;
635  int compn = (int)value;
636  int compx = compn - 1;
637  int scanx = selscan - 1;
639 
640  QString ampllb = lb_amplitu->text();
641  QString extipb = pb_extinct->text();
642  QString comp_s = QString::number( compn );
643  int amnx = ampllb.lastIndexOf( "(" ) + 1;
644  int lnamr = ampllb.mid( amnx ).lastIndexOf( ")" );
645  int exnx = extipb.lastIndexOf( "(" ) + 1;
646  int lnexr = extipb.mid( exnx ).lastIndexOf( ")" );
647  ampllb.replace( amnx, lnamr, comp_s );
648  extipb.replace( exnx, lnexr, comp_s );
649  lb_amplitu->setText( ampllb );
650  pb_extinct->setText( extipb );
651 
652  double ampv = scanfits[ scanx ].amp_vals[ compx ];
653  double ampb = scanfits[ scanx ].amp_rngs[ compx ];
654  ampb = ( ampb == 0.0 ) ? ( ampv * 0.2 ) : ampb;
655  le_amguess->setText( QString::number( ampv ) );
656  le_ambound->setText( QString::number( ampb ) );
657  le_density->setText( QString::number( scanfits[ scanx ].density ) );
658  int jj = min( scanfits[ scanx ].extincts.size() - 1, compx );
659  le_extinct->setText( QString::number( scanfits[ scanx ].extincts[ jj ] ) );
660  chng_floats = false;
661  rb_amfloat->setChecked( scanfits[ scanx ].amp_fits[ compx ] );
662  chng_floats = true;
663 
664  update_sigma();
665  connect_local();
666 }
667 
668 // Select Model button: set up to return data information
670 {
671  update_gvals();
672  update_lvals();
673 
674  accept();
675  mWidget = false;
676  close();
677 }
678 
679 // Update the sigma field after changes in molecular weight
681 {
682 qDebug() << "EMC: update_sigma";
683  int scanx = selscan - 1;
684  int compx = (int)ct_grunpar->value() - 1;
685  EqScanFit* sfit = &scanfits[ scanx ];
686  double molecwt = runfit.mw_vals [ compx ];
687  double vbar20 = runfit.vbar_vals[ compx ];
688  double tempa = sfit->tempera;
689  double density = sfit->density;
690  double viscos = sfit->viscosity;
691  double tempk = tempa + K0;
692  double vbar = US_Math2::adjust_vbar20( vbar20, tempa );
693  double omega_s = sq( sfit->rpm * M_PI / 30.0 );
694 
695  US_Math2::SolutionData solution;
696  solution.vbar20 = vbar20;
697  solution.vbar = vbar;
698  solution.density = density;
699  solution.viscosity = viscos;
700 
701  US_Math2::data_correction( tempa, solution );
702 
703  double sigma = ( 1.0 - vbar * solution.density_tb ) * omega_s * molecwt
704  / ( 2.0 * R * tempk );
705  le_sigma->setText( QString::number( sigma ) );
706 qDebug() << "EMC: u_s: scanx compx" << scanx << compx;
707 qDebug() << "EMC: u_s: mw vbar20 vbar" << molecwt << vbar20 << vbar;
708 qDebug() << "EMC: u_s: dens dens_tb" << density << solution.density_tb;
709 qDebug() << "EMC: u_s: sigma" << sigma;
710 }
711 
712 // Update data to reflect changes in float/fixed status
714 {
715 qDebug() << "EMC:UpFl: chng_floats" << chng_floats;
716  if ( ! chng_floats )
717  return;
718 
719  int scanx = selscan - 1;
720  int compx = (int)ct_grunpar->value() - 1;
721 
722  runfit.mw_fits [ compx ] = rb_mwfloat->isChecked();
723  runfit.vbar_fits[ compx ] = rb_vbfloat->isChecked();
724  runfit.eq_fits [ 0 ] = rb_l1float->isChecked();
725  runfit.eq_fits [ 1 ] = rb_l2float->isChecked();
726  runfit.eq_fits [ 2 ] = rb_l3float->isChecked();
727  runfit.eq_fits [ 3 ] = rb_l4float->isChecked();
728 
729  compx = (int)ct_lrunpar->value() - 1;
730  scanfits[ scanx ].baseln_fit = rb_blfloat->isChecked();
731  scanfits[ scanx ].amp_fits[ compx ] = rb_amfloat->isChecked();
732 }
733 
734 // Update global fit values
736 {
737  int compx = (int)ct_grunpar->value() - 1;
738  runfit.mw_vals [ compx ] = le_mwguess->text().toDouble();
739  runfit.mw_bnds [ compx ] = le_mwbound->text().toDouble();
740  runfit.vbar_vals[ compx ] = le_vbguess->text().toDouble();
741  runfit.vbar_bnds[ compx ] = le_vbbound->text().toDouble();
742  runfit.eq_vals [ 0 ] = le_l1guess->text().toDouble();
743  runfit.eq_bnds [ 0 ] = le_l1bound->text().toDouble();
744  runfit.eq_vals [ 1 ] = le_l2guess->text().toDouble();
745  runfit.eq_bnds [ 1 ] = le_l2bound->text().toDouble();
746  runfit.eq_vals [ 2 ] = le_l3guess->text().toDouble();
747  runfit.eq_bnds [ 2 ] = le_l3bound->text().toDouble();
748  runfit.eq_vals [ 3 ] = le_l4guess->text().toDouble();
749  runfit.eq_bnds [ 3 ] = le_l4bound->text().toDouble();
750 }
751 
752 // Update local fit values
754 {
755  int scanx = selscan - 1;
756  int compx = (int)ct_lrunpar->value() - 1;
757  int extix = min( compx, scanfits[ scanx ].extincts.size() - 1 );
758  scanfits[ scanx ].amp_vals[ compx ] = le_amguess->text().toDouble();
759  scanfits[ scanx ].amp_bnds[ compx ] = le_ambound->text().toDouble();
760  scanfits[ scanx ].baseline = le_blguess->text().toDouble();
761  scanfits[ scanx ].baseln_bnd = le_blbound->text().toDouble();
762  scanfits[ scanx ].extincts[ extix ] = le_extinct->text().toDouble();
763 }
764 
765 // Connect global value GUI components to update slot
767 {
768  connect( le_mwguess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
769  connect( le_mwbound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
770  connect( le_vbguess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
771  connect( le_vbbound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
772  connect( le_l1guess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
773  connect( le_l1bound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
774  connect( le_l2guess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
775  connect( le_l2bound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
776  connect( le_l3guess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
777  connect( le_l3bound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
778  connect( le_l4guess, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
779  connect( le_l4bound, SIGNAL( editingFinished() ), SLOT( update_gvals() ) );
780 }
781 
782 // Connect local value GUI components to update slot
784 {
785  connect( le_amguess, SIGNAL( editingFinished() ), SLOT( update_lvals() ) );
786  connect( le_ambound, SIGNAL( editingFinished() ), SLOT( update_lvals() ) );
787  connect( le_blguess, SIGNAL( editingFinished() ), SLOT( update_lvals() ) );
788  connect( le_blbound, SIGNAL( editingFinished() ), SLOT( update_lvals() ) );
789  connect( le_extinct, SIGNAL( editingFinished() ), SLOT( update_lvals() ) );
790 }
791 
792 // Disconnect global value GUI components
794 {
795  le_mwguess->disconnect();
796  le_mwbound->disconnect();
797  le_vbguess->disconnect();
798  le_vbbound->disconnect();
799  le_l1guess->disconnect();
800  le_l1bound->disconnect();
801  le_l2guess->disconnect();
802  le_l2bound->disconnect();
803  le_l3guess->disconnect();
804  le_l3bound->disconnect();
805  le_l4guess->disconnect();
806  le_l4bound->disconnect();
807 }
808 
809 // Disconnect local value GUI components
811 {
812  le_amguess->disconnect();
813  le_ambound->disconnect();
814  le_blguess->disconnect();
815  le_blbound->disconnect();
816  le_extinct->disconnect();
817 }
818 
819 // Apply pathlen to specified scan(s)
821 {
822  QString scans = le_plenscn->text().simplified();
823  int jj = scans.indexOf( "-" );
824  jj = ( jj < 0 ) ? scans.indexOf( " " ) : jj;
825  jj = ( jj < 0 ) ? scans.indexOf( "," ) : jj;
826  int iscan = scans.toInt();
827  int lscan = iscan;
828  double pathln = le_pathlen->text().toDouble();
829 
830  if ( jj > 0 )
831  {
832  iscan = scans.left( jj ).toInt();
833  lscan = scans.mid( jj + 1 ).toInt();
834  }
835 
836  for ( int ii = iscan - 1; ii < lscan; ii++ )
837  {
838  scanfits[ ii ].pathlen = pathln;
839  }
840 }
841 
842 // Apply density to specified scan(s)
844 {
845  QString scans = le_densscn->text().simplified();
846  int jj = scans.indexOf( "-" );
847  jj = ( jj < 0 ) ? scans.indexOf( " " ) : jj;
848  jj = ( jj < 0 ) ? scans.indexOf( "," ) : jj;
849  int iscan = scans.toInt();
850  int lscan = iscan;
851  double densty = le_density->text().toDouble();
852 
853  if ( jj > 0 )
854  {
855  iscan = scans.left( jj ).toInt();
856  lscan = scans.mid( jj + 1 ).toInt();
857  }
858 
859  for ( int ii = iscan - 1; ii < lscan; ii++ )
860  {
861  scanfits[ ii ].density = densty;
862  }
863 }
864 
865 // Apply extinction to specified scan(s)
867 {
868  QString scans = le_extiscn->text().simplified();
869  int jj = scans.indexOf( "-" );
870  jj = ( jj < 0 ) ? scans.indexOf( " " ) : jj;
871  jj = ( jj < 0 ) ? scans.indexOf( "," ) : jj;
872  int iscan = scans.toInt();
873  int lscan = iscan;
874  int compx = (int)ct_lrunpar->value() - 1;
875  double extval = le_extinct->text().toDouble();
876 
877  if ( jj > 0 )
878  {
879  iscan = scans.left( jj ).toInt();
880  lscan = scans.mid( jj + 1 ).toInt();
881  }
882 
883  for ( int ii = iscan - 1; ii < lscan; ii++ )
884  {
885  scanfits[ ii ].extincts[ compx ] = extval;
886  }
887 }
888 
889 // Create a button box for a pair of radio buttons
891  QGridLayout* lo_rb1, QRadioButton* rbtn1,
892  QGridLayout* lo_rb2, QRadioButton* rbtn2 )
893 {
894  // Create the box and add radiobutton layouts to it
895  QHBoxLayout* lo_radiobox = new QHBoxLayout;
896  lo_radiobox->setSpacing ( 0 );
897  lo_radiobox->setContentsMargins( 0, 0, 0, 0 );
898  lo_radiobox->addLayout( lo_rb1 );
899  lo_radiobox->addLayout( lo_rb2 );
900  // Create a button group, add buttons, and set exclusive
901  QButtonGroup* btn_grp = new QButtonGroup();
902  btn_grp->addButton( rbtn1 );
903  btn_grp->addButton( rbtn2 );
904  btn_grp->setExclusive( true );
905 
906  return lo_radiobox;
907 }
908 
909 // Set Vbar20 from an analyte dialog, after Vbar button is clicked
911 {
912  int dbdisk = runfit.dbdisk;
913  US_AnalyteGui* adiag = new US_AnalyteGui( true, QString(), dbdisk );
914  connect( adiag, SIGNAL( valueChanged( US_Analyte ) ),
915  this, SLOT ( assignVbar ( US_Analyte ) ) );
916  adiag->exec();
917  qApp->processEvents();
918 }
919 
920 // Set Density from a buffer dialog, after Density button is clicked
922 {
923  US_Buffer buff;
924  int dbdisk = runfit.dbdisk;
925  US_BufferGui* bdiag = new US_BufferGui( true, buff, dbdisk );
926  connect( bdiag, SIGNAL( valueChanged( US_Buffer ) ),
927  this, SLOT ( assignDensity( US_Buffer ) ) );
928  bdiag->exec();
929  qApp->processEvents();
930 }
931 
932 // Assign the Vbar from an analyte selected in US_AnalyteGui
934 {
935  int compx = (int)ct_lrunpar->value() - 1;
936  runfit.vbar_vals[ compx ] = analyte.vbar20;
937  le_vbguess->setText( QString::number( runfit.vbar_vals[ compx ] ) );
938 }
939 
940 // Assign the Density from a buffer selected in US_BufferGui
942 {
943  int scanx = selscan - 1;
944  scanfits[ scanx ].density = buffer.density;
945  le_density->setText( QString::number( scanfits[ scanx ].density ) );
946 }
947