MissionSettingsItem.h 5.2 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
#include "SpeedSection.h"
19 20 21

Q_DECLARE_LOGGING_CATEGORY(MissionSettingsComplexItemLog)

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

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

DonLakeFlyer's avatar
DonLakeFlyer committed
29
    Q_PROPERTY(Fact*    plannedHomePositionAltitude READ plannedHomePositionAltitude                                        CONSTANT)
30
    Q_PROPERTY(bool     missionEndRTL               MEMBER _missionEndRTL                                                   NOTIFY missionEndRTLChanged)
DonLakeFlyer's avatar
DonLakeFlyer committed
31
    Q_PROPERTY(QObject* cameraSection               READ cameraSection                                                      CONSTANT)
32
    Q_PROPERTY(QObject* speedSection                READ speedSection                                                       CONSTANT)
DonLakeFlyer's avatar
DonLakeFlyer committed
33

34 35
    Fact*   plannedHomePositionAltitude (void) { return &_plannedHomePositionAltitudeFact; }

36 37
    CameraSection* cameraSection(void) { return &_cameraSection; }
    SpeedSection* speedSection(void) { return &_speedSection; }
38

39
    /// Scans the loaded items for settings items
40
    bool scanForMissionSettings(QmlObjectListModel* visualItems, int scanIndex);
41 42 43 44 45 46 47

    /// 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);
48 49 50 51 52 53 54

    // 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;
DonLakeFlyer's avatar
DonLakeFlyer committed
55
    QString             mapVisualQML        (void) const final { return QStringLiteral("SimpleItemMapVisual.qml"); }
56 57 58 59 60 61 62

    // 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;
63
    bool            specifiesAltitudeOnly   (void) const final { return false; }
64 65 66
    QString         commandDescription      (void) const final { return "Mission Settings"; }
    QString         commandName             (void) const final { return "Mission Settings"; }
    QString         abbreviation            (void) const final { return "H"; }
67 68
    QGeoCoordinate  coordinate              (void) const final { return _plannedHomePositionCoordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _plannedHomePositionCoordinate; }
69
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
DonLakeFlyer's avatar
DonLakeFlyer committed
70
    double          specifiedGimbalYaw      (void) final;
71
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
72
    void            applyNewAltitude        (double newAltitude) final { Q_UNUSED(newAltitude); /* no action */ }
73
    double          specifiedFlightSpeed    (void) final;
74 75 76 77 78 79 80 81

    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;
82
    void save               (QJsonArray&  missionItems) final;
83 84 85 86

    static const char* jsonComplexItemTypeValue;

signals:
87 88
    void specifyMissionFlightSpeedChanged   (bool specifyMissionFlightSpeed);
    void missionEndRTLChanged               (bool missionEndRTL);
89 90

private slots:
DonLakeFlyer's avatar
DonLakeFlyer committed
91 92
    void _setDirtyAndUpdateLastSequenceNumber   (void);
    void _setDirty                              (void);
93
    void _sectionDirtyChanged                   (bool dirty);
94
    void _updateAltitudeInCoordinate            (QVariant value);
95 96

private:
97
    QGeoCoordinate  _plannedHomePositionCoordinate;     // Does not include altitude
98
    Fact            _plannedHomePositionAltitudeFact;
99
    bool            _missionEndRTL;
100
    CameraSection   _cameraSection;
101
    SpeedSection    _speedSection;
102 103 104 105 106 107 108 109 110 111

    int     _sequenceNumber;
    bool    _dirty;

    static QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _plannedHomePositionAltitudeName;
};

#endif