File indexing completed on 2025-06-29 04:10:00

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 
0014 #include "fftoptions.h"
0015 #include "dialogdefaults.h"
0016 
0017 namespace Kst {
0018 
0019 FFTOptions::FFTOptions(QWidget *parent)
0020     : QWidget(parent) {
0021   setupUi(this);
0022 
0023   connect(_interleavedAverage, SIGNAL(clicked()), this, SLOT(clickedInterleaved()));
0024   connect(_apodize, SIGNAL(clicked()), this, SLOT(clickedApodize()));
0025   connect(_apodizeFunction, SIGNAL(currentIndexChanged(int)), this, SLOT(changedApodizeFxn()));
0026   connect(_apodize, SIGNAL(clicked()), this, SLOT(changedApodizeFxn()));
0027 
0028   connect(_apodizeFunction, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
0029   connect(_output, SIGNAL(currentIndexChanged(int)), this, SIGNAL(modified()));
0030   connect(_apodize, SIGNAL(clicked()), this, SIGNAL(modified()));
0031   connect(_removeMean, SIGNAL(clicked()), this, SIGNAL(modified()));
0032   connect(_interleavedAverage, SIGNAL(clicked()), this, SIGNAL(modified()));
0033   connect(_sampleRate, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0034   connect(_vectorUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0035   connect(_rateUnits, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0036   connect(_sigma, SIGNAL(valueChanged(double)), this, SIGNAL(modified()));
0037   connect(_FFTLength, SIGNAL(valueChanged(int)), this, SIGNAL(modified()));
0038 
0039 
0040   _FFTLength->setEnabled(false);
0041 
0042 }
0043 
0044 
0045 FFTOptions::~FFTOptions() {}
0046 
0047 
0048 void FFTOptions::init() {
0049   update();
0050 }
0051 
0052 double FFTOptions::sampleRate() const {
0053   return _sampleRate->text().toDouble();
0054 }
0055 
0056 
0057 bool FFTOptions::sampleRateDirty() const {
0058   return !_sampleRate->text().isEmpty();
0059 }
0060 
0061 
0062 void FFTOptions::setSampleRate(const double sampleRate) {
0063   _sampleRate->setText(QString::number(sampleRate));
0064 }
0065 
0066 
0067 double FFTOptions::sigma() const {
0068   return _sigma->value();
0069 }
0070 
0071 
0072 bool FFTOptions::sigmaDirty() const {
0073   return !_sigma->text().isEmpty();
0074 }
0075 
0076 
0077 void FFTOptions::setSigma(const double sigma) {
0078   _sigma->setValue(sigma);
0079 }
0080 
0081 
0082 bool FFTOptions::interleavedAverage() const {
0083   return _interleavedAverage->isChecked();
0084 }
0085 
0086 
0087 bool FFTOptions::interleavedAverageDirty() const {
0088   return _interleavedAverage->checkState() == Qt::PartiallyChecked;
0089 }
0090 
0091 
0092 void FFTOptions::setInterleavedAverage(const bool interleavedAverage) {
0093   _interleavedAverage->setChecked(interleavedAverage);
0094   _FFTLength->setEnabled(interleavedAverage);
0095 }
0096 
0097 
0098 bool FFTOptions::apodize() const {
0099   return _apodize->isChecked();
0100 }
0101 
0102 
0103 bool FFTOptions::apodizeDirty() const {
0104   return _apodize->checkState() == Qt::PartiallyChecked;
0105 }
0106 
0107 
0108 void FFTOptions::setApodize(const bool apodize) {
0109   _apodize->setChecked(apodize);
0110   _apodizeFunction->setEnabled(apodize);
0111 }
0112 
0113 
0114 bool FFTOptions::removeMean() const {
0115   return _removeMean->isChecked();
0116 }
0117 
0118 
0119 bool FFTOptions::removeMeanDirty() const {
0120   return _removeMean->checkState() == Qt::PartiallyChecked;
0121 }
0122 
0123 
0124 void FFTOptions::setRemoveMean(const bool removeMean) {
0125   _removeMean->setChecked(removeMean);
0126 }
0127 
0128 
0129 int FFTOptions::FFTLength() const {
0130   return _FFTLength->value();
0131 }
0132 
0133 
0134 bool FFTOptions::FFTLengthDirty() const {
0135   return !_FFTLength->text().isEmpty();
0136 }
0137 
0138 
0139 void FFTOptions::setFFTLength(const int FFTLength) {
0140   _FFTLength->setValue(FFTLength);
0141 }
0142 
0143 
0144 QString FFTOptions::vectorUnits() const {
0145   return _vectorUnits->text();
0146 }
0147 
0148 
0149 bool FFTOptions::vectorUnitsDirty() const {
0150   return !_vectorUnits->text().isEmpty();
0151 }
0152 
0153 
0154 void FFTOptions::setVectorUnits(const QString vectorUnits) {
0155   _vectorUnits->setText(vectorUnits);
0156 }
0157 
0158 
0159 QString FFTOptions::rateUnits() const {
0160   return _rateUnits->text();
0161 }
0162 
0163 
0164 bool FFTOptions::rateUnitsDirty() const {
0165   return !_rateUnits->text().isEmpty();
0166 }
0167 
0168 
0169 void FFTOptions::setRateUnits(const QString rateUnits) {
0170   _rateUnits->setText(rateUnits);
0171 }
0172 
0173 
0174 ApodizeFunction FFTOptions::apodizeFunction() const {
0175   return (ApodizeFunction)_apodizeFunction->currentIndex();
0176 }
0177 
0178 
0179 bool FFTOptions::apodizeFunctionDirty() const {
0180   return _apodizeFunction->currentIndex() != -1;
0181 }
0182 
0183 
0184 void FFTOptions::setApodizeFunction(const ApodizeFunction apodizeFunction) {
0185   _apodizeFunction->setCurrentIndex((ApodizeFunction)apodizeFunction);
0186 }
0187 
0188 
0189 PSDType FFTOptions::output() const {
0190   return (PSDType)_output->currentIndex();
0191 }
0192 
0193 
0194 bool FFTOptions::outputDirty() const {
0195   return _output->currentIndex() != -1;
0196 }
0197 
0198 
0199 void FFTOptions::setOutput(const PSDType output) {
0200   _output->setCurrentIndex((PSDType)output);
0201 }
0202 
0203 
0204 void FFTOptions::clearValues() {
0205   _sigma->clear();
0206   _FFTLength->clear();
0207   _sampleRate->clear();
0208   _vectorUnits->clear();
0209   _rateUnits->clear();
0210   _apodize->setCheckState(Qt::PartiallyChecked);
0211   _interleavedAverage->setCheckState(Qt::PartiallyChecked);
0212   _removeMean->setCheckState(Qt::PartiallyChecked);
0213   _apodizeFunction->setCurrentIndex(-1);
0214   _output->setCurrentIndex(-1);
0215 }
0216 
0217 
0218 void FFTOptions::changedApodizeFxn() {
0219   int gaussianIndex = 5;
0220   if (_apodizeFunction->itemText(0).isEmpty()) {
0221     ++gaussianIndex;
0222   }
0223   _sigma->setEnabled(_apodizeFunction->currentIndex() == gaussianIndex && _apodize->isChecked());
0224   _sigmaLabel->setEnabled(_apodizeFunction->currentIndex() == gaussianIndex && _apodize->isChecked());
0225 }
0226 
0227 
0228 void FFTOptions::clickedInterleaved() {
0229   _FFTLength->setEnabled(_interleavedAverage->isChecked());
0230   _FFTLengthLabel->setEnabled(_interleavedAverage->isChecked());
0231 }
0232 
0233 
0234 void FFTOptions::clickedApodize() {
0235   _apodizeFunction->setEnabled(_apodize->isChecked());
0236 }
0237 
0238 
0239 void FFTOptions::synch() {
0240   clickedInterleaved();
0241   clickedApodize();
0242 }
0243 
0244 
0245 bool FFTOptions::checkValues() {
0246   double new_freq = _sampleRate->text().toDouble();
0247   int new_len = _FFTLength->text().toInt();
0248   return checkGivenValues(new_freq, new_len);
0249 }
0250 
0251 
0252 bool FFTOptions::checkGivenValues(double sampleRate, int FFTLength) {
0253   if (sampleRate <= 0) {
0254     return false;
0255   }
0256   if (FFTLength < 2) {
0257     return false;
0258   }
0259   return true;
0260 }
0261 
0262 // store the current state of the widget as the default
0263 void FFTOptions::setWidgetDefaults() {
0264   dialogDefaults().setValue("spectrum/freq", sampleRate());
0265   dialogDefaults().setValue("spectrum/average", interleavedAverage());
0266   dialogDefaults().setValue("spectrum/len", FFTLength());
0267   dialogDefaults().setValue("spectrum/apodize", apodize());
0268   dialogDefaults().setValue("spectrum/removeMean", removeMean());
0269   dialogDefaults().setValue("spectrum/vUnits", vectorUnits());
0270   dialogDefaults().setValue("spectrum/rUnits", rateUnits());
0271   dialogDefaults().setValue("spectrum/apodizeFxn", apodizeFunction());
0272   dialogDefaults().setValue("spectrum/gaussianSigma", sigma());
0273   dialogDefaults().setValue("spectrum/output", output());
0274 }
0275 
0276 // set the widget to the stored default values
0277 void FFTOptions::loadWidgetDefaults() {
0278   setSampleRate(dialogDefaults().value("spectrum/freq",100.0).toDouble());
0279   setInterleavedAverage(dialogDefaults().value("spectrum/average",true).toBool());
0280   setFFTLength(dialogDefaults().value("spectrum/len",12).toInt());
0281   setApodize(dialogDefaults().value("spectrum/apodize",true).toBool());
0282   setRemoveMean(dialogDefaults().value("spectrum/removeMean",true).toBool());
0283   setVectorUnits(dialogDefaults().value("spectrum/vUnits","V").toString());
0284   setRateUnits(dialogDefaults().value("spectrum/rUnits","Hz").toString());
0285   setApodizeFunction(ApodizeFunction(dialogDefaults().value("spectrum/apodizeFxn",WindowOriginal).toInt()));
0286   setSigma(dialogDefaults().value("spectrum/gaussianSigma",1.0).toDouble());
0287   setOutput(PSDType(dialogDefaults().value("spectrum/output",PSDPowerSpectralDensity).toInt()));
0288 }
0289 
0290 }
0291 // vim: ts=2 sw=2 et