MissionSettingsItem.h 5.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/****************************************************************************
 *
 *   (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 MissionSettingsComplexItem_H
#define MissionSettingsComplexItem_H

#include "ComplexMissionItem.h"
#include "MissionItem.h"
#include "Fact.h"
#include "QGCLoggingCategory.h"
17
#include "CameraSection.h"
18 19 20

Q_DECLARE_LOGGING_CATEGORY(MissionSettingsComplexItemLog)

21
class MissionSettingsItem : public ComplexMissionItem
22 23 24 25
{
    Q_OBJECT

public:
26
    MissionSettingsItem(Vehicle* vehicle, QObject* parent = NULL);
27 28 29 30

    enum MissionEndAction {
        MissionEndNoAction,
        MissionEndLoiter,
DonLakeFlyer's avatar
DonLakeFlyer committed
31
        MissionEndRTL
32 33 34
    };
    Q_ENUMS(MissionEndAction)

DonLakeFlyer's avatar
DonLakeFlyer committed
35 36 37 38 39 40
    Q_PROPERTY(bool     specifyMissionFlightSpeed   READ specifyMissionFlightSpeed      WRITE setSpecifyMissionFlightSpeed  NOTIFY specifyMissionFlightSpeedChanged)
    Q_PROPERTY(Fact*    missionFlightSpeed          READ missionFlightSpeed                                                 CONSTANT)
    Q_PROPERTY(Fact*    missionEndAction            READ missionEndAction                                                   CONSTANT)
    Q_PROPERTY(Fact*    plannedHomePositionAltitude READ plannedHomePositionAltitude                                        CONSTANT)
    Q_PROPERTY(QObject* cameraSection               READ cameraSection                                                      CONSTANT)

41 42 43
    Fact*   plannedHomePositionAltitude (void) { return &_plannedHomePositionAltitudeFact; }
    Fact*   missionFlightSpeed          (void) { return &_missionFlightSpeedFact; }
    Fact*   missionEndAction            (void) { return &_missionEndActionFact; }
DonLakeFlyer's avatar
DonLakeFlyer committed
44
    bool    specifyMissionFlightSpeed   (void) const { return _specifyMissionFlightSpeed; }
45

46 47
    void setSpecifyMissionFlightSpeed(bool specifyMissionFlightSpeed);
    QObject* cameraSection(void) { return &_cameraSection; }
48

49
    /// Scans the loaded items for settings items
50 51 52 53 54 55 56 57
    static bool scanForMissionSettings(QmlObjectListModel* visualItems, int scanIndex, Vehicle* vehicle);

    /// Adds the optional mission end action to the list
    ///     @param items Mission items list to append to
    ///     @param seqNum Sequence number for new item
    ///     @param missionItemParent Parent for newly allocated MissionItems
    /// @return true: Mission end action was added
    bool addMissionEndAction(QList<MissionItem*>& items, int seqNum, QObject* missionItemParent);
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

    // Overrides from ComplexMissionItem

    double              complexDistance     (void) const final;
    int                 lastSequenceNumber  (void) const final;
    bool                load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    double              greatestDistanceTo  (const QGeoCoordinate &other) const final;
    QString             mapVisualQML        (void) const final { return QStringLiteral("MissionSettingsMapVisual.qml"); }

    // Overrides from VisualMissionItem

    bool            dirty                   (void) const final { return _dirty; }
    bool            isSimpleItem            (void) const final { return false; }
    bool            isStandaloneCoordinate  (void) const final { return false; }
    bool            specifiesCoordinate     (void) const final;
73
    bool            specifiesAltitudeOnly   (void) const final { return false; }
74 75 76
    QString         commandDescription      (void) const final { return "Mission Settings"; }
    QString         commandName             (void) const final { return "Mission Settings"; }
    QString         abbreviation            (void) const final { return "H"; }
77 78
    QGeoCoordinate  coordinate              (void) const final { return _plannedHomePositionCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _plannedHomePositionCoordinate; }
79
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
80 81
    double          specifiedFlightSpeed    (void) final;
    double          specifiedGimbalYaw      (void) final;
82
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
83 84 85 86 87 88 89 90

    bool coordinateHasRelativeAltitude      (void) const final { return true; }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return true; }
    bool exitCoordinateSameAsEntry          (void) const final { return true; }

    void setDirty           (bool dirty) final;
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
91
    void save               (QJsonArray&  missionItems) final;
92 93 94 95

    static const char* jsonComplexItemTypeValue;

signals:
DonLakeFlyer's avatar
DonLakeFlyer committed
96
    void specifyMissionFlightSpeedChanged(bool specifyMissionFlightSpeed);
97 98

private slots:
DonLakeFlyer's avatar
DonLakeFlyer committed
99 100 101
    void _setDirtyAndUpdateLastSequenceNumber   (void);
    void _setDirty                              (void);
    void _cameraSectionDirtyChanged             (bool dirty);
102
    void _updateAltitudeInCoordinate            (QVariant value);
103 104

private:
105
    bool            _specifyMissionFlightSpeed;
106
    QGeoCoordinate  _plannedHomePositionCoordinate;     // Does not include altitde
107 108 109 110
    Fact            _plannedHomePositionAltitudeFact;
    Fact            _missionFlightSpeedFact;
    Fact            _missionEndActionFact;
    CameraSection   _cameraSection;
111 112 113 114 115 116 117 118 119 120 121 122

    int     _sequenceNumber;
    bool    _dirty;

    static QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _plannedHomePositionAltitudeName;
    static const char* _missionFlightSpeedName;
    static const char* _missionEndActionName;
};

#endif