GeoTagController.h 4.04 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#ifndef GeoTagController_H
#define GeoTagController_H

13 14 15
#include "QmlObjectListModel.h"
#include "Fact.h"
#include "FactMetaData.h"
Don Gagne's avatar
Don Gagne committed
16 17 18
#include <QObject>
#include <QString>
#include <QThread>
19
#include <QFileInfoList>
Andreas Bircher's avatar
Andreas Bircher committed
20 21 22
#include <QElapsedTimer>
#include <QDebug>
#include <QGeoCoordinate>
Don Gagne's avatar
Don Gagne committed
23 24 25 26 27 28 29 30

class GeoTagWorker : public QThread
{
    Q_OBJECT

public:
    GeoTagWorker(void);

31 32 33
    void setLogFile         (const QString& logFile)        { _logFile = logFile; }
    void setImageDirectory  (const QString& imageDirectory) { _imageDirectory = imageDirectory; }
    void setSaveDirectory   (const QString& saveDirectory)  { _saveDirectory = saveDirectory; }
Don Gagne's avatar
Don Gagne committed
34

35 36 37
    QString logFile         (void) const { return _logFile; }
    QString imageDirectory  (void) const { return _imageDirectory; }
    QString saveDirectory   (void) const { return _saveDirectory; }
Don Gagne's avatar
Don Gagne committed
38

39
    void cancelTagging      (void) { _cancel = true; }
Don Gagne's avatar
Don Gagne committed
40 41 42 43 44

protected:
    void run(void) final;

signals:
45 46 47
    void error              (QString errorMsg);
    void taggingComplete    (void);
    void progressChanged    (double progress);
Don Gagne's avatar
Don Gagne committed
48 49

private:
Andreas Bircher's avatar
Andreas Bircher committed
50 51 52
    bool parsePX4Log();
    bool triggerFiltering();

53 54 55 56 57 58 59 60 61 62
    bool                    _cancel;
    QString                 _logFile;
    QString                 _imageDirectory;
    QString                 _saveDirectory;
    QFileInfoList           _imageList;
    QList<double>           _tagTime;
    QList<QGeoCoordinate>   _geoRef;
    QList<double>           _triggerTime;
    QList<int>              _imageIndices;
    QList<int>              _triggerIndices;
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69 70 71 72 73 74 75
};

/// Controller for GeoTagPage.qml. Supports geotagging images based on logfile camera tags.
class GeoTagController : public QObject
{
    Q_OBJECT
    
public:
    GeoTagController(void);
    ~GeoTagController();
    
    Q_PROPERTY(QString  logFile         READ logFile        NOTIFY logFileChanged)
    Q_PROPERTY(QString  imageDirectory  READ imageDirectory NOTIFY imageDirectoryChanged)
76
    Q_PROPERTY(QString  saveDirectory   READ saveDirectory  NOTIFY saveDirectoryChanged)
Don Gagne's avatar
Don Gagne committed
77 78 79 80 81 82 83 84 85 86 87 88

    /// Set to an error message is geotagging fails
    Q_PROPERTY(QString  errorMessage    READ errorMessage   NOTIFY errorMessageChanged)

    /// Progress indicator: 0-100
    Q_PROPERTY(double   progress        READ progress       NOTIFY progressChanged)

    /// true: Currently in the process of tagging
    Q_PROPERTY(bool     inProgress      READ inProgress     NOTIFY inProgressChanged)

    Q_INVOKABLE void pickLogFile(void);
    Q_INVOKABLE void pickImageDirectory(void);
89
    Q_INVOKABLE void pickSaveDirectory(void);
Don Gagne's avatar
Don Gagne committed
90
    Q_INVOKABLE void startTagging(void);
Andreas Bircher's avatar
Andreas Bircher committed
91
    Q_INVOKABLE void cancelTagging(void) { _worker.cancelTagging(); }
Don Gagne's avatar
Don Gagne committed
92

93 94 95 96 97 98
    QString logFile             (void) const { return _worker.logFile(); }
    QString imageDirectory      (void) const { return _worker.imageDirectory(); }
    QString saveDirectory       (void) const { return _worker.saveDirectory(); }
    double  progress            (void) const { return _progress; }
    bool    inProgress          (void) const { return _worker.isRunning(); }
    QString errorMessage        (void) const { return _errorMessage; }
Don Gagne's avatar
Don Gagne committed
99 100

signals:
101 102 103 104 105 106
    void logFileChanged                 (QString logFile);
    void imageDirectoryChanged          (QString imageDirectory);
    void saveDirectoryChanged           (QString saveDirectory);
    void progressChanged                (double progress);
    void inProgressChanged              (void);
    void errorMessageChanged            (QString errorMessage);
Don Gagne's avatar
Don Gagne committed
107 108 109 110 111 112

private slots:
    void _workerProgressChanged(double progress);
    void _workerError(QString errorMsg);

private:
113 114 115
    QString             _errorMessage;
    double              _progress;
    bool                _inProgress;
Don Gagne's avatar
Don Gagne committed
116

117
    GeoTagWorker        _worker;
Don Gagne's avatar
Don Gagne committed
118 119 120
};

#endif