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

10 11 12 13

#ifndef SimpleMissionItem_H
#define SimpleMissionItem_H

14
#include "VisualMissionItem.h"
15
#include "MissionItem.h"
16
#include "MissionCommandTree.h"
17
#include "CameraSection.h"
18
#include "SpeedSection.h"
19

20 21
/// A SimpleMissionItem is used to represent a single MissionItem to the ui.
class SimpleMissionItem : public VisualMissionItem
22 23 24 25
{
    Q_OBJECT
    
public:
26 27 28
    SimpleMissionItem(Vehicle* vehicle, bool flyView, QObject* parent);
    SimpleMissionItem(Vehicle* vehicle, bool flyView, const MissionItem& missionItem, QObject* parent);
    SimpleMissionItem(const SimpleMissionItem& other, bool flyView, QObject* parent);
29

30 31
    ~SimpleMissionItem();

32
    enum AltitudeMode {
33 34 35 36
        AltitudeRelative,       // MAV_FRAME_GLOBAL_RELATIVE_ALT
        AltitudeAbsolute,       // MAV_FRAME_GLOBAL
        AltitudeAboveTerrain,   // Absolute altitude above terrain calculated from terrain data
        AltitudeTerrainFrame    // MAV_FRAME_GLOBAL_TERRAIN_ALT
37 38 39
    };

    Q_ENUM(AltitudeMode)
40 41 42 43
    
    Q_PROPERTY(QString          category                READ category                                           NOTIFY commandChanged)
    Q_PROPERTY(bool             friendlyEditAllowed     READ friendlyEditAllowed                                NOTIFY friendlyEditAllowedChanged)
    Q_PROPERTY(bool             rawEdit                 READ rawEdit                WRITE setRawEdit            NOTIFY rawEditChanged)              ///< true: raw item editing with all params
44 45 46 47
    Q_PROPERTY(bool             specifiesAltitude       READ specifiesAltitude                                  NOTIFY commandChanged)
    Q_PROPERTY(Fact*            altitude                READ altitude                                           CONSTANT)                           ///< Altitude as specified by altitudeMode. Not necessarily true mission item altitude
    Q_PROPERTY(AltitudeMode     altitudeMode            READ altitudeMode           WRITE setAltitudeMode       NOTIFY altitudeModeChanged)
    Q_PROPERTY(Fact*            amslAltAboveTerrain     READ amslAltAboveTerrain                                CONSTANT)                           ///< Actual AMSL altitude for item if altitudeMode == AltitudeAboveTerrain
48
    Q_PROPERTY(int              command                 READ command                WRITE setCommand            NOTIFY commandChanged)
49
    Q_PROPERTY(bool             supportsTerrainFrame    READ supportsTerrainFrame                               NOTIFY supportsTerrainFrameChanged)
50

51
    /// Optional sections
52
    Q_PROPERTY(QObject*         speedSection            READ speedSection                                       NOTIFY speedSectionChanged)
53 54
    Q_PROPERTY(QObject*         cameraSection           READ cameraSection                                      NOTIFY cameraSectionChanged)

55
    // These properties are used to display the editing ui
56 57 58
    Q_PROPERTY(QmlObjectListModel*  comboboxFacts   READ comboboxFacts  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  textFieldFacts  READ textFieldFacts CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  nanFacts        READ nanFacts       CONSTANT)
59

60 61 62 63
    /// Scans the loaded items for additional section settings
    ///     @param visualItems List of all visual items
    ///     @param scanIndex Index to start scanning from
    ///     @param vehicle Vehicle associated with this mission
64
    /// @return true: section found, scanIndex updated
65
    bool scanForSections(QmlObjectListModel* visualItems, int scanIndex, Vehicle* vehicle);
66

67 68 69
    // Property accesors
    
    QString         category            (void) const;
70
    int             command(void) const { return _missionItem._commandFact.cookedValue().toInt(); }
71 72
    bool            friendlyEditAllowed (void) const;
    bool            rawEdit             (void) const;
73 74 75 76
    bool            specifiesAltitude   (void) const;
    AltitudeMode    altitudeMode        (void) const { return _altitudeMode; }
    Fact*           altitude            (void) { return &_altitudeFact; }
    Fact*           amslAltAboveTerrain (void) { return &_amslAltAboveTerrainFact; }
77
    bool            supportsTerrainFrame(void) const { return _vehicle->supportsTerrainFrame(); }
78

79
    CameraSection*  cameraSection       (void) { return _cameraSection; }
80
    SpeedSection*   speedSection        (void) { return _speedSection; }
81

82 83 84
    QmlObjectListModel* textFieldFacts  (void) { return &_textFieldFacts; }
    QmlObjectListModel* nanFacts        (void) { return &_nanFacts; }
    QmlObjectListModel* comboboxFacts   (void) { return &_comboboxFacts; }
85 86

    void setRawEdit(bool rawEdit);
87
    void setAltitudeMode(AltitudeMode altitudeMode);
88 89 90
    
    void setCommandByIndex(int index);

91
    void setCommand(int command);
92 93 94 95 96 97 98

    void setAltDifference   (double altDifference);
    void setAltPercent      (double altPercent);
    void setAzimuth         (double azimuth);
    void setDistance        (double distance);

    bool load(QTextStream &loadStream);
Don Gagne's avatar
Don Gagne committed
99
    bool load(const QJsonObject& json, int sequenceNumber, QString& errorString);
100 101

    MissionItem& missionItem(void) { return _missionItem; }
102
    const MissionItem& missionItem(void) const { return _missionItem; }
103 104 105 106 107 108 109

    // Overrides from VisualMissionItem

    bool            dirty                   (void) const final { return _dirty; }
    bool            isSimpleItem            (void) const final { return true; }
    bool            isStandaloneCoordinate  (void) const final;
    bool            specifiesCoordinate     (void) const final;
110
    bool            specifiesAltitudeOnly   (void) const final;
111 112
    QString         commandDescription      (void) const final;
    QString         commandName             (void) const final;
113
    QString         abbreviation            (void) const final;
114 115
    QGeoCoordinate  coordinate              (void) const final { return _missionItem.coordinate(); }
    QGeoCoordinate  exitCoordinate          (void) const final { return coordinate(); }
116
    int             sequenceNumber          (void) const final { return _missionItem.sequenceNumber(); }
DonLakeFlyer's avatar
DonLakeFlyer committed
117 118
    double          specifiedFlightSpeed    (void) final;
    double          specifiedGimbalYaw      (void) final;
119
    double          specifiedGimbalPitch    (void) final;
120
    QString         mapVisualQML            (void) const final { return QStringLiteral("SimpleItemMapVisual.qml"); }
121
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
122
    void            applyNewAltitude        (double newAltitude) final;
123
    void            setMissionFlightStatus  (MissionController::MissionFlightStatus_t& missionFlightStatus) final;
124
    bool            readyForSave            (void) const final;
125 126 127 128 129 130

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

    void setDirty           (bool dirty) final;
131 132
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
133 134
    int  lastSequenceNumber (void) const final;
    void save               (QJsonArray&  missionItems) final;
135 136 137 138 139 140 141 142 143

public slots:
    void setDefaultsForCommand(void);

signals:
    void commandChanged             (int command);
    void friendlyEditAllowedChanged (bool friendlyEditAllowed);
    void headingDegreesChanged      (double heading);
    void rawEditChanged             (bool rawEdit);
144
    void cameraSectionChanged       (QObject* cameraSection);
145
    void speedSectionChanged        (QObject* cameraSection);
146
    void altitudeModeChanged        (void);
147
    void supportsTerrainFrameChanged(void);
148

149
private slots:
150 151 152 153 154 155 156 157 158 159 160
    void _setDirty                      (void);
    void _sectionDirtyChanged           (bool dirty);
    void _sendCommandChanged            (void);
    void _sendCoordinateChanged         (void);
    void _sendFriendlyEditAllowedChanged(void);
    void _altitudeChanged               (void);
    void _altitudeModeChanged           (void);
    void _terrainAltChanged             (void);
    void _updateLastSequenceNumber      (void);
    void _rebuildFacts                  (void);
    void _rebuildTextFieldFacts         (void);
161

162
private:
163 164
    void _connectSignals        (void);
    void _setupMetaData         (void);
165
    void _updateOptionalSections(void);
166 167
    void _rebuildNaNFacts       (void);
    void _rebuildComboBoxFacts  (void);
168

169 170 171 172
    MissionItem     _missionItem;
    bool            _rawEdit;
    bool            _dirty;
    bool            _ignoreDirtyChangeSignals;
173

174
    SpeedSection*   _speedSection;
175 176
    CameraSection* _cameraSection;

177 178
    MissionCommandTree* _commandTree;

179 180 181 182 183
    Fact                _supportedCommandFact;

    AltitudeMode    _altitudeMode;
    Fact            _altitudeFact;
    Fact            _amslAltAboveTerrainFact;
184 185 186 187

    QmlObjectListModel  _textFieldFacts;
    QmlObjectListModel  _nanFacts;
    QmlObjectListModel  _comboboxFacts;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    
    static FactMetaData*    _altitudeMetaData;
    static FactMetaData*    _commandMetaData;
    static FactMetaData*    _defaultParamMetaData;
    static FactMetaData*    _frameMetaData;
    static FactMetaData*    _latitudeMetaData;
    static FactMetaData*    _longitudeMetaData;

    FactMetaData    _param1MetaData;
    FactMetaData    _param2MetaData;
    FactMetaData    _param3MetaData;
    FactMetaData    _param4MetaData;
    FactMetaData    _param5MetaData;
    FactMetaData    _param6MetaData;
    FactMetaData    _param7MetaData;

204 205 206 207 208
    bool _syncingHeadingDegreesAndParam4;   ///< true: already in a sync signal, prevents signal loop

    static const char* _jsonAltitudeModeKey;
    static const char* _jsonAltitudeKey;
    static const char* _jsonAMSLAltAboveTerrainKey;
209 210 211
};

#endif