ComplexMissionItem.h 4.76 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
9

10 11 12
#ifndef ComplexMissionItem_H
#define ComplexMissionItem_H

13
#include "VisualMissionItem.h"
14
#include "QGCGeo.h"
15

Don Gagne's avatar
Don Gagne committed
16 17
#include <QSettings>

18
class ComplexMissionItem : public VisualMissionItem
19 20
{
    Q_OBJECT
21

22
public:
23
    ComplexMissionItem(Vehicle* vehicle, bool flyView, QObject* parent);
24

25 26
    const ComplexMissionItem& operator=(const ComplexMissionItem& other);

Don Gagne's avatar
Don Gagne committed
27 28 29 30 31 32
    Q_PROPERTY(double       complexDistance     READ complexDistance                            NOTIFY complexDistanceChanged)
    Q_PROPERTY(bool         presetsSupported    READ presetsSupported                           CONSTANT)
    Q_PROPERTY(QStringList  presetNames         READ presetNames                                NOTIFY presetNamesChanged)
    Q_PROPERTY(QString      currentPreset       READ currentPreset                              NOTIFY currentPresetChanged)
    Q_PROPERTY(bool         cameraInPreset      READ cameraInPreset     WRITE setCameraInPreset NOTIFY cameraInPresetChanged)
    Q_PROPERTY(bool         builtInPreset       READ builtInPreset      WRITE setBuiltInPreset  NOTIFY builtInPresetChanged)
33

34
    /// @return The distance covered the complex mission item in meters.
35
    /// Signals complexDistanceChanged
36
    virtual double complexDistance(void) const = 0;
37

38 39
    /// Load the complex mission item from Json
    ///     @param complexObject Complex mission item json object
Don Gagne's avatar
Don Gagne committed
40
    ///     @param sequenceNumber Sequence number for first MISSION_ITEM in survey
41 42
    ///     @param[out] errorString Error if load fails
    /// @return true: load success, false: load failed, errorString set
Don Gagne's avatar
Don Gagne committed
43
    virtual bool load(const QJsonObject& complexObject, int sequenceNumber, QString& errorString) = 0;
44

Don Gagne's avatar
Don Gagne committed
45 46 47 48 49 50 51 52 53 54 55
    /// Loads the specified preset into the complex item.
    ///     @param name Preset name.
    Q_INVOKABLE virtual void loadPreset(const QString& name);

    /// Saves the current state of the complex item as the named preset.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    Q_INVOKABLE virtual void savePreset(const QString& name);

    Q_INVOKABLE void clearCurrentPreset(void);
    Q_INVOKABLE void deleteCurrentPreset(void);

56 57 58
    /// Get the point of complex mission item furthest away from a coordinate
    ///     @param other QGeoCoordinate to which distance is calculated
    /// @return the greatest distance from any point of the complex item to some coordinate
59
    /// Signals greatestDistanceToChanged
60
    virtual double greatestDistanceTo(const QGeoCoordinate &other) const = 0;
61

Don Gagne's avatar
Don Gagne committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    /// Returns the list of currently saved presets for this complex item type.
    ///     @param name User visible name for preset. Will replace existing preset if already exists.
    virtual QStringList presetNames(void);

    /// Returns the name of the settings group for presets.
    ///     Empty string signals no support for presets.
    virtual QString presetsSettingsGroup(void) { return QString(); }

    bool    presetsSupported    (void) { return !presetsSettingsGroup().isEmpty(); }
    QString currentPreset       (void) const { return _currentPreset; }
    bool    cameraInPreset      (void) const { return _cameraInPreset; }
    bool    builtInPreset       (void) const { return _builtInPreset; }
    void    setCameraInPreset   (bool cameraInPreset);
    void    setBuiltInPreset    (bool builtInPreset);

Don Gagne's avatar
Don Gagne committed
77 78 79
    /// This mission item attribute specifies the type of the complex item.
    static const char* jsonComplexItemTypeKey;

80
signals:
81
    void complexDistanceChanged     (void);
82
    void boundingCubeChanged        (void);
83
    void greatestDistanceToChanged  (void);
Don Gagne's avatar
Don Gagne committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    void presetNamesChanged         (void);
    void currentPresetChanged       (QString currentPreset);
    void cameraInPresetChanged      (bool cameraInPreset);
    void builtInPresetChanged       (bool builtInPreset);

protected:
    void        _saveItem       (QJsonObject& saveObject);
    void        _loadItem       (const QJsonObject& saveObject);
    void        _savePresetJson (const QString& name, QJsonObject& presetObject);
    QJsonObject _loadPresetJson (const QString& name);


    QMap<QString, FactMetaData*> _metaDataMap;

    QString         _currentPreset;
    SettingsFact    _saveCameraInPresetFact;
    bool            _cameraInPreset;
    bool            _builtInPreset;

    static const char* _presetSettingsKey;
    static const char* _presetNameKey;
    static const char* _saveCameraInPresetKey;
    static const char* _builtInPresetKey;
107 108 109
};

#endif