File indexing completed on 2024-12-29 04:11:45

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 ASCII_SOURCE_H
0014 #define ASCII_SOURCE_H
0015 
0016 #include "asciidatareader.h"
0017 #include "asciisourceconfig.h"
0018 
0019 #include "datasource.h"
0020 #include "dataplugin.h"
0021 
0022 #include <QTime>
0023 
0024 
0025 class QFile;
0026 class DataInterfaceAsciiString;
0027 class DataInterfaceAsciiVector;
0028 class QProgressBar;
0029 class QLabel;
0030 
0031 class AsciiSource : public Kst::DataSource
0032 {
0033   Q_OBJECT
0034 
0035   public:
0036     AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e = QDomElement());
0037     ~AsciiSource();
0038 
0039     bool initRowIndex();
0040 
0041     UpdateType internalDataSourceUpdate(bool read_completely);
0042 
0043     virtual UpdateType internalDataSourceUpdate();
0044 
0045     void prepareRead(int count);
0046     void readingDone();
0047     int readField(double *v, const QString &field, int s, int n);
0048 
0049     QString fileType() const;
0050     void setUpdateType(UpdateCheckType);
0051 
0052     void save(QXmlStreamWriter &s);
0053     void parseProperties(QXmlStreamAttributes &properties);
0054 
0055     bool isEmpty() const;
0056 
0057     bool supportsTimeConversions() const;
0058 
0059     int sampleForTime(double ms, bool *ok);
0060 
0061     int sampleForTime(const QDateTime& time, bool *ok);
0062 
0063     bool isTime(const QString &field) const;
0064 
0065     virtual void reset();
0066     void updateLists();
0067 
0068     virtual const QString& typeString() const;
0069 
0070     static const QString asciiTypeKey();
0071 
0072     static QStringList fieldListFor(const QString& filename, AsciiSourceConfig cfg);
0073     static QStringList unitListFor(const QString& filename, AsciiSourceConfig cfg);
0074     static QStringList scalarListFor(const QString& filename, AsciiSourceConfig cfg);
0075     static QStringList stringListFor(const QString& filename, AsciiSourceConfig cfg);
0076 
0077     Kst::ObjectList<Kst::Object> autoCurves(Kst::ObjectStore& objectStore);
0078 
0079     QString timeFormat() const;
0080 
0081     void triggerRowProgress() { emit signalRowProgress(); }
0082 
0083     virtual void enableUpdates() {_updatesDisabled = false;}
0084 
0085 signals:
0086     void signalRowProgress();
0087 
0088 private:
0089     AsciiDataReader _reader;
0090     AsciiFileBuffer _fileBuffer;
0091     bool _busy;
0092     int _read_count_max;
0093     int _read_count;
0094 
0095     friend class AsciiConfigWidget;
0096     mutable AsciiSourceConfig _config;
0097 
0098     qint64 _fileSize;
0099     qint64 _lastFileSize;
0100 
0101     bool _haveHeader;
0102     bool _fieldListComplete;
0103     bool _haveWarned;
0104     double _fileCreationTime_t;
0105     bool _showFieldProgress;
0106     double _progress;
0107     double _progressSteps;
0108     void updateFieldMessage(const QString&);
0109     void updateFieldProgress(const QString&);
0110     void emitProgress(int precent, const QString&);
0111     QString _actualField;
0112 
0113     QStringList _scalarList;
0114     QMap<QString, QString> _strings;
0115     QStringList _fieldList;
0116     QHash<QString, int> _fieldLookup;
0117     QMap<QString, QString> _fieldUnits;
0118 
0119     bool useThreads() const;
0120     bool useSlidingWindow(qint64 bytesToRead)  const;
0121 
0122     int tryReadField(double *v, const QString &field, int s, int n);
0123     int parseWindowSinglethreaded(QVector<AsciiFileData>& fileData, int col, double* v, int start, const QString& field, int sRead);
0124     int parseWindowMultithreaded(QVector<AsciiFileData>& fileData, int col, double* v, int start, const QString& field);
0125 
0126     int columnOfField(const QString& field) const;
0127     static int splitHeaderLine(const QByteArray& line, const AsciiSourceConfig& cfg, QStringList* parts = 0);
0128 
0129     DataInterfaceAsciiString* is;
0130     DataInterfaceAsciiVector* iv;
0131 
0132     int _progressValue;
0133     qint64 _progressRows;
0134     static void rowProgress(QObject*);
0135     QTime _progressTimer;
0136 
0137     // TODO remove
0138     friend class DataInterfaceAsciiString;
0139     friend class DataInterfaceAsciiVector;
0140 
0141     bool _updatesDisabled;
0142 };
0143 
0144 
0145 #endif
0146 // vim: ts=2 sw=2 et