UltraScan III
us_mwl_pltctrl.cpp
Go to the documentation of this file.
1 
3 #include "us_mwlr_viewer.h"
4 #include "us_mwl_pltctrl.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 ZSCAL_FACT
12 #define ZSCAL_FACT 0.008
13 #define RXSCL_FACT 0.032
14 #define RYSCL_FACT 0.900
15 #endif
16 
17 // constructor: enhanced plot control widget
18 US_MwlPlotControl::US_MwlPlotControl( QWidget* p, QVector< QVector3D >* d )
19  : US_WidgetsDialog( 0, 0 )
20 {
21 qDebug() << "PCtrl: IN";
22  wparent = p;
23  xyzdat = d;
24 qDebug() << "PCtrl: xyzdat count" << xyzdat->count();
25 
26  setObjectName( "US_MwlPlotControl" );
27  setAttribute( Qt::WA_DeleteOnClose, true );
28  setPalette( US_GuiSettings::frameColor() );
30 
31  // lay out the GUI
32  setWindowTitle( tr( "3-D Plotting Controls" ) );
33 
34  mainLayout = new QVBoxLayout( this );
35  controlsLayout = new QGridLayout( );
36  buttonsLayout = new QHBoxLayout( );
37 
38  mainLayout->setSpacing ( 2 );
39  mainLayout->setContentsMargins( 2, 2, 2, 2 );
40 
41  mainLayout->addLayout( controlsLayout );
42  mainLayout->addLayout( buttonsLayout );
43 
44  QLabel* lb_zscalefac = us_label( tr( "Z Scale Factor:" ) );
45  QLabel* lb_rxscale = us_label( tr( "Relative X Scale:" ) );
46  QLabel* lb_ryscale = us_label( tr( "Relative Y Scale:" ) );
47 
48  QPushButton* pb_plot3d = us_pushbutton( tr( "3D Plot" ) );
49  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
50  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
51 
52  QLayout* lo_yrevrs = us_checkbox( tr( "Reverse Y" ), ck_yrevrs,
53  false );
54 
55  ct_zscalefac = us_counter( 3, 0.01, 1000, 0.01 );
56  ct_rxscale = us_counter( 3, 0.01, 1000, 0.01 );
57  ct_ryscale = us_counter( 3, 0.01, 1000, 0.01 );
58 
59  int row = 0;
60  controlsLayout->addWidget( lb_zscalefac, row, 0, 1, 2 );
61  controlsLayout->addWidget( ct_zscalefac, row++, 2, 1, 2 );
62  controlsLayout->addWidget( lb_rxscale, row, 0, 1, 2 );
63  controlsLayout->addWidget( ct_rxscale, row++, 2, 1, 2 );
64  controlsLayout->addWidget( lb_ryscale, row, 0, 1, 2 );
65  controlsLayout->addWidget( ct_ryscale, row++, 2, 1, 2 );
66  controlsLayout->addLayout( lo_yrevrs, row++, 2, 1, 2 );
67 
68  buttonsLayout->addWidget( pb_plot3d );
69  buttonsLayout->addWidget( pb_help );
70  buttonsLayout->addWidget( pb_close );
71 
72  zscale = 1.0;
73  rxscale = 1.0;
74  ryscale = 1.0;
75  ct_zscalefac->setValue( zscale );
76  ct_rxscale ->setValue( rxscale );
77  ct_ryscale ->setValue( ryscale );
78  ct_zscalefac->setStep( 0.01 );
79  ct_rxscale ->setStep( 0.01 );
80  ct_ryscale ->setStep( 0.01 );
81 
82  connect( pb_plot3d, SIGNAL( clicked() ),
83  this, SLOT ( plot3_btn() ) );
84  connect( pb_help, SIGNAL( clicked() ),
85  this, SLOT ( help() ) );
86  connect( pb_close, SIGNAL( clicked() ),
87  this, SLOT ( close_all() ) );
88 
89  plot3d_w = 0;
90 
91  ct_zscalefac->setMinimumWidth( lb_zscalefac->width() );
92  adjustSize();
93 qDebug() << "PCtrl: w size" << size();
94 }
95 
96 // Return caller of plot_control
97 QWidget* US_MwlPlotControl::caller( void )
98 {
99  return wparent;
100 }
101 
102 // Public slot to force (re-)plot of currently specified 3-D plot
104 {
105  plot3_btn();
106 }
107 
108 // Public slot to return a pointer to the 3D plot data widget
110 {
111  QGLWidget* widgP = (QGLWidget*)0;
112  widgP = ( plot3d_w != 0 ) ? plot3d_w->dataWidgetP() : widgP;
113 
114  return widgP;
115 }
116 
117 // Public slot to return a pointer to the 3D plot main widget
119 {
120  return plot3d_w;
121 }
122 
123 // 3D Plot button clicked
125 {
126 qDebug() << "PCtrl: plot3_btn";
127  QString wtitle = tr( "Multiwavelength 3-Dimensional Viewer" );
128  QString ptitle = tr( "MWL 3-D Plot, Scan 1" );
129  QString xatitle = tr( "Radius(cm)" );
130  QString yatitle = tr( "Lambda(nm)" );
131  QString zatitle = tr( "Intensity" );
132  zscale = ct_zscalefac->value() * ZSCAL_FACT;
133  rxscale = ct_rxscale ->value() * RXSCL_FACT;
134  ryscale = ct_ryscale ->value() * RYSCL_FACT;
135  ryscale = ( ck_yrevrs->isChecked() ) ? -ryscale : ryscale;
136 qDebug() << "PCtrl: plot3_btn: scales" << rxscale << ryscale << zscale;
137  int nidpt = xyzdat->count();
138  QList< double > xvals;
139 
140  for ( int ii = 0; ii < nidpt; ii++ )
141  { // Accumulate unique X values so that we can count rows
142  double xval = xyzdat->at( ii ).x();
143  if ( ! xvals.contains( xval ) )
144  xvals << xval;
145  }
146 
147  int nrow = xvals.count(); // Row count is number of unique X's
148  int ncol = nidpt / nrow; // Column count is Total/Rows
149 
150  if ( plot3d_w == 0 )
151  { // If no 3-D plot window, bring it up now
152  plot3d_w = new US_Plot3Dxyz( this, xyzdat );
153  // Position so a corner is near a control dialog corner
154  int cx = x();
155  int cy = y();
156  int ncx = width();
157  int ncy = height();
158  int nhdx = qApp->desktop()->width() / 2;
159  int nhdy = qApp->desktop()->height() / 2;
160  int nwx = plot3d_w->width();
161  int nwy = plot3d_w->height();
162  int wx = ( cx < nhdx ) ? ( cx + ncx + 20 ) : ( cx - nwx - 20 );
163  int wy = ( cy < nhdy ) ? ( cy + ncy + 20 ) : ( cy - nwy - 20 );
164  plot3d_w->move( wx, wy );
165  }
166 
167  // Set plot window parameters; do initial plot; and make it visible
168  plot3d_w->setTitles ( wtitle, ptitle, xatitle, yatitle, zatitle );
169  plot3d_w->setParameters( ncol, nrow, rxscale, ryscale, zscale );
170  plot3d_w->replot ( );
171 
172  plot3d_w->setVisible( true );
173 }
174 
175 // Close button clicked
177 {
178  if ( plot3d_w != 0 ) // Close 3-D plot window if need be
179  plot3d_w->close();
180 
181  emit has_closed(); // Send a signal of the closing
182 
183  close(); // And go away
184 }
185