File indexing completed on 2024-12-22 04:17:27
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 #include "csddialog.h" 0014 0015 #include "dialogpage.h" 0016 #include "editmultiplewidget.h" 0017 0018 #include "psd.h" 0019 0020 #include "view.h" 0021 #include "plotitem.h" 0022 #include "tabwidget.h" 0023 #include "mainwindow.h" 0024 #include "document.h" 0025 #include "objectstore.h" 0026 #include "application.h" 0027 #include "plotrenderitem.h" 0028 #include "curve.h" 0029 #include "palette.h" 0030 #include "image.h" 0031 0032 #include "datacollection.h" 0033 #include "updatemanager.h" 0034 0035 #include <QPushButton> 0036 0037 namespace Kst { 0038 0039 CSDTab::CSDTab(QWidget *parent) 0040 : DataTab(parent) { 0041 0042 setupUi(this); 0043 setTabTitle(tr("Spectrogram")); 0044 connect(_vector, SIGNAL(selectionChanged(QString)), this, SLOT(selectionChanged())); 0045 connect(_FFTOptions, SIGNAL(modified()), this, SIGNAL(modified())); 0046 connect(_vector, SIGNAL(selectionChanged(QString)), this, SIGNAL(modified())); 0047 connect(_windowSize, SIGNAL(valueChanged(int)), this, SIGNAL(modified())); 0048 0049 0050 } 0051 0052 0053 CSDTab::~CSDTab() { 0054 } 0055 0056 0057 void CSDTab::selectionChanged() { 0058 emit optionsChanged(); 0059 } 0060 0061 0062 VectorPtr CSDTab::vector() const { 0063 return _vector->selectedVector(); 0064 } 0065 0066 0067 bool CSDTab::vectorDirty() const { 0068 return _vector->selectedVectorDirty(); 0069 } 0070 0071 0072 void CSDTab::setVector(const VectorPtr vector) { 0073 _vector->setSelectedVector(vector); 0074 } 0075 0076 0077 CurvePlacement* CSDTab::curvePlacement() const { 0078 return _curvePlacement; 0079 } 0080 0081 0082 FFTOptions* CSDTab::FFTOptionsWidget() const { 0083 return _FFTOptions; 0084 } 0085 0086 0087 ColorPalette* CSDTab::colorPalette() const { 0088 return _colorPalette; 0089 } 0090 0091 0092 int CSDTab::windowSize() const { 0093 return _windowSize->value(); 0094 } 0095 0096 0097 bool CSDTab::windowSizeDirty() const { 0098 return !_windowSize->text().isEmpty(); 0099 } 0100 0101 0102 void CSDTab::setWindowSize(const int windowSize) { 0103 _windowSize->setValue(windowSize); 0104 } 0105 0106 0107 void CSDTab::setObjectStore(ObjectStore *store) { 0108 _vector->setObjectStore(store); 0109 } 0110 0111 0112 void CSDTab::hideImageOptions() { 0113 _imageOptionsGroup->setVisible(false); 0114 _curvePlacement->setVisible(false); 0115 } 0116 0117 0118 void CSDTab::clearTabValues() { 0119 _vector->clearSelection(); 0120 _windowSize->clear(); 0121 _FFTOptions->clearValues(); 0122 } 0123 0124 0125 CSDDialog::CSDDialog(ObjectPtr dataObject, QWidget *parent) 0126 : DataDialog(dataObject, parent) { 0127 0128 if (editMode() == Edit) 0129 setWindowTitle(tr("Edit Spectrogram")); 0130 else 0131 setWindowTitle(tr("New Spectrogram")); 0132 0133 _CSDTab = new CSDTab(this); 0134 addDataTab(_CSDTab); 0135 0136 if (editMode() == Edit) { 0137 configureTab(dataObject); 0138 } 0139 0140 connect(_CSDTab, SIGNAL(optionsChanged()), this, SLOT(updateButtons())); 0141 connect(this, SIGNAL(editMultipleMode()), this, SLOT(editMultipleMode())); 0142 connect(this, SIGNAL(editSingleMode()), this, SLOT(editSingleMode())); 0143 0144 connect(_CSDTab, SIGNAL(modified()), this, SLOT(modified())); 0145 updateButtons(); 0146 } 0147 0148 0149 CSDDialog::~CSDDialog() { 0150 } 0151 0152 0153 // QString CSDDialog::tagString() const { 0154 // return DataDialog::tagString(); 0155 // } 0156 0157 0158 void CSDDialog::editMultipleMode() { 0159 _CSDTab->clearTabValues(); 0160 } 0161 0162 0163 void CSDDialog::editSingleMode() { 0164 configureTab(dataObject()); 0165 } 0166 0167 0168 void CSDDialog::updateButtons() { 0169 _buttonBox->button(QDialogButtonBox::Ok)->setEnabled(_CSDTab->vector() || (editMode() == EditMultiple)); 0170 } 0171 0172 0173 void CSDDialog::setVector(VectorPtr vector) { 0174 _CSDTab->setVector(vector); 0175 } 0176 0177 0178 void CSDDialog::configureTab(ObjectPtr object) { 0179 if (CSDPtr csd = kst_cast<CSD>(object)) { 0180 _CSDTab->setVector(csd->vector()); 0181 _CSDTab->setWindowSize(csd->windowSize()); 0182 _CSDTab->FFTOptionsWidget()->setSampleRate(csd->frequency()); 0183 _CSDTab->FFTOptionsWidget()->setInterleavedAverage(csd->average()); 0184 _CSDTab->FFTOptionsWidget()->setFFTLength(csd->length()); 0185 _CSDTab->FFTOptionsWidget()->setApodize(csd->apodize()); 0186 _CSDTab->FFTOptionsWidget()->setRemoveMean(csd->removeMean()); 0187 _CSDTab->FFTOptionsWidget()->setVectorUnits(csd->vectorUnits()); 0188 _CSDTab->FFTOptionsWidget()->setRateUnits(csd->rateUnits()); 0189 _CSDTab->FFTOptionsWidget()->setApodizeFunction(csd->apodizeFxn()); 0190 _CSDTab->FFTOptionsWidget()->setSigma(csd->gaussianSigma()); 0191 _CSDTab->FFTOptionsWidget()->setOutput(csd->output()); 0192 _CSDTab->hideImageOptions(); 0193 if (_editMultipleWidget) { 0194 CSDList objects = _document->objectStore()->getObjects<CSD>(); 0195 _editMultipleWidget->clearObjects(); 0196 foreach(CSDPtr object, objects) { 0197 _editMultipleWidget->addObject(object->Name(), object->descriptionTip()); 0198 } 0199 } 0200 } 0201 } 0202 0203 0204 ObjectPtr CSDDialog::createNewDataObject() { 0205 Q_ASSERT(_document && _document->objectStore()); 0206 CSDPtr csd = _document->objectStore()->createObject<CSD>(); 0207 csd->change(_CSDTab->vector(), 0208 _CSDTab->FFTOptionsWidget()->sampleRate(), 0209 _CSDTab->FFTOptionsWidget()->interleavedAverage(), 0210 _CSDTab->FFTOptionsWidget()->removeMean(), 0211 _CSDTab->FFTOptionsWidget()->apodize(), 0212 _CSDTab->FFTOptionsWidget()->apodizeFunction(), 0213 _CSDTab->windowSize(), 0214 _CSDTab->FFTOptionsWidget()->FFTLength(), 0215 _CSDTab->FFTOptionsWidget()->sigma(), 0216 _CSDTab->FFTOptionsWidget()->output(), 0217 _CSDTab->FFTOptionsWidget()->vectorUnits(), 0218 _CSDTab->FFTOptionsWidget()->rateUnits()); 0219 0220 if (DataDialog::tagStringAuto()) { 0221 csd->setDescriptiveName(QString()); 0222 } else { 0223 csd->setDescriptiveName(DataDialog::tagString()); 0224 } 0225 0226 csd->writeLock(); 0227 csd->registerChange(); 0228 csd->unlock(); 0229 0230 ImagePtr image = _document->objectStore()->createObject<Image>(); 0231 image->changeToColorOnly(csd->outputMatrix(), 0, 1, true, _CSDTab->colorPalette()->selectedPalette()); 0232 0233 image->writeLock(); 0234 image->registerChange(); 0235 image->unlock(); 0236 0237 if(editMode()==New) { 0238 PlotItem *plotItem = 0; 0239 switch (_CSDTab->curvePlacement()->place()) { 0240 case CurvePlacement::NoPlot: 0241 break; 0242 case CurvePlacement::ExistingPlot: 0243 { 0244 plotItem = static_cast<PlotItem*>(_CSDTab->curvePlacement()->existingPlot()); 0245 break; 0246 } 0247 case CurvePlacement::NewPlotNewTab: 0248 _document->createView(); 0249 // fall through to case NewPlot. 0250 case CurvePlacement::NewPlot: 0251 { 0252 CreatePlotForCurve *cmd = new CreatePlotForCurve(); 0253 cmd->createItem(); 0254 0255 plotItem = static_cast<PlotItem*>(cmd->item()); 0256 if (_CSDTab->curvePlacement()->scaleFonts()) { 0257 plotItem->view()->resetPlotFontSizes(plotItem); 0258 plotItem->view()->configurePlotFontDefaults(plotItem); // copy plots already in window 0259 } 0260 break; 0261 } 0262 default: 0263 break; 0264 } 0265 0266 if (_CSDTab->curvePlacement()->place() != CurvePlacement::NoPlot) { 0267 PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian); 0268 renderItem->addRelation(kst_cast<Relation>(image)); 0269 plotItem->update(); 0270 0271 if (_CSDTab->curvePlacement()->place() != CurvePlacement::ExistingPlot) { 0272 plotItem->view()->appendToLayout(_CSDTab->curvePlacement()->layout(), plotItem, _CSDTab->curvePlacement()->gridColumns()); 0273 } 0274 } 0275 } 0276 0277 return ObjectPtr(image.data()); 0278 } 0279 0280 0281 ObjectPtr CSDDialog::editExistingDataObject() const { 0282 if (CSDPtr csd = kst_cast<CSD>(dataObject())) { 0283 if (editMode() == EditMultiple) { 0284 const FFTOptions *options = _CSDTab->FFTOptionsWidget(); 0285 QStringList objects = _editMultipleWidget->selectedObjects(); 0286 foreach (const QString &objectName, objects) { 0287 CSDPtr csd = kst_cast<CSD>(_document->objectStore()->retrieveObject(objectName)); 0288 if (csd) { 0289 VectorPtr vector = _CSDTab->vectorDirty() ? _CSDTab->vector() : csd->vector(); 0290 const double frequency = options->sampleRateDirty() ? options->sampleRate() : csd->frequency(); 0291 const double sigma = options->sigmaDirty() ? options->sigma() : csd->gaussianSigma(); 0292 const bool apodize = options->apodizeDirty() ? options->apodize() : csd->apodize(); 0293 const bool removeMean = options->removeMeanDirty() ? options->removeMean() : csd->removeMean(); 0294 const bool interleavedAverage = options->interleavedAverageDirty() ? options->interleavedAverage() : csd->average(); 0295 const int FFTLength = options->FFTLengthDirty() ? options->FFTLength() : csd->length(); 0296 const ApodizeFunction apodizeFunction = options->apodizeFunctionDirty() ? options->apodizeFunction() : csd->apodizeFxn(); 0297 const PSDType output = options->outputDirty() ? options->output() : csd->output(); 0298 const QString vectorUnits = options->vectorUnitsDirty() ? options->vectorUnits() : csd->vectorUnits(); 0299 const QString rateUnits = options->rateUnitsDirty() ? options->rateUnits() : csd->rateUnits(); 0300 const int windowSize = _CSDTab->windowSizeDirty() ? _CSDTab->windowSize() : csd->windowSize(); 0301 0302 csd->writeLock(); 0303 csd->change(vector, 0304 frequency, 0305 interleavedAverage, 0306 removeMean, 0307 apodize, 0308 apodizeFunction, 0309 windowSize, 0310 FFTLength, 0311 sigma, 0312 output, 0313 vectorUnits, 0314 rateUnits); 0315 0316 csd->registerChange(); 0317 csd->unlock(); 0318 } 0319 } 0320 } else { 0321 csd->writeLock(); 0322 csd->change(_CSDTab->vector(), 0323 _CSDTab->FFTOptionsWidget()->sampleRate(), 0324 _CSDTab->FFTOptionsWidget()->interleavedAverage(), 0325 _CSDTab->FFTOptionsWidget()->removeMean(), 0326 _CSDTab->FFTOptionsWidget()->apodize(), 0327 _CSDTab->FFTOptionsWidget()->apodizeFunction(), 0328 _CSDTab->windowSize(), 0329 _CSDTab->FFTOptionsWidget()->FFTLength(), 0330 _CSDTab->FFTOptionsWidget()->sigma(), 0331 _CSDTab->FFTOptionsWidget()->output(), 0332 _CSDTab->FFTOptionsWidget()->vectorUnits(), 0333 _CSDTab->FFTOptionsWidget()->rateUnits()); 0334 if (DataDialog::tagStringAuto()) { 0335 csd->setDescriptiveName(QString()); 0336 } else { 0337 csd->setDescriptiveName(DataDialog::tagString()); 0338 } 0339 csd->registerChange(); 0340 csd->unlock(); 0341 } 0342 } 0343 0344 return dataObject(); 0345 } 0346 0347 } 0348 0349 // vim: ts=2 sw=2 et