scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

FFTDialog.cpp
Go to the documentation of this file.
1 
11 
29 #include "FFTDialog.h"
30 #include "Graph.h"
31 #include "MyParser.h"
32 #include "ApplicationWindow.h"
33 #include "MultiLayer.h"
34 #include "Table.h"
35 #include "Plot.h"
36 #include "FFT.h"
37 
38 #include <QRadioButton>
39 #include <QGroupBox>
40 #include <QCheckBox>
41 #include <QMessageBox>
42 #include <QPushButton>
43 #include <QLabel>
44 #include <QLineEdit>
45 #include <QComboBox>
46 #include <QLayout>
47 
48 #include <memory>
49 using namespace std;
50 
51 FFTDialog::FFTDialog(int type, QWidget* parent, Qt::WindowFlags fl )
52 : QDialog( parent, fl )
53 {
54  setWindowTitle(tr("FFT Options"));
55 
56  d_table = 0;
57  graph = 0;
58  d_type = type;
59 
60  forwardBtn = new QRadioButton(tr("&Forward"));
61  forwardBtn->setChecked( true );
62  backwardBtn = new QRadioButton(tr("&Inverse"));
63 
64  QHBoxLayout *hbox1 = new QHBoxLayout();
65  hbox1->addWidget(forwardBtn);
66  hbox1->addWidget(backwardBtn);
67 
68  QGroupBox *gb1 = new QGroupBox();
69  gb1->setLayout(hbox1);
70 
71  QGridLayout *gl1 = new QGridLayout();
72  if (d_type == onGraph)
73  gl1->addWidget(new QLabel(tr("Curve")), 0, 0);
74  else
75  gl1->addWidget(new QLabel(tr("Sampling")), 0, 0);
76 
77  boxName = new QComboBox();
78  gl1->addWidget(boxName, 0, 1);
79 
80  boxSampling = new QLineEdit();
81  if (d_type == onTable)
82  {
83  gl1->addWidget(new QLabel(tr("Real")), 1, 0);
84  boxReal = new QComboBox();
85  gl1->addWidget(boxReal, 1, 1);
86 
87  gl1->addWidget(new QLabel(tr("Imaginary")), 2, 0);
88  boxImaginary = new QComboBox();
89  gl1->addWidget(boxImaginary, 2, 1);
90 
91  gl1->addWidget(new QLabel(tr("Sampling Interval")), 3, 0);
92  gl1->addWidget(boxSampling, 3, 1);
93  }
94  else
95  {
96  gl1->addWidget(new QLabel(tr("Sampling Interval")), 1, 0);
97  gl1->addWidget(boxSampling, 1, 1);
98  }
99  QGroupBox *gb2 = new QGroupBox();
100  gb2->setLayout(gl1);
101 
102  boxNormalize = new QCheckBox(tr( "&Normalize Amplitude" ));
103  boxNormalize->setChecked(true);
104 
105  boxOrder = new QCheckBox(tr( "&Shift Results" ));
106  boxOrder->setChecked(true);
107 
108  QVBoxLayout *vbox1 = new QVBoxLayout();
109  vbox1->addWidget(gb1);
110  vbox1->addWidget(gb2);
111  vbox1->addWidget(boxNormalize);
112  vbox1->addWidget(boxOrder);
113  vbox1->addStretch();
114 
115  buttonOK = new QPushButton(tr("&OK"));
116  buttonOK->setDefault( true );
117  buttonCancel = new QPushButton(tr("&Close"));
118 
119  QVBoxLayout *vbox2 = new QVBoxLayout();
120  vbox2->addWidget(buttonOK);
121  vbox2->addWidget(buttonCancel);
122  vbox2->addStretch();
123 
124  QHBoxLayout *hbox2 = new QHBoxLayout(this);
125  hbox2->addLayout(vbox1);
126  hbox2->addLayout(vbox2);
127 
128  setFocusProxy(boxName);
129 
130  // signals and slots connections
131  connect( boxName, SIGNAL( activated(const QString&) ), this, SLOT( activateCurve(const QString&) ) );
132  connect( buttonOK, SIGNAL( clicked() ), this, SLOT( accept() ) );
133  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
134 }
135 
137 {
138  double sampling;
139  try
140  {
141  MyParser parser;
142  parser.SetExpr(boxSampling->text());
143  sampling=parser.Eval();
144  }
145  catch(mu::ParserError &e)
146  {
147  QMessageBox::critical(this, tr("Sampling value error"), QStringFromString(e.GetMsg()));
148  boxSampling->setFocus();
149  return;
150  }
151 
152  ApplicationWindow *app = (ApplicationWindow *)parent();
153  unique_ptr<FFT> fft;
154  if (graph)
155  {
156  fft.reset(new FFT(app, graph, boxName->currentText()));
157  }
158  else if (d_table)
159  {
160  if (boxReal->currentText().isEmpty())
161  {
162  QMessageBox::critical(this, tr("Error"), tr("Please choose a column for the real part of the data!"));
163  boxReal->setFocus();
164  return;
165  }
166  fft.reset(new FFT(app, d_table, boxReal->currentText(), boxImaginary->currentText()));
167  }
168  if (fft)
169  {
170  fft->setInverseFFT(backwardBtn->isChecked());
171  fft->setSampling(sampling);
172  fft->normalizeAmplitudes(boxNormalize->isChecked());
173  fft->shiftFrequencies(boxOrder->isChecked());
174  fft->run();
175  }
176  close();
177 }
178 
180 {
181  graph = g;
182  boxName->addItems (g->analysableCurvesList());
183  activateCurve(boxName->currentText());
184 };
185 
186 void FFTDialog::activateCurve(const QString& curveName)
187 {
188  if (graph)
189  {
190  QwtPlotCurve *c = graph->curve(curveName);
191  if (!c)
192  return;
193 
194  boxSampling->setText(QString::number(c->x(1) - c->x(0)));
195  }
196  else if (d_table)
197  {
198  int col = d_table->colIndex(curveName);
199  double x0 = d_table->text(0, col).toDouble();
200  double x1 = d_table->text(1, col).toDouble();
201  boxSampling->setText(QString::number(x1 - x0));
202  }
203 };
204 
206 {
207  d_table = t;
208  QStringList l = t->columnsList();
209  boxName->addItems (l);
210  boxReal->addItems (l);
211  boxImaginary->addItems (l);
212 
213  int xcol = t->firstXCol();
214  if (xcol >= 0)
215  {
216  boxName->setCurrentIndex(xcol);
217 
218  double x0 = t->text(0, xcol).toDouble();
219  double x1 = t->text(1, xcol).toDouble();
220  boxSampling->setText(QString::number(x1 - x0));
221  }
222 
223  l = t->selectedColumns();
224  int selected = (int)l.size();
225  if (!selected)
226  {
227  boxReal->setItemText(boxReal->currentIndex(), QString());
228  boxImaginary->setItemText(boxImaginary->currentIndex(), QString());
229  }
230  else if (selected == 1)
231  {
232  boxReal->setCurrentIndex(t->colIndex(l[0]));
233  boxImaginary->setItemText(boxImaginary->currentIndex(), QString());
234  }
235  else
236  {
237  boxReal->setCurrentIndex(t->colIndex(l[0]));
238  boxImaginary->setCurrentIndex(t->colIndex(l[1]));
239  }
240 };
FFTDialog.h
Plot.h
FFTDialog::boxImaginary
QComboBox * boxImaginary
Definition: FFTDialog.h:56
MyParser.h
Table::text
QString text(int row, int col)
Definition: Table.cpp:931
FFT::shiftFrequencies
void shiftFrequencies(bool shift=true)
Definition: FFT.h:45
FFT::normalizeAmplitudes
void normalizeAmplitudes(bool norm=true)
Definition: FFT.h:44
FFTDialog::forwardBtn
QRadioButton * forwardBtn
Definition: FFTDialog.h:55
FFTDialog::activateCurve
void activateCurve(const QString &curveName)
Definition: FFTDialog.cpp:186
FFTDialog::boxOrder
QCheckBox * boxOrder
Definition: FFTDialog.h:58
QStringFromString
QString QStringFromString(const std::string &x)
Definition: QStringStdString.h:15
FFTDialog::onGraph
@ onGraph
Definition: FFTDialog.h:48
Graph::analysableCurvesList
QStringList analysableCurvesList()
Returns the names of all the curves suitable for data analysis, as a string list. The list excludes e...
Definition: Graph.cpp:1311
FFTDialog::setTable
void setTable(Table *t)
Definition: FFTDialog.cpp:205
FFTDialog::boxNormalize
QCheckBox * boxNormalize
Definition: FFTDialog.h:58
FFTDialog::buttonOK
QPushButton * buttonOK
Definition: FFTDialog.h:51
FFTDialog::boxReal
QComboBox * boxReal
Definition: FFTDialog.h:56
FFTDialog::boxName
QComboBox * boxName
Definition: FFTDialog.h:56
MyParser
Mathematical parser class based on muParser.
Definition: MyParser.h:52
FFTDialog::graph
Graph * graph
Definition: FFTDialog.h:67
Table
MDI window providing a spreadsheet table with column logic.
Definition: Table.h:51
MyParser::SetExpr
void SetExpr(const QString &x)
Definition: MyParser.h:56
FFT.h
FFTDialog::d_table
Table * d_table
Definition: FFTDialog.h:68
Table::firstXCol
int firstXCol()
Definition: Table.cpp:640
FFTDialog::FFTDialog
FFTDialog(int type, QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: FFTDialog.cpp:51
FFTDialog::accept
void accept()
Definition: FFTDialog.cpp:136
Table::columnsList
QStringList columnsList()
Definition: Table.cpp:745
FFT
Definition: FFT.h:35
MultiLayer.h
FFT::setSampling
void setSampling(double sampling)
Definition: FFT.h:43
FFTDialog::onTable
@ onTable
Definition: FFTDialog.h:48
FFTDialog::setGraph
void setGraph(Graph *g)
Definition: FFTDialog.cpp:179
FFT::setInverseFFT
void setInverseFFT(bool inverse=true)
Definition: FFT.h:42
FFTDialog::boxSampling
QLineEdit * boxSampling
Definition: FFTDialog.h:57
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
Graph.h
Table::selectedColumns
QStringList selectedColumns()
Definition: Table.cpp:663
FFTDialog::buttonCancel
QPushButton * buttonCancel
Definition: FFTDialog.h:54
FFTDialog::backwardBtn
QRadioButton * backwardBtn
Definition: FFTDialog.h:55
Filter::run
virtual bool run()
Actually does the job. Should be reimplemented in derived classes.
Definition: Filter.cpp:208
Graph
A 2D-plotting widget.
Definition: Graph.h:119
Table::colIndex
int colIndex(const QString &name)
Definition: Table.cpp:1017
ApplicationWindow.h
Table.h
Graph::curve
QwtPlotCurve * curve(int index) const
get curve by index
Definition: Graph.cpp:2821
FFTDialog::d_type
int d_type
Definition: FFTDialog.h:69