~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/FFTDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : FFTDialog.cpp
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Hoener zu Siederdissen
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
7
    Description          : Fast Fourier transform options dialog
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
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
FFTDialog::FFTDialog(int type, QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
 
49
: QDialog( parent, name, modal, fl )
 
50
{
 
51
        setWindowTitle(tr("QtiPlot - FFT Options"));
 
52
 
 
53
        d_table = 0;
 
54
        graph = 0;
 
55
        d_type = type;
 
56
 
 
57
        forwardBtn = new QRadioButton(tr("&Forward"));
 
58
        forwardBtn->setChecked( true );
 
59
        backwardBtn = new QRadioButton(tr("&Inverse"));
 
60
 
 
61
        QHBoxLayout *hbox1 = new QHBoxLayout();
 
62
    hbox1->addWidget(forwardBtn);
 
63
    hbox1->addWidget(backwardBtn);
 
64
 
 
65
        QGroupBox *gb1 = new QGroupBox();
 
66
    gb1->setLayout(hbox1);
 
67
 
 
68
        QGridLayout *gl1 = new QGridLayout();
 
69
        if (d_type == onGraph)
 
70
            gl1->addWidget(new QLabel(tr("Curve")), 0, 0);
 
71
        else
 
72
                gl1->addWidget(new QLabel(tr("Sampling")), 0, 0);
 
73
 
 
74
        boxName = new QComboBox();
 
75
        gl1->addWidget(boxName, 0, 1);
 
76
 
 
77
    boxSampling = new QLineEdit();
 
78
        if (d_type == onTable)
 
79
       {
 
80
                gl1->addWidget(new QLabel(tr("Real")), 1, 0);
 
81
                boxReal = new QComboBox();
 
82
                gl1->addWidget(boxReal, 1, 1);
 
83
 
 
84
                gl1->addWidget(new QLabel(tr("Imaginary")), 2, 0);
 
85
                boxImaginary = new QComboBox();
 
86
                gl1->addWidget(boxImaginary, 2, 1);
 
87
 
 
88
                gl1->addWidget(new QLabel(tr("Sampling Interval")), 3, 0);
 
89
                gl1->addWidget(boxSampling, 3, 1);
 
90
           }
 
91
    else
 
92
       {
 
93
        gl1->addWidget(new QLabel(tr("Sampling Interval")), 1, 0);
 
94
                gl1->addWidget(boxSampling, 1, 1);
 
95
       }
 
96
        QGroupBox *gb2 = new QGroupBox();
 
97
    gb2->setLayout(gl1);
 
98
 
 
99
        boxNormalize = new QCheckBox(tr( "&Normalize Amplitude" ));
 
100
        boxNormalize->setChecked(true);
 
101
 
 
102
    boxOrder = new QCheckBox(tr( "&Shift Results" ));
 
103
        boxOrder->setChecked(true);
 
104
 
 
105
    QVBoxLayout *vbox1 = new QVBoxLayout();
 
106
    vbox1->addWidget(gb1);
 
107
    vbox1->addWidget(gb2);
 
108
    vbox1->addWidget(boxNormalize);
 
109
    vbox1->addWidget(boxOrder);
 
110
        vbox1->addStretch();
 
111
 
 
112
    buttonOK = new QPushButton(tr("&OK"));
 
113
        buttonOK->setDefault( true );
 
114
        buttonCancel = new QPushButton(tr("&Close"));
 
115
 
 
116
        QVBoxLayout *vbox2 = new QVBoxLayout();
 
117
    vbox2->addWidget(buttonOK);
 
118
    vbox2->addWidget(buttonCancel);
 
119
    vbox2->addStretch();
 
120
 
 
121
    QHBoxLayout *hbox2 = new QHBoxLayout(this);
 
122
    hbox2->addLayout(vbox1);
 
123
    hbox2->addLayout(vbox2);
 
124
 
 
125
        setFocusProxy(boxName);
 
126
 
 
127
        // signals and slots connections
 
128
        connect( boxName, SIGNAL( activated(const QString&) ), this, SLOT( activateCurve(const QString&) ) );
 
129
        connect( buttonOK, SIGNAL( clicked() ), this, SLOT( accept() ) );
 
130
        connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
131
}
 
132
 
 
133
void FFTDialog::accept()
 
134
{
 
135
        double sampling;
 
136
        try
 
137
        {
 
138
                MyParser parser;
 
139
                parser.SetExpr(boxSampling->text().ascii());
 
140
                sampling=parser.Eval();
 
141
        }
 
142
        catch(mu::ParserError &e)
 
143
        {
 
144
                QMessageBox::critical(this, tr("QtiPlot - Sampling value error"), QString::fromStdString(e.GetMsg()));
 
145
                boxSampling->setFocus();
 
146
                return;
 
147
        }
 
148
 
 
149
        ApplicationWindow *app = (ApplicationWindow *)parent();
 
150
    FFT *fft;
 
151
        if (graph)
 
152
        {
 
153
        fft = new FFT(app, graph, boxName->currentText());
 
154
        }
 
155
        else if (d_table)
 
156
        {
 
157
                if (boxReal->currentText().isEmpty())
 
158
                {
 
159
                        QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please choose a column for the real part of the data!"));
 
160
                        boxReal->setFocus();
 
161
                        return;
 
162
                }
 
163
        fft = new FFT(app, d_table, boxReal->currentText(), boxImaginary->currentText());
 
164
        }
 
165
    fft->setInverseFFT(backwardBtn->isChecked());
 
166
    fft->setSampling(sampling);
 
167
    fft->normalizeAmplitudes(boxNormalize->isChecked());
 
168
    fft->shiftFrequencies(boxOrder->isChecked());
 
169
    fft->run();
 
170
    delete fft;
 
171
        close();
 
172
}
 
173
 
 
174
void FFTDialog::setGraph(Graph *g)
 
175
{
 
176
        graph = g;
 
177
        boxName->insertStringList (g->analysableCurvesList());
 
178
        activateCurve(boxName->currentText());
 
179
};
 
180
 
 
181
void FFTDialog::activateCurve(const QString& curveName)
 
182
{
 
183
        if (graph)
 
184
        {
 
185
                QwtPlotCurve *c = graph->curve(curveName);
 
186
                if (!c)
 
187
                        return;
 
188
 
 
189
                boxSampling->setText(QString::number(c->x(1) - c->x(0)));
 
190
        }
 
191
        else if (d_table)
 
192
        {
 
193
            int col = d_table->colIndex(curveName);
 
194
                double x0 = d_table->text(0, col).toDouble();
 
195
                double x1 = d_table->text(1, col).toDouble();
 
196
                boxSampling->setText(QString::number(x1 - x0));
 
197
        }
 
198
};
 
199
 
 
200
void FFTDialog::setTable(Table *t)
 
201
{
 
202
        d_table = t;
 
203
        QStringList l = t->columnsList();
 
204
        boxName->insertStringList (l);
 
205
        boxReal->insertStringList (l);
 
206
        boxImaginary->insertStringList (l);
 
207
 
 
208
        int xcol = t->firstXCol();
 
209
        if (xcol >= 0)
 
210
        {
 
211
                boxName->setCurrentItem(xcol);
 
212
 
 
213
                double x0 = t->text(0, xcol).toDouble();
 
214
                double x1 = t->text(1, xcol).toDouble();
 
215
                boxSampling->setText(QString::number(x1 - x0));
 
216
        }
 
217
 
 
218
        l = t->selectedColumns();
 
219
        int selected = (int)l.size();
 
220
        if (!selected)
 
221
        {
 
222
                boxReal->setCurrentText(QString());
 
223
                boxImaginary->setCurrentText(QString());
 
224
        }
 
225
        else if (selected == 1)
 
226
        {
 
227
                boxReal->setCurrentItem(t->colIndex(l[0]));
 
228
                boxImaginary->setCurrentText(QString());
 
229
        }
 
230
        else
 
231
        {
 
232
                boxReal->setCurrentItem(t->colIndex(l[0]));
 
233
                boxImaginary->setCurrentItem(t->colIndex(l[1]));
 
234
        }
 
235
};