UltraScan III
us_plot_control_pc.cpp
Go to the documentation of this file.
1 
3 #include "us_pcsa.h"
4 #include "us_plot_control_pc.h"
5 #include "us_settings.h"
6 #include "us_gui_settings.h"
7 #include "us_constants.h"
8 
9 #include <qwt_legend.h>
10 
11 // constructor: enhanced plot control widget
13  : US_WidgetsDialog( p, 0 )
14 {
15  model = amodel;
16 
17  setObjectName( "US_PlotControlPc" );
18  setAttribute( Qt::WA_DeleteOnClose, true );
19  setPalette( US_GuiSettings::frameColor() );
21 
22  // lay out the GUI
23  setWindowTitle( tr( "3-D Plotting Controls" ) );
24 
25  mainLayout = new QVBoxLayout( this );
26  controlsLayout = new QGridLayout( );
27  buttonsLayout = new QHBoxLayout( );
28 
29  mainLayout->setSpacing ( 2 );
30  mainLayout->setContentsMargins( 2, 2, 2, 2 );
31 
32  mainLayout->addLayout( controlsLayout );
33  mainLayout->addLayout( buttonsLayout );
34 
35  QLabel* lb_dimens = us_label( tr( "Dimension:" ) );
36  QLabel* lb_molwt = us_label( tr( "Molecular Weight:" ) );
37  QLabel* lb_sedcoeff = us_label( tr( "Sedimentation Coefficient:" ) );
38  QLabel* lb_diffcoeff = us_label( tr( "Diffusion Coefficient:" ) );
39  QLabel* lb_friccoeff = us_label( tr( "Frictional Coefficient:" ) );
40  QLabel* lb_fricratio = us_label( tr( "Frictional Ratio:" ) );
41  QLabel* lb_vbar = us_label( tr( "Vbar at 20" ) + DEGC + ":" );
42  QLabel* lb_zscalefac = us_label( tr( "Z-Scaling Factor:" ) );
43  QLabel* lb_gridreso = us_label( tr( "Grid Resolution:" ) );
44  QLabel* lb_peaksmoo = us_label( tr( "Peak Smoothing:" ) );
45  QLabel* lb_peakwidth = us_label( tr( "Peak Width:" ) );
46  QLabel* lb_dimen1 = us_label( tr( "1 (x)" ) );
47  QLabel* lb_dimen2 = us_label( tr( "2 (y)" ) );
48  QLabel* lb_rxscale = us_label( tr( "Relative X Scale:" ) );
49  QLabel* lb_ryscale = us_label( tr( "Relative Y Scale:" ) );
50 
51  //QPushButton* pb_rplot = us_pushbutton( tr( "Residuals Plot" ) );
52  QPushButton* pb_plot3d = us_pushbutton( tr( "3D Plot" ) );
53  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
54  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
55 
56  QCheckBox* ck_xmwt;
57  QCheckBox* ck_ymwt;
58  QCheckBox* ck_xsed;
59  QCheckBox* ck_ysed;
60  QCheckBox* ck_xdif;
61  QCheckBox* ck_ydif;
62  QCheckBox* ck_xfco;
63  QCheckBox* ck_yfco;
64  QCheckBox* ck_xfra;
65  QCheckBox* ck_yfra;
66  QCheckBox* ck_xvba;
67  QCheckBox* ck_yvba;
68 
69  QLayout* lo_xmwt = us_checkbox( tr( "x=mw" ), ck_xmwt, false );
70  QLayout* lo_ymwt = us_checkbox( tr( "y=mw" ), ck_ymwt, false );
71  QLayout* lo_xsed = us_checkbox( tr( "x=s" ), ck_xsed, true );
72  QLayout* lo_ysed = us_checkbox( tr( "y=s" ), ck_ysed, false );
73  QLayout* lo_xdif = us_checkbox( tr( "x=D" ), ck_xdif, false );
74  QLayout* lo_ydif = us_checkbox( tr( "y=D" ), ck_ydif, false );
75  QLayout* lo_xfco = us_checkbox( tr( "x=f" ), ck_xfco, false );
76  QLayout* lo_yfco = us_checkbox( tr( "y=f" ), ck_yfco, false );
77  QLayout* lo_xfra = us_checkbox( tr( "x=f/f0" ), ck_xfra, false );
78  QLayout* lo_yfra = us_checkbox( tr( "y=f/f0" ), ck_yfra, true );
79  QLayout* lo_xvba = us_checkbox( tr( "x=vb" ), ck_xvba, false );
80  QLayout* lo_yvba = us_checkbox( tr( "y=vb" ), ck_yvba, false );
81 
82  QwtCounter* ct_zscalefac = us_counter( 3, 0.1, 10, 0.01 );
83  QwtCounter* ct_gridreso = us_counter( 3, 50, 300, 10 );
84  QwtCounter* ct_peaksmoo = us_counter( 3, 1, 200, 1 );
85  QwtCounter* ct_peakwidth = us_counter( 3, 0.01, 10.0, 0.01 );
86  ct_rxscale = us_counter( 3, 0.1, 50, 0.01 );
87  ct_ryscale = us_counter( 3, 0.1, 50, 0.01 );
88 
89  int row = 1;
90  controlsLayout->addWidget( lb_dimens, row, 0, 1, 2 );
91  controlsLayout->addWidget( lb_dimen1, row, 2, 1, 1 );
92  controlsLayout->addWidget( lb_dimen2, row++, 3, 1, 1 );
93  controlsLayout->addWidget( lb_molwt, row, 0, 1, 2 );
94  controlsLayout->addLayout( lo_xmwt, row, 2, 1, 1 );
95  controlsLayout->addLayout( lo_ymwt, row++, 3, 1, 1 );
96  controlsLayout->addWidget( lb_sedcoeff, row, 0, 1, 2 );
97  controlsLayout->addLayout( lo_xsed, row, 2, 1, 1 );
98  controlsLayout->addLayout( lo_ysed, row++, 3, 1, 1 );
99  controlsLayout->addWidget( lb_diffcoeff, row, 0, 1, 2 );
100  controlsLayout->addLayout( lo_xdif, row, 2, 1, 1 );
101  controlsLayout->addLayout( lo_ydif, row++, 3, 1, 1 );
102  controlsLayout->addWidget( lb_friccoeff, row, 0, 1, 2 );
103  controlsLayout->addLayout( lo_xfco, row, 2, 1, 1 );
104  controlsLayout->addLayout( lo_yfco, row++, 3, 1, 1 );
105  controlsLayout->addWidget( lb_fricratio, row, 0, 1, 2 );
106  controlsLayout->addLayout( lo_xfra, row, 2, 1, 1 );
107  controlsLayout->addLayout( lo_yfra, row++, 3, 1, 1 );
108  controlsLayout->addWidget( lb_vbar, row, 0, 1, 2 );
109  controlsLayout->addLayout( lo_xvba, row, 2, 1, 1 );
110  controlsLayout->addLayout( lo_yvba, row++, 3, 1, 1 );
111  controlsLayout->addWidget( lb_zscalefac, row, 0, 1, 2 );
112  controlsLayout->addWidget( ct_zscalefac, row++, 2, 1, 2 );
113  controlsLayout->addWidget( lb_gridreso, row, 0, 1, 2 );
114  controlsLayout->addWidget( ct_gridreso, row++, 2, 1, 2 );
115  controlsLayout->addWidget( lb_peaksmoo, row, 0, 1, 2 );
116  controlsLayout->addWidget( ct_peaksmoo, row++, 2, 1, 2 );
117  controlsLayout->addWidget( lb_peakwidth, row, 0, 1, 2 );
118  controlsLayout->addWidget( ct_peakwidth, row++, 2, 1, 2 );
119  controlsLayout->addWidget( lb_rxscale, row, 0, 1, 2 );
120  controlsLayout->addWidget( ct_rxscale, row++, 2, 1, 2 );
121  controlsLayout->addWidget( lb_ryscale, row, 0, 1, 2 );
122  controlsLayout->addWidget( ct_ryscale, row++, 2, 1, 2 );
123 
124  buttonsLayout->addWidget( pb_plot3d );
125  buttonsLayout->addWidget( pb_help );
126  buttonsLayout->addWidget( pb_close );
127 
128  ck_ysed->setEnabled( false );
129  ck_xfra->setEnabled( false );
130 
131  // set up so check boxes are like 2-d radio buttons
132  xCheck.resize( 6 );
133  xCheck[ 0 ] = ck_xmwt;
134  xCheck[ 1 ] = ck_xsed;
135  xCheck[ 2 ] = ck_xdif;
136  xCheck[ 3 ] = ck_xfco;
137  xCheck[ 4 ] = ck_xfra;
138  xCheck[ 5 ] = ck_xvba;
139  yCheck.resize( 6 );
140  yCheck[ 0 ] = ck_ymwt;
141  yCheck[ 1 ] = ck_ysed;
142  yCheck[ 2 ] = ck_ydif;
143  yCheck[ 3 ] = ck_yfco;
144  yCheck[ 4 ] = ck_yfra;
145  yCheck[ 5 ] = ck_yvba;
146 
147  zscale = 1.0;
148  gridres = 150.0;
149  pksmooth = 80.0;
150  pkwidth = 0.1;
151  ct_zscalefac->setValue( zscale );
152  ct_gridreso ->setValue( gridres );
153  ct_peaksmoo ->setValue( pksmooth );
154  ct_peakwidth->setValue( pkwidth );
155  ct_rxscale ->setValue( 1.0 );
156  ct_ryscale ->setValue( 1.0 );
157  ct_zscalefac->setStep ( 0.01 );
158  ct_gridreso ->setStep ( 10 );
159  ct_peaksmoo ->setStep ( 1 );
160  ct_peakwidth->setStep ( 0.01 );
161  ct_rxscale ->setStep ( 0.01 );
162  ct_ryscale ->setStep ( 0.01 );
163 
164  connect( ck_xmwt, SIGNAL( toggled( bool ) ),
165  this, SLOT( xmwtCheck( bool ) ) );
166  connect( ck_ymwt, SIGNAL( toggled( bool ) ),
167  this, SLOT( ymwtCheck( bool ) ) );
168  connect( ck_xsed, SIGNAL( toggled( bool ) ),
169  this, SLOT( xsedCheck( bool ) ) );
170  connect( ck_ysed, SIGNAL( toggled( bool ) ),
171  this, SLOT( ysedCheck( bool ) ) );
172  connect( ck_xdif, SIGNAL( toggled( bool ) ),
173  this, SLOT( xdifCheck( bool ) ) );
174  connect( ck_ydif, SIGNAL( toggled( bool ) ),
175  this, SLOT( ydifCheck( bool ) ) );
176  connect( ck_xfco, SIGNAL( toggled( bool ) ),
177  this, SLOT( xfcoCheck( bool ) ) );
178  connect( ck_yfco, SIGNAL( toggled( bool ) ),
179  this, SLOT( yfcoCheck( bool ) ) );
180  connect( ck_xfra, SIGNAL( toggled( bool ) ),
181  this, SLOT( xfraCheck( bool ) ) );
182  connect( ck_yfra, SIGNAL( toggled( bool ) ),
183  this, SLOT( yfraCheck( bool ) ) );
184  connect( ck_xvba, SIGNAL( toggled( bool ) ),
185  this, SLOT( xvbaCheck( bool ) ) );
186  connect( ck_yvba, SIGNAL( toggled( bool ) ),
187  this, SLOT( yvbaCheck( bool ) ) );
188 
189  connect( ct_zscalefac, SIGNAL( valueChanged( double ) ),
190  this, SLOT( zscal_value( double ) ) );
191  connect( ct_gridreso , SIGNAL( valueChanged( double ) ),
192  this, SLOT( gridr_value( double ) ) );
193  connect( ct_peaksmoo , SIGNAL( valueChanged( double ) ),
194  this, SLOT( peaks_value( double ) ) );
195  connect( ct_peakwidth, SIGNAL( valueChanged( double ) ),
196  this, SLOT( peakw_value( double ) ) );
197 
198  connect( pb_plot3d, SIGNAL( clicked() ),
199  this, SLOT( plot3_btn() ) );
200  connect( pb_help, SIGNAL( clicked() ),
201  this, SLOT( help() ) );
202  connect( pb_close, SIGNAL( clicked() ),
203  this, SLOT( close_all() ) );
204 
205  plot3d_w = 0;
206 
207  lb_sedcoeff ->adjustSize();
208  ct_zscalefac->setMinimumWidth( lb_sedcoeff->width() );
209  adjustSize();
210 
211  bool cnstff0 = model->constant_ff0();
212 
213  if ( cnstff0 )
214  { // f/f0 constant, so disable f/f0 X,Y check boxes
215  ck_xfra->setEnabled( false );
216  ck_yfra->setEnabled( false );
217  ck_xfra->setChecked( false );
218  ck_yfra->setChecked( false );
219  ck_yvba->setChecked( true );
220  }
221  if ( model->constant_vbar() )
222  { // Vbar constant, so disable vbar X,Y check boxes
223  ck_xvba->setEnabled( false );
224  ck_yvba->setEnabled( false );
225  ck_xvba->setChecked( false );
226  ck_yvba->setChecked( false );
227  if ( cnstff0 )
228  ck_yfco->setChecked( true );
229  else
230  ck_yfra->setChecked( true );
231  }
232 
233 qDebug() << "PlCtl: cnst_vbar" << model->constant_vbar();
234 qDebug() << "PlCtl: cnst_ff0 " << model->constant_ff0 ();
235 qDebug() << "PlCtl: ck_yfra " << ck_yfra->text();
236 qDebug() << "PlCtl: ncomps " << model->components.size();
237 }
238 
239 // mw x box checked
241 {
242  checkSet( chkd, true, 0 );
243 }
244 // mw y box checked
246 {
247  checkSet( chkd, false, 0 );
248 }
249 // sedcoeff x box checked
251 {
252  checkSet( chkd, true, 1 );
253 }
254 // sedcoeff y box checked
256 {
257  checkSet( chkd, false, 1 );
258 }
259 // diffcoeff x box checked
261 {
262  checkSet( chkd, true, 2 );
263 }
264 // diffcoeff y box checked
266 {
267  checkSet( chkd, false, 2 );
268 }
269 // friccoeff x box checked
271 {
272  checkSet( chkd, true, 3 );
273 }
274 // friccoeff y box checked
276 {
277  checkSet( chkd, false, 3 );
278 }
279 // fricratio x box checked
281 {
282  checkSet( chkd, true, 4 );
283 }
284 // fricratio y box checked
286 {
287  checkSet( chkd, false, 4 );
288 }
289 // Vbar x box checked
291 {
292  checkSet( chkd, true, 5 );
293 }
294 // Vbar y box checked
296 {
297  checkSet( chkd, false, 5 );
298 }
299 
300 // handle any x or y box checked
301 void US_PlotControlPc::checkSet( bool chkd, bool isX, int row )
302 {
303  if ( !chkd ) // only respond if checked
304  return;
305 
306  if ( isX )
307  { // this is a X box
308  for ( int ii = 0; ii < 6; ii++ )
309  { // review all check boxes
310  if ( ii != row )
311  { // in other rows, uncheck X, enable Y
312  xCheck[ ii ]->setChecked( false );
313  yCheck[ ii ]->setEnabled( true );
314  }
315 
316  else
317  { // in this row, disable the Y
318  yCheck[ ii ]->setEnabled( false );
319  }
320  }
321  }
322 
323  else
324  { // this is a Y box
325  for ( int ii = 0; ii < 6; ii++ )
326  { // review all check boxes
327  if ( ii != row )
328  { // in other rows, uncheck Y, enable X
329  yCheck[ ii ]->setChecked( false );
330  xCheck[ ii ]->setEnabled( true );
331  }
332 
333  else
334  { // in this row, disable the X
335  xCheck[ ii ]->setEnabled( false );
336  }
337  }
338  }
339  if ( model->constant_ff0() )
340  { // f/f0 constant, so disable f/f0 X,Y check boxes
341  xCheck[ 4 ]->setEnabled( false );
342  yCheck[ 4 ]->setEnabled( false );
343  xCheck[ 4 ]->setChecked( false );
344  yCheck[ 4 ]->setChecked( false );
345  }
346  if ( model->constant_vbar() )
347  { // Vbar constant, so disable vbar X,Y check boxes
348  xCheck[ 5 ]->setEnabled( false );
349  yCheck[ 5 ]->setEnabled( false );
350  xCheck[ 5 ]->setChecked( false );
351  yCheck[ 5 ]->setChecked( false );
352  }
353 }
354 
355 // z scale factor changed
356 void US_PlotControlPc::zscal_value( double value )
357 {
358  zscale = value;
359 }
360 // grid resolution changed
361 void US_PlotControlPc::gridr_value( double value )
362 {
363  gridres = value;
364 }
365 // peak smoothing changed
366 void US_PlotControlPc::peaks_value( double value )
367 {
368  pksmooth = value;
369 }
370 // peak width changed
371 void US_PlotControlPc::peakw_value( double value )
372 {
373  pkwidth = value;
374 }
375 
376 // 3d plot button clicked
378 {
379  int typex = dimensionType( xCheck );
380  int typey = dimensionType( yCheck );
381  int typez = 1;
382  double rxscl = ct_rxscale->value();
383  double ryscl = ct_ryscale->value();
384 
385  if ( plot3d_w == 0 )
386  {
387  if ( model == 0 || model->components.size() < 1 )
388  return;
389 
390  plot3d_w = new US_Plot3D( this, model );
391  }
392 
393  plot3d_w->setTypes ( typex, typey, typez );
394  plot3d_w->setParameters( zscale, gridres, pksmooth, pkwidth, rxscl, ryscl );
395  plot3d_w->replot ( );
396 
397  plot3d_w->setVisible( true );
398 }
399 
400 // close button clicked
402 {
403  close();
404 }
405 
406 int US_PlotControlPc::dimensionType( QVector< QCheckBox* >& xycheck )
407 {
408  int dimType = 1;
409 
410  for ( int ii = 0; ii < xycheck.size(); ii++ )
411  {
412  if ( xycheck[ ii ]->isChecked() )
413  {
414  dimType = ii + 1;
415  break;
416  }
417  }
418 
419  return dimType;
420 }
421