File indexing completed on 2024-12-29 04:11:44
0001 /*************************************************************************** 0002 * * 0003 * Copyright : (C) 2003 The University of Toronto * 0004 * email : 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 #ifndef ASCIIDATAINTERFACES_H 0014 #define ASCIIDATAINTERFACES_H 0015 0016 #include "datasource.h" 0017 #include "dataplugin.h" 0018 0019 #include "curve.h" 0020 #include "colorsequence.h" 0021 #include "objectstore.h" 0022 0023 0024 using namespace Kst; 0025 0026 0027 // 0028 // Vector interface 0029 // 0030 0031 0032 //------------------------------------------------------------------------------------------- 0033 class DataInterfaceAsciiVector : public DataSource::DataInterface<DataVector> 0034 { 0035 public: 0036 explicit DataInterfaceAsciiVector(AsciiSource& a) : ascii(a) {} 0037 0038 void prepareRead(int); 0039 void readingDone(); 0040 // read one element 0041 int read(const QString&, DataVector::ReadInfo&); 0042 0043 // named elements 0044 QStringList list() const { return ascii._fieldList; } 0045 bool isListComplete() const { return ascii._fieldListComplete; } 0046 bool isValid(const QString& field) const { return ascii._fieldLookup.contains( field ); } 0047 0048 // T specific 0049 const DataVector::DataInfo dataInfo(const QString&, int frame = 0) const; 0050 void setDataInfo(const QString&, const DataVector::DataInfo&) {} 0051 0052 // meta data 0053 QMap<QString, double> metaScalars(const QString&); 0054 QMap<QString, QString> metaStrings(const QString&); 0055 0056 0057 AsciiSource& ascii; 0058 }; 0059 0060 0061 //------------------------------------------------------------------------------------------- 0062 const DataVector::DataInfo DataInterfaceAsciiVector::dataInfo(const QString &field, int frame) const 0063 { 0064 Q_UNUSED(frame) 0065 if (!ascii._fieldLookup.contains(field)) 0066 return DataVector::DataInfo(); 0067 0068 return DataVector::DataInfo(ascii._reader.numberOfFrames(), 1); 0069 } 0070 0071 //------------------------------------------------------------------------------------------- 0072 void DataInterfaceAsciiVector::prepareRead(int number_of_read_calls) 0073 { 0074 ascii.prepareRead(number_of_read_calls); 0075 } 0076 0077 //------------------------------------------------------------------------------------------- 0078 void DataInterfaceAsciiVector::readingDone() 0079 { 0080 ascii.readingDone(); 0081 } 0082 0083 //------------------------------------------------------------------------------------------- 0084 int DataInterfaceAsciiVector::read(const QString& field, DataVector::ReadInfo& p) 0085 { 0086 return ascii.readField(p.data, field, p.startingFrame, p.numberOfFrames); 0087 } 0088 0089 0090 //------------------------------------------------------------------------------------------- 0091 // TODO FRAMES only in vector? 0092 QMap<QString, double> DataInterfaceAsciiVector::metaScalars(const QString&) 0093 { 0094 QMap<QString, double> m; 0095 m["FRAMES"] = ascii._reader.numberOfFrames(); 0096 return m; 0097 } 0098 0099 QMap<QString, QString> DataInterfaceAsciiVector::metaStrings(const QString& field) 0100 { 0101 QMap<QString, QString> m; 0102 if (ascii._fieldUnits.contains(field)) { 0103 m["units"] = ascii._fieldUnits[field]; 0104 } 0105 return m; 0106 } 0107 0108 0109 0110 // 0111 // String interface 0112 // 0113 0114 class DataInterfaceAsciiString : public DataSource::DataInterface<DataString> 0115 { 0116 public: 0117 explicit DataInterfaceAsciiString(AsciiSource& s) : ascii(s) {} 0118 0119 // read one element 0120 int read(const QString&, DataString::ReadInfo&); 0121 0122 // named elements 0123 QStringList list() const { return ascii._strings.keys(); } 0124 bool isListComplete() const { return true; } 0125 bool isValid(const QString&) const; 0126 0127 // T specific 0128 const DataString::DataInfo dataInfo(const QString&, int frame=0) const { Q_UNUSED(frame) return DataString::DataInfo(); } 0129 void setDataInfo(const QString&, const DataString::DataInfo&) {} 0130 0131 // meta data 0132 QMap<QString, double> metaScalars(const QString&) { return QMap<QString, double>(); } 0133 QMap<QString, QString> metaStrings(const QString&) { return QMap<QString, QString>(); } 0134 0135 0136 private: 0137 AsciiSource& ascii; 0138 }; 0139 0140 0141 //------------------------------------------------------------------------------------------- 0142 int DataInterfaceAsciiString::read(const QString& string, DataString::ReadInfo& p) 0143 { 0144 if (isValid(string) && p.value) { 0145 *p.value = ascii._strings[string]; 0146 return 1; 0147 } 0148 return 0; 0149 } 0150 0151 0152 //------------------------------------------------------------------------------------------- 0153 bool DataInterfaceAsciiString::isValid(const QString& string) const 0154 { 0155 return ascii._strings.contains( string ); 0156 } 0157 0158 #endif