UltraScan III
us_plot_control_fem.cpp
Go to the documentation of this file.
1 
3 #include "us_fematch.h"
4 #include "us_plot_control_fem.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( 0, 0 )
14 {
15  wparent = p;
16  model = amodel;
17 
18  setObjectName( "US_PlotControlFem" );
19  setAttribute( Qt::WA_DeleteOnClose, true );
20  setPalette( US_GuiSettings::frameColor() );
22 
23  // lay out the GUI
24  setWindowTitle( tr( "3-D Plotting Controls" ) );
25 
26  mainLayout = new QVBoxLayout( this );
27  controlsLayout = new QGridLayout( );
28  buttonsLayout = new QHBoxLayout( );
29 
30  mainLayout->setSpacing ( 2 );
31  mainLayout->setContentsMargins( 2, 2, 2, 2 );
32 
33  mainLayout->addLayout( controlsLayout );
34  mainLayout->addLayout( buttonsLayout );
35 
36  QLabel* lb_dimens = us_label( tr( "Dimension:" ) );
37  QLabel* lb_molwt = us_label( tr( "Molecular Weight:" ) );
38  QLabel* lb_sedcoeff = us_label( tr( "Sedimentation Coefficient:" ) );
39  QLabel* lb_diffcoeff = us_label( tr( "Diffusion Coefficient:" ) );
40  QLabel* lb_friccoeff = us_label( tr( "Frictional Coefficient:" ) );
41  QLabel* lb_fricratio = us_label( tr( "Frictional Ratio:" ) );
42  QLabel* lb_vbar = us_label( tr( "Vbar at 20" ) + DEGC + ":" );
43  QLabel* lb_zscalefac = us_label( tr( "Z-Scaling Factor:" ) );
44  QLabel* lb_gridreso = us_label( tr( "Grid Resolution:" ) );
45  QLabel* lb_peaksmoo = us_label( tr( "Peak Smoothing:" ) );
46  QLabel* lb_peakwidth = us_label( tr( "Peak Width:" ) );
47  QLabel* lb_dimen1 = us_label( tr( "1 (x)" ) );
48  QLabel* lb_dimen2 = us_label( tr( "2 (y)" ) );
49  QLabel* lb_rxscale = us_label( tr( "Relative X Scale:" ) );
50  QLabel* lb_ryscale = us_label( tr( "Relative Y Scale:" ) );
51 
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 = 0;
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 = 130.0;
150  pkwidth = 0.3;
151  double xscl = 1.0;
152  double yscl = 1.0;
153  ct_zscalefac->setValue( zscale );
154  ct_gridreso ->setValue( gridres );
155  ct_peaksmoo ->setValue( pksmooth );
156  ct_peakwidth->setValue( pkwidth );
157  ct_rxscale ->setValue( xscl );
158  ct_ryscale ->setValue( yscl );
159  ct_zscalefac->setStep( 0.01 );
160  ct_gridreso ->setStep( 10 );
161  ct_peaksmoo ->setStep( 1 );
162  ct_peakwidth->setStep( 0.01 );
163  ct_rxscale ->setStep( 0.01 );
164  ct_ryscale ->setStep( 0.01 );
165 
166  connect( ck_xmwt, SIGNAL( toggled( bool ) ),
167  this, SLOT( xmwtCheck( bool ) ) );
168  connect( ck_ymwt, SIGNAL( toggled( bool ) ),
169  this, SLOT( ymwtCheck( bool ) ) );
170  connect( ck_xsed, SIGNAL( toggled( bool ) ),
171  this, SLOT( xsedCheck( bool ) ) );
172  connect( ck_ysed, SIGNAL( toggled( bool ) ),
173  this, SLOT( ysedCheck( bool ) ) );
174  connect( ck_xdif, SIGNAL( toggled( bool ) ),
175  this, SLOT( xdifCheck( bool ) ) );
176  connect( ck_ydif, SIGNAL( toggled( bool ) ),
177  this, SLOT( ydifCheck( bool ) ) );
178  connect( ck_xfco, SIGNAL( toggled( bool ) ),
179  this, SLOT( xfcoCheck( bool ) ) );
180  connect( ck_yfco, SIGNAL( toggled( bool ) ),
181  this, SLOT( yfcoCheck( bool ) ) );
182  connect( ck_xfra, SIGNAL( toggled( bool ) ),
183  this, SLOT( xfraCheck( bool ) ) );
184  connect( ck_yfra, SIGNAL( toggled( bool ) ),
185  this, SLOT( yfraCheck( bool ) ) );
186  connect( ck_xvba, SIGNAL( toggled( bool ) ),
187  this, SLOT( xvbaCheck( bool ) ) );
188  connect( ck_yvba, SIGNAL( toggled( bool ) ),
189  this, SLOT( yvbaCheck( bool ) ) );
190 
191  connect( ct_zscalefac, SIGNAL( valueChanged( double ) ),
192  this, SLOT( zscal_value( double ) ) );
193  connect( ct_gridreso , SIGNAL( valueChanged( double ) ),
194  this, SLOT( gridr_value( double ) ) );
195  connect( ct_peaksmoo , SIGNAL( valueChanged( double ) ),
196  this, SLOT( peaks_value( double ) ) );
197  connect( ct_peakwidth, SIGNAL( valueChanged( double ) ),
198  this, SLOT( peakw_value( double ) ) );
199 
200  connect( pb_plot3d, SIGNAL( clicked() ),
201  this, SLOT( plot3_btn() ) );
202  connect( pb_help, SIGNAL( clicked() ),
203  this, SLOT( help() ) );
204  connect( pb_close, SIGNAL( clicked() ),
205  this, SLOT( close_all() ) );
206 
207  plot3d_w = 0;
208 
209  lb_sedcoeff ->adjustSize();
210  ct_zscalefac->setMinimumWidth( lb_sedcoeff->width() );
211  adjustSize();
212  bool cnstff0 = model->constant_ff0();
213 
214  if ( cnstff0 )
215  { // f/f0 constant, so disable f/f0 check boxes
216  ck_xfra->setEnabled( false );
217  ck_yfra->setEnabled( false );
218  ck_xfra->setChecked( false );
219  ck_yfra->setChecked( false );
220  ck_yvba->setChecked( true );
221  }
222 
223  if ( model->constant_vbar() )
224  { // Vbar constant, so disable vbar X,Y check boxes
225  ck_xvba->setEnabled( false );
226  ck_yvba->setEnabled( false );
227  ck_xvba->setChecked( false );
228  ck_yvba->setChecked( false );
229  if ( cnstff0 )
230  ck_yfco->setChecked( true );
231  else
232  ck_yfra->setChecked( true );
233  }
234 }
235 
236 // return caller of plot_control
238 {
239  return wparent;
240 }
241 
242 // public slot to force (re-)plot of currently specified 3-D plot
244 {
245  plot3_btn();
246 }
247 
248 // Public slot to return a pointer to the 3D plot data widget
250 {
251  QGLWidget* widgP = (QGLWidget*)0;
252 
253  if ( plot3d_w != 0 )
254  {
255  //plot3_btn();
256  widgP = plot3d_w->dataWidgetP();
257  }
258 
259  return widgP;
260 }
261 
262 // Public slot to return a pointer to the 3D plot main widget
264 {
265  return (US_Plot3D*)plot3d_w;
266 }
267 
268 // mw x box checked
270 {
271  checkSet( chkd, true, 0 );
272 }
273 // mw y box checked
275 {
276  checkSet( chkd, false, 0 );
277 }
278 // sedcoeff x box checked
280 {
281  checkSet( chkd, true, 1 );
282 }
283 // sedcoeff y box checked
285 {
286  checkSet( chkd, false, 1 );
287 }
288 // diffcoeff x box checked
290 {
291  checkSet( chkd, true, 2 );
292 }
293 // diffcoeff y box checked
295 {
296  checkSet( chkd, false, 2 );
297 }
298 // friccoeff x box checked
300 {
301  checkSet( chkd, true, 3 );
302 }
303 // friccoeff y box checked
305 {
306  checkSet( chkd, false, 3 );
307 }
308 // fricratio x box checked
310 {
311  checkSet( chkd, true, 4 );
312 }
313 // fricratio y box checked
315 {
316  checkSet( chkd, false, 4 );
317 }
318 // Vbar x box checked
320 {
321  checkSet( chkd, true, 5 );
322 }
323 // Vbar y box checked
325 {
326  checkSet( chkd, false, 5 );
327 }
328 
329 // handle any x or y box checked
330 void US_PlotControlFem::checkSet( bool chkd, bool isX, int row )
331 {
332  if ( !chkd ) // only respond if checked
333  return;
334 
335  if ( isX )
336  { // this is a X box
337  for ( int ii = 0; ii < 6; ii++ )
338  { // review all check boxes
339  if ( ii != row )
340  { // in other rows, uncheck X, enable Y
341  xCheck[ ii ]->setChecked( false );
342  yCheck[ ii ]->setEnabled( true );
343  }
344 
345  else
346  { // in this row, disable the Y
347  yCheck[ ii ]->setEnabled( false );
348  }
349  }
350  }
351 
352  else
353  { // this is a Y box
354  for ( int ii = 0; ii < 6; ii++ )
355  { // review all check boxes
356  if ( ii != row )
357  { // in other rows, uncheck Y, enable X
358  yCheck[ ii ]->setChecked( false );
359  xCheck[ ii ]->setEnabled( true );
360  }
361 
362  else
363  { // in this row, disable the X
364  xCheck[ ii ]->setEnabled( false );
365  }
366  }
367  }
368 
369  if ( model->constant_ff0() )
370  { // f/f0 constant, so disable f/f0 check boxes
371  xCheck[ 4 ]->setEnabled( false );
372  yCheck[ 4 ]->setEnabled( false );
373  xCheck[ 4 ]->setChecked( false );
374  yCheck[ 4 ]->setChecked( false );
375  }
376 
377  if ( model->constant_vbar() )
378  { // Vbar constant, so disable vbar X,Y check boxes
379  xCheck[ 5 ]->setEnabled( false );
380  yCheck[ 5 ]->setEnabled( false );
381  xCheck[ 5 ]->setChecked( false );
382  yCheck[ 5 ]->setChecked( false );
383  }
384 }
385 
386 // z scale factor changed
387 void US_PlotControlFem::zscal_value( double value )
388 {
389  zscale = value;
390 }
391 // grid resolution changed
392 void US_PlotControlFem::gridr_value( double value )
393 {
394  gridres = value;
395 }
396 // peak smoothing changed
397 void US_PlotControlFem::peaks_value( double value )
398 {
399  pksmooth = value;
400 }
401 // peak width changed
402 void US_PlotControlFem::peakw_value( double value )
403 {
404  pkwidth = value;
405 }
406 
407 // 3d plot button clicked
409 {
410  int typex = dimensionType( xCheck );
411  int typey = dimensionType( yCheck );
412  int typez = 1;
413  double rxscl = ct_rxscale->value();
414  double ryscl = ct_ryscale->value();
415 //qDebug() << "PC: p3btn type x,y" << typex << typey;
416 
417  if ( plot3d_w == 0 )
418  {
419  plot3d_w = new US_Plot3D( this, model );
420  }
421 
422  plot3d_w->setTypes ( typex, typey, typez );
423  plot3d_w->setParameters( zscale, gridres, pksmooth, pkwidth, rxscl, ryscl );
424  plot3d_w->replot ( );
425 
426  plot3d_w->setVisible( true );
427 }
428 
429 // close button clicked
431 {
432  if ( plot3d_w != 0 )
433  plot3d_w->close();
434 
435  close();
436 }
437 
438 int US_PlotControlFem::dimensionType( QVector< QCheckBox* >& xycheck )
439 {
440  int dimType = 1;
441 
442  for ( int ii = 0; ii < xycheck.size(); ii++ )
443  {
444  if ( xycheck[ ii ]->isChecked() )
445  {
446  dimType = ii + 1;
447  break;
448  }
449  }
450 
451  return dimType;
452 }
453