UltraScan III
us_intensity_ra.cpp
Go to the documentation of this file.
1 
3 #include "us_intensity_ra.h"
4 #include "us_settings.h"
5 #include "us_gui_settings.h"
6 #include "us_util.h"
7 #include "us_gui_util.h"
8 
10  const QString runID,
11  const QString triple,
12  const QVector< double >& data,
13  const QVector< double >& scan )
14  : US_WidgetsDialog( 0, 0 ), dataIn( data ), scanIn( scan )
15 {
16  setWindowTitle( tr( "Details for Average Intensity Values" ) );
17  setPalette( US_GuiSettings::frameColor() );
18  setAttribute( Qt::WA_DeleteOnClose );
19 
20  QGridLayout* main = new QGridLayout( this );
21  main->setSpacing ( 2 );
22  main->setContentsMargins( 2, 2, 2, 2 );
23 
24  int row = 0;
25 
26  // Plot Rows
27  QBoxLayout* plot = new US_Plot( data_plot,
28  tr( "Intensity Profile" ),
29  tr( "Scan Number" ),
30  tr( "Intensity" ));
31 
32  data_plot->setMinimumSize( 800, 200 );
33 
34  QwtPlotGrid* grid = us_grid( data_plot );
35  grid->enableXMin( false );
36 
37  main->addLayout( plot, row, 0, 5, 6 );
38  row += 6;
39 
40  QHBoxLayout* buttons = new QHBoxLayout();
41 
42  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
43  pb_close->setFixedWidth( 100 );
44  connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
45  buttons->insertStretch( 0, 10 );
46  buttons->addWidget( pb_close );
47 
48  main->addLayout( buttons, row++, 2, 1, 4 );
49  QString ctriple = US_Util::compressed_triple( triple );
50 
51  if ( triple.contains( "-" ) )
52  { // Handle special MWL triple with wavelength range
53  data_plot->setTitle( tr( "Intensity Profile\n"
54  "for wavelengths: " )
55  + ctriple.mid( 2 ) );
56  data_plot->setAxisTitle( QwtPlot::xBottom,
57  tr( "Wavelength.Scan Number" ) );
58  }
59 
61 
62  // Just automatically save the plot in a file
63  QString dir = US_Settings::reportDir() + "/" + runID;
64  if ( ! QDir( dir ).exists() ) // make sure the directory exists
65  QDir().mkdir( dir );
66 
67  QString filename = dir + "/cnvt." + ctriple + ".intensity.svgz";
68 
69  int status = US_GuiUtil::save_plot( filename, data_plot );
70  if ( status != 0 )
71  qDebug() << filename << "plot not saved";
72 
73 }
74 
75 void US_IntensityRa::draw_plot( const QVector< double >& scanData,
76  const QVector< double >& scanNbrs )
77 {
78  // Set up the axes and titles
79  QwtText axisTitle = data_plot->axisTitle( QwtPlot::yLeft );
80 
81  int szdata = scanData.size();
82  double xmin = qFloor( scanNbrs[ 0 ] );
83  double xmax = qFloor( scanNbrs[ szdata - 1 ] ) + 1.0;
84  data_plot->setAxisAutoScale( QwtPlot::yLeft );
85  data_plot->setAxisScale ( QwtPlot::xBottom, xmin, xmax );
86  data_plot->setAxisMaxMinor ( QwtPlot::xBottom, 0 );
87  data_plot->setAxisTitle ( QwtPlot::yLeft, "Intensity" );
88 
89  QwtSymbol sym;
90 
91  sym.setStyle( QwtSymbol::Ellipse );
92  sym.setPen ( QPen( Qt::yellow ) );
93  sym.setBrush( Qt::white );
94  sym.setSize ( 6 );
95 
96  // Get the scan data in the right format
97  QVector< double > xvec( szdata );
98  QVector< double > yvec( szdata );
99  double* xx = xvec.data();
100  double* yy = yvec.data();
101 
102  for ( int ii = 0; ii < szdata; ii++ )
103  {
104  xx[ ii ] = scanNbrs[ ii ];
105  yy[ ii ] = scanData[ ii ];
106  }
107 qDebug() << "Ints:dr_pl: xx0 xxn" << xx[0] << xx[scanData.size()-1];
108 
109  QwtPlotCurve* c1 = us_curve( data_plot, tr( "Intensity" ) );
110  c1->setPen ( QPen( QBrush( Qt::yellow ), 2 ) );
111  c1->setSymbol( sym );
112  c1->setData ( xx, yy, szdata );
113 
114  data_plot->replot();
115 }
116