1 /***************************************************************************
2  *                                                                         *
3  *   copyright : (C) 2007 The University of Toronto                        *
4  *                   netterfield@astro.utoronto.ca                         *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  ***************************************************************************/
12 
13 
14 #include "fftoptions.h"
15 #include "dialogdefaults.h"
16 
17 namespace Kst {
18 
FFTOptions(QWidget * parent)19 FFTOptions::FFTOptions(QWidget *parent)
20     : QWidget(parent) {
21   setupUi(this);
22 
23   connect(_interleavedAverage, SIGNAL(clicked()), this, SLOT(clickedInterleaved()));
24   connect(_apodize, SIGNAL(clicked()), this, SLOT(clickedApodize()));
25   connect(_apodizeFunction, SIGNAL(currentIndexChanged(int)), this, SLOT(changedApodizeFxn()));
26   connect(_apodize, SIGNAL(clicked()), this, SLOT(changedApodizeFxn()));
27 
28   connect(_apodizeFunction, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
29   connect(_output, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
30   connect(_apodize, SIGNAL(clicked()), this, SIGNAL(modified()));
31   connect(_removeMean, SIGNAL(clicked()), this, SIGNAL(modified()));
32   connect(_interleavedAverage, SIGNAL(clicked()), this, SIGNAL(modified()));
33   connect(_sampleRate, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
34   connect(_vectorUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
35   connect(_rateUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
36   connect(_sigma, SIGNAL(valueChanged(double)), this, SIGNAL(modified()));
37   connect(_FFTLength, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
38 
39 
40   _FFTLength->setEnabled(false);
41 
42 }
43 
44 
~FFTOptions()45 FFTOptions::~FFTOptions() {}
46 
47 
init()48 void FFTOptions::init() {
49   update();
50 }
51 
sampleRate() const52 double FFTOptions::sampleRate() const {
53   return _sampleRate->text().toDouble();
54 }
55 
56 
sampleRateDirty() const57 bool FFTOptions::sampleRateDirty() const {
58   return !_sampleRate->text().isEmpty();
59 }
60 
61 
setSampleRate(const double sampleRate)62 void FFTOptions::setSampleRate(const double sampleRate) {
63   _sampleRate->setText(QString::number(sampleRate));
64 }
65 
66 
sigma() const67 double FFTOptions::sigma() const {
68   return _sigma->value();
69 }
70 
71 
sigmaDirty() const72 bool FFTOptions::sigmaDirty() const {
73   return !_sigma->text().isEmpty();
74 }
75 
76 
setSigma(const double sigma)77 void FFTOptions::setSigma(const double sigma) {
78   _sigma->setValue(sigma);
79 }
80 
81 
interleavedAverage() const82 bool FFTOptions::interleavedAverage() const {
83   return _interleavedAverage->isChecked();
84 }
85 
86 
interleavedAverageDirty() const87 bool FFTOptions::interleavedAverageDirty() const {
88   return _interleavedAverage->checkState() == Qt::PartiallyChecked;
89 }
90 
91 
setInterleavedAverage(const bool interleavedAverage)92 void FFTOptions::setInterleavedAverage(const bool interleavedAverage) {
93   _interleavedAverage->setChecked(interleavedAverage);
94   _FFTLength->setEnabled(interleavedAverage);
95 }
96 
97 
apodize() const98 bool FFTOptions::apodize() const {
99   return _apodize->isChecked();
100 }
101 
102 
apodizeDirty() const103 bool FFTOptions::apodizeDirty() const {
104   return _apodize->checkState() == Qt::PartiallyChecked;
105 }
106 
107 
setApodize(const bool apodize)108 void FFTOptions::setApodize(const bool apodize) {
109   _apodize->setChecked(apodize);
110   _apodizeFunction->setEnabled(apodize);
111 }
112 
113 
removeMean() const114 bool FFTOptions::removeMean() const {
115   return _removeMean->isChecked();
116 }
117 
118 
removeMeanDirty() const119 bool FFTOptions::removeMeanDirty() const {
120   return _removeMean->checkState() == Qt::PartiallyChecked;
121 }
122 
123 
setRemoveMean(const bool removeMean)124 void FFTOptions::setRemoveMean(const bool removeMean) {
125   _removeMean->setChecked(removeMean);
126 }
127 
128 
FFTLength() const129 int FFTOptions::FFTLength() const {
130   return _FFTLength->value();
131 }
132 
133 
FFTLengthDirty() const134 bool FFTOptions::FFTLengthDirty() const {
135   return !_FFTLength->text().isEmpty();
136 }
137 
138 
setFFTLength(const int FFTLength)139 void FFTOptions::setFFTLength(const int FFTLength) {
140   _FFTLength->setValue(FFTLength);
141 }
142 
143 
vectorUnits() const144 QString FFTOptions::vectorUnits() const {
145   return _vectorUnits->text();
146 }
147 
148 
vectorUnitsDirty() const149 bool FFTOptions::vectorUnitsDirty() const {
150   return !_vectorUnits->text().isEmpty();
151 }
152 
153 
setVectorUnits(const QString vectorUnits)154 void FFTOptions::setVectorUnits(const QString vectorUnits) {
155   _vectorUnits->setText(vectorUnits);
156 }
157 
158 
rateUnits() const159 QString FFTOptions::rateUnits() const {
160   return _rateUnits->text();
161 }
162 
163 
rateUnitsDirty() const164 bool FFTOptions::rateUnitsDirty() const {
165   return !_rateUnits->text().isEmpty();
166 }
167 
168 
setRateUnits(const QString rateUnits)169 void FFTOptions::setRateUnits(const QString rateUnits) {
170   _rateUnits->setText(rateUnits);
171 }
172 
173 
apodizeFunction() const174 ApodizeFunction FFTOptions::apodizeFunction() const {
175   return (ApodizeFunction)_apodizeFunction->currentIndex();
176 }
177 
178 
apodizeFunctionDirty() const179 bool FFTOptions::apodizeFunctionDirty() const {
180   return _apodizeFunction->currentIndex() != -1;
181 }
182 
183 
setApodizeFunction(const ApodizeFunction apodizeFunction)184 void FFTOptions::setApodizeFunction(const ApodizeFunction apodizeFunction) {
185   _apodizeFunction->setCurrentIndex((ApodizeFunction)apodizeFunction);
186 }
187 
188 
output() const189 PSDType FFTOptions::output() const {
190   return (PSDType)_output->currentIndex();
191 }
192 
193 
outputDirty() const194 bool FFTOptions::outputDirty() const {
195   return _output->currentIndex() != -1;
196 }
197 
198 
setOutput(const PSDType output)199 void FFTOptions::setOutput(const PSDType output) {
200   _output->setCurrentIndex((PSDType)output);
201 }
202 
203 
clearValues()204 void FFTOptions::clearValues() {
205   _sigma->clear();
206   _FFTLength->clear();
207   _sampleRate->clear();
208   _vectorUnits->clear();
209   _rateUnits->clear();
210   _apodize->setCheckState(Qt::PartiallyChecked);
211   _interleavedAverage->setCheckState(Qt::PartiallyChecked);
212   _removeMean->setCheckState(Qt::PartiallyChecked);
213   _apodizeFunction->setCurrentIndex(-1);
214   _output->setCurrentIndex(-1);
215 }
216 
217 
changedApodizeFxn()218 void FFTOptions::changedApodizeFxn() {
219   int gaussianIndex = 5;
220   if (_apodizeFunction->itemText(0).isEmpty()) {
221     ++gaussianIndex;
222   }
223   _sigma->setEnabled(_apodizeFunction->currentIndex() == gaussianIndex && _apodize->isChecked());
224   _sigmaLabel->setEnabled(_apodizeFunction->currentIndex() == gaussianIndex && _apodize->isChecked());
225 }
226 
227 
clickedInterleaved()228 void FFTOptions::clickedInterleaved() {
229   _FFTLength->setEnabled(_interleavedAverage->isChecked());
230   _FFTLengthLabel->setEnabled(_interleavedAverage->isChecked());
231 }
232 
233 
clickedApodize()234 void FFTOptions::clickedApodize() {
235   _apodizeFunction->setEnabled(_apodize->isChecked());
236 }
237 
238 
synch()239 void FFTOptions::synch() {
240   clickedInterleaved();
241   clickedApodize();
242 }
243 
244 
checkValues()245 bool FFTOptions::checkValues() {
246   double new_freq = _sampleRate->text().toDouble();
247   int new_len = _FFTLength->text().toInt();
248   return checkGivenValues(new_freq, new_len);
249 }
250 
251 
checkGivenValues(double sampleRate,int FFTLength)252 bool FFTOptions::checkGivenValues(double sampleRate, int FFTLength) {
253   if (sampleRate <= 0) {
254     return false;
255   }
256   if (FFTLength < 2) {
257     return false;
258   }
259   return true;
260 }
261 
262 // store the current state of the widget as the default
setWidgetDefaults()263 void FFTOptions::setWidgetDefaults() {
264   dialogDefaults().setValue("spectrum/freq", sampleRate());
265   dialogDefaults().setValue("spectrum/average", interleavedAverage());
266   dialogDefaults().setValue("spectrum/len", FFTLength());
267   dialogDefaults().setValue("spectrum/apodize", apodize());
268   dialogDefaults().setValue("spectrum/removeMean", removeMean());
269   dialogDefaults().setValue("spectrum/vUnits", vectorUnits());
270   dialogDefaults().setValue("spectrum/rUnits", rateUnits());
271   dialogDefaults().setValue("spectrum/apodizeFxn", apodizeFunction());
272   dialogDefaults().setValue("spectrum/gaussianSigma", sigma());
273   dialogDefaults().setValue("spectrum/output", output());
274 }
275 
276 // set the widget to the stored default values
loadWidgetDefaults()277 void FFTOptions::loadWidgetDefaults() {
278   setSampleRate(dialogDefaults().value("spectrum/freq",100.0).toDouble());
279   setInterleavedAverage(dialogDefaults().value("spectrum/average",true).toBool());
280   setFFTLength(dialogDefaults().value("spectrum/len",12).toInt());
281   setApodize(dialogDefaults().value("spectrum/apodize",true).toBool());
282   setRemoveMean(dialogDefaults().value("spectrum/removeMean",true).toBool());
283   setVectorUnits(dialogDefaults().value("spectrum/vUnits","V").toString());
284   setRateUnits(dialogDefaults().value("spectrum/rUnits","Hz").toString());
285   setApodizeFunction(ApodizeFunction(dialogDefaults().value("spectrum/apodizeFxn",WindowOriginal).toInt()));
286   setSigma(dialogDefaults().value("spectrum/gaussianSigma",1.0).toDouble());
287   setOutput(PSDType(dialogDefaults().value("spectrum/output",PSDPowerSpectralDensity).toInt()));
288 }
289 
290 }
291 // vim: ts=2 sw=2 et
292