File indexing completed on 2024-12-22 04:17:59
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 "psdfactory.h" 0014 0015 #include "debug.h" 0016 #include "psd.h" 0017 #include "datacollection.h" 0018 #include "objectstore.h" 0019 0020 namespace Kst { 0021 0022 PSDFactory::PSDFactory() 0023 : ObjectFactory() { 0024 registerFactory(PSD::staticTypeTag, this); 0025 } 0026 0027 0028 PSDFactory::~PSDFactory() { 0029 } 0030 0031 0032 DataObjectPtr PSDFactory::generateObject(ObjectStore *store, QXmlStreamReader& xml) { 0033 Q_ASSERT(store); 0034 0035 double frequency=1.0, gaussianSigma=1.0; 0036 int length=8, apodizeFunction=0, outputType=0; 0037 QString vectorName, vectorUnits, rateUnits, descriptiveName; 0038 bool average=false, removeMean=false, apodize=false; 0039 0040 while (!xml.atEnd()) { 0041 const QString n = xml.name().toString(); 0042 if (xml.isStartElement()) { 0043 if (n == PSD::staticTypeTag) { 0044 QXmlStreamAttributes attrs = xml.attributes(); 0045 vectorName = attrs.value("vector").toString(); 0046 vectorUnits = attrs.value("vectorunits").toString(); 0047 rateUnits = attrs.value("rateunits").toString(); 0048 0049 frequency = attrs.value("samplerate").toString().toDouble(); 0050 gaussianSigma = attrs.value("gaussiansigma").toString().toDouble(); 0051 0052 length = attrs.value("fftlength").toString().toInt(); 0053 apodizeFunction = attrs.value("apodizefunction").toString().toInt(); 0054 outputType = attrs.value("outputtype").toString().toInt(); 0055 0056 average = attrs.value("average").toString() == "true" ? true : false; 0057 removeMean = attrs.value("removemean").toString() == "true" ? true : false; 0058 apodize = attrs.value("apodize").toString() == "true" ? true : false; 0059 if (attrs.value("descriptiveNameIsManual").toString() == "true") { 0060 descriptiveName = attrs.value("descriptiveName").toString(); 0061 } 0062 Object::processShortNameIndexAttributes(attrs); 0063 0064 } else { 0065 return 0; 0066 } 0067 } else if (xml.isEndElement()) { 0068 if (n == PSD::staticTypeTag) { 0069 break; 0070 } else { 0071 Debug::self()->log(QObject::tr("Error creating PSD from Kst file."), Debug::Warning); 0072 return 0; 0073 } 0074 } 0075 xml.readNext(); 0076 } 0077 0078 if (xml.hasError()) { 0079 return 0; 0080 } 0081 0082 VectorPtr vector = 0; 0083 if (store && !vectorName.isEmpty()) { 0084 vector = kst_cast<Vector>(store->retrieveObject(vectorName)); 0085 } 0086 0087 if (!vector) { 0088 Debug::self()->log(QObject::tr("Error creating PSD from Kst file. Could not find Vector."), Debug::Warning); 0089 return 0; 0090 } 0091 0092 PSDPtr powerspectrum = store->createObject<PSD>(); 0093 Q_ASSERT(powerspectrum); 0094 0095 powerspectrum->writeLock(); 0096 powerspectrum->change(vector, frequency, 0097 average, length, apodize, removeMean, 0098 vectorUnits, rateUnits, (ApodizeFunction)apodizeFunction, 0099 gaussianSigma, (PSDType)outputType); 0100 0101 powerspectrum->setDescriptiveName(descriptiveName); 0102 0103 powerspectrum->registerChange(); 0104 powerspectrum->unlock(); 0105 0106 return powerspectrum; 0107 } 0108 0109 } 0110 0111 // vim: ts=2 sw=2 et