UltraScan III
us_vhwc_pltctl.cpp
Go to the documentation of this file.
1 
3 #include "us_vhw_combine.h"
4 #include "us_vhwc_pltctl.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 #ifndef ZSCLF_CE // Plot scale adjusts: Contour/Points Envel/Integ
12 #define ZSCLF_CE 0.07
13 #define XSCLF_CE 0.13
14 #define YSCLF_CE 0.70
15 #define ZSCLF_CI 0.50
16 #define XSCLF_CI 0.16
17 #define YSCLF_CI 0.80
18 #define ZSCLF_PE 0.10
19 #define XSCLF_PE 0.12
20 #define YSCLF_PE 1.00
21 #define ZSCLF_PI 0.45
22 #define XSCLF_PI 0.16
23 #define YSCLF_PI 1.00
24 #endif
25 
26 // Constructor: enhanced spectra plot control widget
27 US_VhwCPlotControl::US_VhwCPlotControl( QWidget* p, QVector< QVector3D >* d,
28  int a_ptype )
29  : US_WidgetsDialog( 0, 0 )
30 {
31 qDebug() << "PCtrl: IN";
32  wparent = p;
33  xyzdat = d;
34  p_type = a_ptype;
35  envel = ( p_type == 0 );
36 qDebug() << "PCtrl: xyzdat count" << xyzdat->count();
37 
38  setObjectName( "US_VhwCPlotControl" );
39  setAttribute( Qt::WA_DeleteOnClose, true );
40  setPalette( US_GuiSettings::frameColor() );
42 
43  // Lay out the GUI
44  setWindowTitle( tr( "3-D Plotting Controls" ) );
45 
46  mainLayout = new QVBoxLayout( this );
47  controlsLayout = new QGridLayout( );
48  buttonsLayout = new QHBoxLayout( );
49 
50  mainLayout->setSpacing ( 2 );
51  mainLayout->setContentsMargins( 2, 2, 2, 2 );
52 
53  mainLayout->addLayout( controlsLayout );
54  mainLayout->addLayout( buttonsLayout );
55 
56  QLabel* lb_zscalefac = us_label( tr( "Z Scale Factor:" ) );
57  QLabel* lb_rxscale = us_label( tr( "Relative X Scale:" ) );
58  QLabel* lb_ryscale = us_label( tr( "Relative Y Scale:" ) );
59  QLabel* lb_peaksmoo = us_label( tr( "Peak Smoothing" ) );
60  QLabel* lb_peakwid = us_label( tr( "Peak Width:" ) );
61  QLabel* lb_gridres = us_label( tr( "Grid Resolution:" ) );
62 
63  QPushButton* pb_plot3d = us_pushbutton( tr( "3D Plot" ) );
64  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
65  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
66 
67  QLayout* lo_yrevrs = us_checkbox( tr( "Reverse Y" ), ck_yrevrs,
68  false );
69  QLayout* lo_contour = us_checkbox( tr( "Contour Plot" ), ck_contour,
70  true );
71 
72  ct_peaksmoo = us_counter( 3, 1, 200, 1 );
73  ct_peakwid = us_counter( 3, 0.01, 10.0, 0.01 );
74  ct_gridres = us_counter( 3, 50, 600, 10 );
75  ct_zscalefac = us_counter( 3, 0.01, 1000, 0.01 );
76  ct_rxscale = us_counter( 3, 0.01, 1000, 0.01 );
77  ct_ryscale = us_counter( 3, 0.01, 1000, 0.01 );
78 
79  int row = 0;
80  controlsLayout->addWidget( lb_zscalefac, row, 0, 1, 2 );
81  controlsLayout->addWidget( ct_zscalefac, row++, 2, 1, 2 );
82  controlsLayout->addWidget( lb_rxscale, row, 0, 1, 2 );
83  controlsLayout->addWidget( ct_rxscale, row++, 2, 1, 2 );
84  controlsLayout->addWidget( lb_ryscale, row, 0, 1, 2 );
85  controlsLayout->addWidget( ct_ryscale, row++, 2, 1, 2 );
86  controlsLayout->addWidget( lb_peaksmoo, row, 0, 1, 2 );
87  controlsLayout->addWidget( ct_peaksmoo, row++, 2, 1, 2 );
88  controlsLayout->addWidget( lb_peakwid, row, 0, 1, 2 );
89  controlsLayout->addWidget( ct_peakwid, row++, 2, 1, 2 );
90  controlsLayout->addWidget( lb_gridres, row, 0, 1, 2 );
91  controlsLayout->addWidget( ct_gridres, row++, 2, 1, 2 );
92  controlsLayout->addLayout( lo_contour, row, 0, 1, 2 );
93  controlsLayout->addLayout( lo_yrevrs, row++, 2, 1, 2 );
94 
95  buttonsLayout->addWidget( pb_plot3d );
96  buttonsLayout->addWidget( pb_help );
97  buttonsLayout->addWidget( pb_close );
98 
99  zscale = 1.0;
100  rxscale = 1.0;
101  ryscale = 1.0;
102  pksmooth = 80.0;
103  pkwidth = 0.1;
104  gridres = 150;
105  ct_zscalefac->setValue( zscale );
106  ct_rxscale ->setValue( rxscale );
107  ct_ryscale ->setValue( ryscale );
108  ct_peaksmoo ->setValue( pksmooth );
109  ct_peakwid ->setValue( pkwidth );
110  ct_gridres ->setValue( gridres );
111  ct_zscalefac->setStep( 0.01 );
112  ct_rxscale ->setStep( 0.01 );
113  ct_ryscale ->setStep( 0.01 );
114  ct_peaksmoo ->setStep( 1 );
115  ct_peakwid ->setStep( 0.01 );
116  ct_gridres ->setStep( 10 );
117  ct_peaksmoo ->setEnabled( !ck_contour->isChecked() );
118  ct_peakwid ->setEnabled( !ck_contour->isChecked() );
119  ct_gridres ->setEnabled( !ck_contour->isChecked() );
120 
121  connect( pb_plot3d, SIGNAL( clicked() ),
122  this, SLOT ( plot3_btn() ) );
123  connect( ck_contour, SIGNAL( toggled ( bool ) ),
124  this, SLOT ( ptype_toggle( bool ) ) );
125  connect( pb_help, SIGNAL( clicked() ),
126  this, SLOT ( help() ) );
127  connect( pb_close, SIGNAL( clicked() ),
128  this, SLOT ( close_all() ) );
129 
130  plot3d_w = 0;
131 
132  ct_zscalefac->setMinimumWidth( lb_zscalefac->width() );
133  adjustSize();
134 qDebug() << "PCtrl: w size" << size();
135 }
136 
137 // Make changes based on plot type (contour/point) toggled
139 {
140  ct_peaksmoo ->setEnabled( !chkd );
141  ct_peakwid ->setEnabled( !chkd );
142  ct_gridres ->setEnabled( !chkd );
143 }
144 
145 // Return caller of plot_control
147 {
148  return wparent;
149 }
150 
151 // Public slot to force (re-)plot of currently specified 3-D plot
153 {
154  plot3_btn();
155 }
156 
157 // Public slot to return a pointer to the 3D plot data widget
159 {
160  QGLWidget* widgP = (QGLWidget*)0;
161  widgP = ( plot3d_w != 0 ) ? plot3d_w->dataWidgetP() : widgP;
162 
163  return widgP;
164 }
165 
166 // Public slot to return a pointer to the 3D plot main widget
168 {
169  return plot3d_w;
170 }
171 
172 // 3D Plot button clicked
174 {
175 qDebug() << "PCtrl: plot3_btn";
176  QString wtitle = tr( "Multiwavelength 3-D vHW Viewer" );
177  QString ptitle = tr( "MWL 3-D Plot, vHW Distributions" );
178  QString xatitle = tr( "Sed.C.(*e+13)" );
179  QString yatitle = tr( "Lambda(nm)" );
180  QString zatitle = envel ? tr( "Concen." ) :
181  ( ( p_type == 1 ) ? tr( "B.Frac." ) :
182  tr( "BF*Conc." ) );
183  zscale = ct_zscalefac->value();
184  rxscale = ct_rxscale ->value();
185  ryscale = ct_ryscale ->value();
186  ryscale = ( ck_yrevrs->isChecked() ) ? -ryscale : ryscale;
187 qDebug() << "PCtrl: plot3_btn: scales" << rxscale << ryscale << zscale;
188  bool contour = ck_contour->isChecked();
189  pksmooth = contour ? 0.0 : ct_peaksmoo ->value();
190  pkwidth = contour ? 0.0 : ct_peakwid ->value();
191 qDebug() << "PCtrl: plot3_btn: smoo.." << pksmooth << pkwidth << gridres;
192 
193  int nidpt = xyzdat->count();
194 qDebug() << "PCtrl: plot3_btn: nidpt" << nidpt;
195  QList< double > yvals;
196 
197  for ( int ii = 0; ii < nidpt; ii++ )
198  { // Accumulate unique Y values so that we can count columns
199  double yval = xyzdat->at( ii ).y();
200  if ( ! yvals.contains( yval ) )
201  yvals << yval;
202  }
203 
204  int ncol = yvals.count(); // Column count is number of unique Y's
205  int nrow = nidpt / ncol; // Row count is Total/Columns
206  gridres = contour ? (int)ct_gridres->value() : nrow;
207 qDebug() << "PCtrl: ncol nrow" << ncol << nrow << "gridres" << gridres;
208  ncol = contour ? ncol : gridres;
209  nrow = contour ? nrow : gridres;
210 
211  if ( plot3d_w == 0 )
212  { // If no 3-D plot window, bring it up now
213  plot3d_w = new US_Plot3Dxyz( this, xyzdat );
214  // Position so a corner is near a control dialog corner
215  int cx = x();
216  int cy = y();
217  int ncx = width();
218  int ncy = height();
219  int nhdx = qApp->desktop()->width() / 2;
220  int nhdy = qApp->desktop()->height() / 2;
221  int nwx = plot3d_w->width();
222  int nwy = plot3d_w->height();
223  int wx = ( cx < nhdx ) ? ( cx + ncx + 20 ) : ( cx - nwx - 20 );
224  int wy = ( cy < nhdy ) ? ( cy + ncy + 20 ) : ( cy - nwy - 20 );
225  plot3d_w->move( wx, wy );
226  }
227 
228  // Set plot window parameters; do initial plot; and make it visible
229  if ( contour )
230  { // Contour plot scale adjustments Envel/Integ
231  zscale *= ( envel ? ZSCLF_CE : ZSCLF_CI );
232  rxscale *= ( envel ? XSCLF_CE : XSCLF_CI );
233  ryscale *= ( envel ? YSCLF_CE : YSCLF_CI );
234  }
235  else
236  { // Points plot scale adjustments Envel/Integ
237  zscale *= ( envel ? ZSCLF_PE : ZSCLF_PI );
238  rxscale *= ( envel ? XSCLF_PE : XSCLF_PI );
239  ryscale *= ( envel ? YSCLF_PE : YSCLF_PI );
240  }
241 
242  plot3d_w->setTitles ( wtitle, ptitle, xatitle, yatitle, zatitle );
243  plot3d_w->setParameters( ncol, nrow, rxscale, ryscale, zscale,
244  pksmooth, pkwidth );
245  plot3d_w->replot ( );
246 
247  plot3d_w->setVisible( true );
248 }
249 
250 // Close button clicked
252 {
253  if ( plot3d_w != 0 ) // Close 3-D plot window if need be
254  plot3d_w->close();
255 
256  emit has_closed(); // Send a signal of the closing
257 
258  close(); // And go away
259 }
260