GeoTagController.h 4.31 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

class GeoTagWorker : public QThread
{
    Q_OBJECT

public:
Gus Grubba's avatar
Gus Grubba committed
29
    GeoTagWorker();
Don Gagne's avatar
Don Gagne committed
30

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

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

Gus Grubba's avatar
Gus Grubba committed
39
    void cancelTagging      () { _cancel = true; }
Don Gagne's avatar
Don Gagne committed
40

41 42 43 44 45 46 47 48 49 50 51 52
    struct cameraFeedbackPacket {
        double timestamp;
        double timestampUTC;
        uint32_t imageSequence;
        double latitude;
        double longitude;
        float altitude;
        float groundDistance;
        float attitudeQuaternion[4];
        uint8_t captureResult;
    };

Don Gagne's avatar
Don Gagne committed
53
protected:
Gus Grubba's avatar
Gus Grubba committed
54
    void run() final;
Don Gagne's avatar
Don Gagne committed
55 56

signals:
57
    void error              (QString errorMsg);
Gus Grubba's avatar
Gus Grubba committed
58
    void taggingComplete    ();
59
    void progressChanged    (double progress);
Don Gagne's avatar
Don Gagne committed
60 61

private:
Andreas Bircher's avatar
Andreas Bircher committed
62 63
    bool triggerFiltering();

64 65 66 67 68
    bool                    _cancel;
    QString                 _logFile;
    QString                 _imageDirectory;
    QString                 _saveDirectory;
    QFileInfoList           _imageList;
69 70
    QList<double>           _imageTime;
    QList<cameraFeedbackPacket> _triggerList;
71 72
    QList<int>              _imageIndices;
    QList<int>              _triggerIndices;
73

Don Gagne's avatar
Don Gagne committed
74 75 76 77 78 79 80
};

/// Controller for GeoTagPage.qml. Supports geotagging images based on logfile camera tags.
class GeoTagController : public QObject
{
    Q_OBJECT
public:
Gus Grubba's avatar
Gus Grubba committed
81
    GeoTagController();
Don Gagne's avatar
Don Gagne committed
82
    ~GeoTagController();
Gus Grubba's avatar
Gus Grubba committed
83 84 85 86

    Q_PROPERTY(QString  logFile         READ logFile        WRITE setLogFile        NOTIFY logFileChanged)
    Q_PROPERTY(QString  imageDirectory  READ imageDirectory WRITE setImageDirectory NOTIFY imageDirectoryChanged)
    Q_PROPERTY(QString  saveDirectory   READ saveDirectory  WRITE setSaveDirectory  NOTIFY saveDirectoryChanged)
Don Gagne's avatar
Don Gagne committed
87 88 89 90 91 92 93 94 95 96

    /// 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)

Gus Grubba's avatar
Gus Grubba committed
97 98 99 100 101 102 103 104 105
    Q_INVOKABLE void startTagging();
    Q_INVOKABLE void cancelTagging() { _worker.cancelTagging(); }

    QString logFile             () const { return _worker.logFile(); }
    QString imageDirectory      () const { return _worker.imageDirectory(); }
    QString saveDirectory       () const { return _worker.saveDirectory(); }
    double  progress            () const { return _progress; }
    bool    inProgress          () const { return _worker.isRunning(); }
    QString errorMessage        () const { return _errorMessage; }
Don Gagne's avatar
Don Gagne committed
106

Gus Grubba's avatar
Gus Grubba committed
107 108 109
    void    setLogFile          (QString file);
    void    setImageDirectory   (QString dir);
    void    setSaveDirectory    (QString dir);
Don Gagne's avatar
Don Gagne committed
110 111

signals:
Gus Grubba's avatar
Gus Grubba committed
112 113 114 115 116 117
    void logFileChanged         (QString logFile);
    void imageDirectoryChanged  (QString imageDirectory);
    void saveDirectoryChanged   (QString saveDirectory);
    void progressChanged        (double progress);
    void inProgressChanged      ();
    void errorMessageChanged    (QString errorMessage);
Don Gagne's avatar
Don Gagne committed
118 119

private slots:
120 121 122
    void _workerProgressChanged (double progress);
    void _workerError           (QString errorMsg);
    void _setErrorMessage       (const QString& error);
Don Gagne's avatar
Don Gagne committed
123 124

private:
125 126 127
    QString             _errorMessage;
    double              _progress;
    bool                _inProgress;
Don Gagne's avatar
Don Gagne committed
128

129
    GeoTagWorker        _worker;
Don Gagne's avatar
Don Gagne committed
130 131 132
};

#endif