File indexing completed on 2024-12-22 04:17:16

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 #ifndef MATLAB_DATASOURCE_H
0015 #define MATLAB_DATASOURCE_H
0016 
0017 #include <datasource.h>
0018 #include <dataplugin.h>
0019 
0020 #include <matio.h>
0021 
0022 class DataInterfaceMatlabScalar;
0023 class DataInterfaceMatlabString;
0024 class DataInterfaceMatlabVector;
0025 class DataInterfaceMatlabMatrix;
0026 
0027 class MatlabSource : public Kst::DataSource {
0028   Q_OBJECT
0029 
0030   public:
0031     MatlabSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e);
0032 
0033     ~MatlabSource();
0034 
0035     bool init();
0036     virtual void reset();
0037 
0038     Kst::Object::UpdateType internalDataSourceUpdate();
0039 
0040     int readScalar(double *v, const QString& field);
0041 
0042     int readString(QString *stringValue, const QString& stringName);
0043 
0044     int readField(double *v, const QString& field, int s, int n);
0045 
0046     int readMatrix(double *v, const QString& field);
0047 
0048     int samplesPerFrame(const QString& field);
0049     int frameCount(const QString& field = QString()) const;
0050 
0051     QString fileType() const;
0052 
0053     void save(QXmlStreamWriter &streamWriter);
0054 
0055     class Config;
0056 
0057 
0058   private:
0059     QMap<QString, int> _frameCounts;
0060     int _maxFrameCount;
0061 
0062     // Matio file object
0063     mat_t *_matfile;
0064     mutable Config *_config;
0065 
0066     // Primitive lists
0067     QMap<QString, QString> _strings;
0068     QStringList _scalarList;
0069     QStringList _fieldList;
0070     QStringList _matrixList;
0071 
0072     friend class DataInterfaceMatlabScalar;
0073     friend class DataInterfaceMatlabString;
0074     friend class DataInterfaceMatlabVector;
0075     friend class DataInterfaceMatlabMatrix;
0076     DataInterfaceMatlabScalar* is;
0077     DataInterfaceMatlabString* it;
0078     DataInterfaceMatlabVector* iv;
0079     DataInterfaceMatlabMatrix* im;
0080 
0081 };
0082 
0083 
0084 class MatlabSourcePlugin : public QObject, public Kst::DataSourcePluginInterface {
0085     Q_OBJECT
0086     Q_INTERFACES(Kst::DataSourcePluginInterface)
0087     Q_PLUGIN_METADATA(IID "com.kst.DataSourcePluginInterface/2.0")
0088   public:
0089     virtual ~MatlabSourcePlugin() {}
0090 
0091     virtual QString pluginName() const;
0092     virtual QString pluginDescription() const;
0093 
0094     virtual bool hasConfigWidget() const { return false; }
0095 
0096     virtual Kst::DataSource *create(Kst::ObjectStore *store,
0097                                   QSettings *cfg,
0098                                   const QString &filename,
0099                                   const QString &type,
0100                                   const QDomElement &element) const;
0101 
0102     virtual QStringList matrixList(QSettings *cfg,
0103                                   const QString& filename,
0104                                   const QString& type,
0105                                   QString *typeSuggestion,
0106                                   bool *complete) const;
0107 
0108     virtual QStringList fieldList(QSettings *cfg,
0109                                   const QString& filename,
0110                                   const QString& type,
0111                                   QString *typeSuggestion,
0112                                   bool *complete) const;
0113 
0114     virtual QStringList scalarList(QSettings *cfg,
0115                                   const QString& filename,
0116                                   const QString& type,
0117                                   QString *typeSuggestion,
0118                                   bool *complete) const;
0119 
0120     virtual QStringList stringList(QSettings *cfg,
0121                                   const QString& filename,
0122                                   const QString& type,
0123                                   QString *typeSuggestion,
0124                                   bool *complete) const;
0125 
0126     virtual int understands(QSettings *cfg, const QString& filename) const;
0127 
0128     virtual bool supportsTime(QSettings *cfg, const QString& filename) const;
0129 
0130     virtual QStringList provides() const;
0131 
0132     virtual Kst::DataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const;
0133 };
0134 
0135 
0136 #endif
0137 // vim: ts=2 sw=2 et