MissionSettingsItem.h 6.89 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
    Q_PROPERTY(Fact*    missionName                 READ missionName                                                        CONSTANT)
36
    Q_PROPERTY(QString  loadedMissionDirectory      READ loadedMissionDirectory         WRITE setLoadedMissionDirectory     NOTIFY loadedMissionDirectoryChanged)
DonLakeFlyer's avatar
DonLakeFlyer committed
37 38 39 40 41 42 43 44
    Q_PROPERTY(bool     existingMission             READ existingMission                WRITE setExistingMission            NOTIFY existingMissionChanged)
    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)

    Fact*   missionName                 (void) { return &_missionNameFact; }
45 46 47
    Fact*   plannedHomePositionAltitude (void) { return &_plannedHomePositionAltitudeFact; }
    Fact*   missionFlightSpeed          (void) { return &_missionFlightSpeedFact; }
    Fact*   missionEndAction            (void) { return &_missionEndActionFact; }
DonLakeFlyer's avatar
DonLakeFlyer committed
48 49
    bool    specifyMissionFlightSpeed   (void) const { return _specifyMissionFlightSpeed; }
    bool    existingMission             (void) const { return _existingMission; }
50

51
    void setSpecifyMissionFlightSpeed(bool specifyMissionFlightSpeed);
DonLakeFlyer's avatar
DonLakeFlyer committed
52
    void setExistingMission(bool existingMission);
53
    QObject* cameraSection(void) { return &_cameraSection; }
54

55
    /// Scans the loaded items for settings items
56 57 58 59 60 61 62 63
    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);
64

65 66 67 68
    // Returns the directory the misiosn was loaded from. Empty string is laoded from normal savePath.
    QString loadedMissionDirectory(void) const { return _loadedMissionDirectory; }
    void setLoadedMissionDirectory(QString& loadedMissionDirectory);

69 70 71 72 73 74 75 76 77 78 79 80 81 82
    // 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;
83
    bool            specifiesAltitudeOnly   (void) const final { return false; }
84 85 86
    QString         commandDescription      (void) const final { return "Mission Settings"; }
    QString         commandName             (void) const final { return "Mission Settings"; }
    QString         abbreviation            (void) const final { return "H"; }
87 88
    QGeoCoordinate  coordinate              (void) const final { return _plannedHomePositionCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _plannedHomePositionCoordinate; }
89
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
90 91
    double          specifiedFlightSpeed    (void) final;
    double          specifiedGimbalYaw      (void) final;
92
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
93 94 95 96 97 98 99 100

    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;
101
    void save               (QJsonArray&  missionItems) final;
102 103 104 105

    static const char* jsonComplexItemTypeValue;

signals:
DonLakeFlyer's avatar
DonLakeFlyer committed
106 107
    void specifyMissionFlightSpeedChanged(bool specifyMissionFlightSpeed);
    void existingMissionChanged(bool existingMission);
108
    void loadedMissionDirectoryChanged(QString& loadedMissionDirectory);
109 110

private slots:
DonLakeFlyer's avatar
DonLakeFlyer committed
111 112 113
    void _setDirtyAndUpdateLastSequenceNumber   (void);
    void _setDirty                              (void);
    void _cameraSectionDirtyChanged             (bool dirty);
114
    void _updateAltitudeInCoordinate            (QVariant value);
115 116

private:
DonLakeFlyer's avatar
DonLakeFlyer committed
117
    bool            _existingMission;
118
    bool            _specifyMissionFlightSpeed;
119
    QGeoCoordinate  _plannedHomePositionCoordinate;     // Does not include altitde
DonLakeFlyer's avatar
DonLakeFlyer committed
120
    Fact            _missionNameFact;
121 122 123
    Fact            _plannedHomePositionAltitudeFact;
    Fact            _missionFlightSpeedFact;
    Fact            _missionEndActionFact;
124
    QString         _loadedMissionDirectory;
125
    CameraSection   _cameraSection;
126 127 128 129 130 131

    int     _sequenceNumber;
    bool    _dirty;

    static QMap<QString, FactMetaData*> _metaDataMap;

DonLakeFlyer's avatar
DonLakeFlyer committed
132
    static const char* _missionNameName;
133 134 135 136 137 138
    static const char* _plannedHomePositionAltitudeName;
    static const char* _missionFlightSpeedName;
    static const char* _missionEndActionName;
};

#endif