SimpleMissionItem.h 10.5 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * 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
#include "QGroundControlQmlGlobal.h"
20

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

30 31 32 33 34
    ~SimpleMissionItem();

    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
35 36
    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
37
    Q_PROPERTY(QGroundControlQmlGlobal::AltitudeMode altitudeMode READ altitudeMode WRITE setAltitudeMode       NOTIFY altitudeModeChanged)
38
    Q_PROPERTY(Fact*            amslAltAboveTerrain     READ amslAltAboveTerrain                                CONSTANT)                           ///< Actual AMSL altitude for item if altitudeMode == AltitudeAboveTerrain
39
    Q_PROPERTY(int              command                 READ command                WRITE setCommand            NOTIFY commandChanged)
40
    Q_PROPERTY(bool             supportsTerrainFrame    READ supportsTerrainFrame                               NOTIFY supportsTerrainFrameChanged)
41

42
    /// Optional sections
43
    Q_PROPERTY(QObject*         speedSection            READ speedSection                                       NOTIFY speedSectionChanged)
44 45
    Q_PROPERTY(QObject*         cameraSection           READ cameraSection                                      NOTIFY cameraSectionChanged)

46
    // These properties are used to display the editing ui
47 48 49
    Q_PROPERTY(QmlObjectListModel*  comboboxFacts   READ comboboxFacts  CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  textFieldFacts  READ textFieldFacts CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  nanFacts        READ nanFacts       CONSTANT)
50

51 52 53
    /// This should be called before changing the command. It is needed if the command changes
    /// from an item which does not include a coordinate to an item which requires a coordinate.
    /// It uses this value to set that new coordinate.
DonLakeFlyer's avatar
DonLakeFlyer committed
54
    Q_INVOKABLE void setMapCenterHintForCommandChange(QGeoCoordinate mapCenter) { _mapCenterHint = mapCenter; }
55

56 57 58 59
    /// 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
60
    /// @return true: section found, scanIndex updated
61
    bool scanForSections(QmlObjectListModel* visualItems, int scanIndex, Vehicle* vehicle);
62

63 64 65
    // Property accesors
    
    QString         category            (void) const;
66 67
    int             command             (void) const { return _missionItem._commandFact.cookedValue().toInt(); }
    MAV_CMD         mavCommand          (void) const { return static_cast<MAV_CMD>(command()); }
68 69
    bool            friendlyEditAllowed (void) const;
    bool            rawEdit             (void) const;
70
    bool            specifiesAltitude   (void) const;
71
    QGroundControlQmlGlobal::AltitudeMode altitudeMode(void) const { return _altitudeMode; }
72 73
    Fact*           altitude            (void) { return &_altitudeFact; }
    Fact*           amslAltAboveTerrain (void) { return &_amslAltAboveTerrainFact; }
74
    bool            supportsTerrainFrame(void) const { return _vehicle->supportsTerrainFrame(); }
75

76
    CameraSection*  cameraSection       (void) { return _cameraSection; }
77
    SpeedSection*   speedSection        (void) { return _speedSection; }
78

79 80 81
    QmlObjectListModel* textFieldFacts  (void) { return &_textFieldFacts; }
    QmlObjectListModel* nanFacts        (void) { return &_nanFacts; }
    QmlObjectListModel* comboboxFacts   (void) { return &_comboboxFacts; }
82 83

    void setRawEdit(bool rawEdit);
84
    void setAltitudeMode(QGroundControlQmlGlobal::AltitudeMode altitudeMode);
85 86 87
    
    void setCommandByIndex(int index);

88
    void setCommand(int command);
89 90 91 92 93 94

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

95 96
    virtual bool load(QTextStream &loadStream);
    virtual bool load(const QJsonObject& json, int sequenceNumber, QString& errorString);
97 98

    MissionItem& missionItem(void) { return _missionItem; }
99
    const MissionItem& missionItem(void) const { return _missionItem; }
100 101

    // Overrides from VisualMissionItem
102
    bool            dirty                   (void) const override { return _dirty; }
103 104 105
    bool            isSimpleItem            (void) const final { return true; }
    bool            isStandaloneCoordinate  (void) const final;
    bool            specifiesCoordinate     (void) const final;
106
    bool            specifiesAltitudeOnly   (void) const final;
107 108
    QString         commandDescription      (void) const final;
    QString         commandName             (void) const final;
109
    QString         abbreviation            (void) const final;
110 111
    QGeoCoordinate  coordinate              (void) const final { return _missionItem.coordinate(); }
    QGeoCoordinate  exitCoordinate          (void) const final { return coordinate(); }
112
    int             sequenceNumber          (void) const final { return _missionItem.sequenceNumber(); }
113 114 115
    double          specifiedFlightSpeed    (void) override;
    double          specifiedGimbalYaw      (void) override;
    double          specifiedGimbalPitch    (void) override;
116
    double          specifiedVehicleYaw     (void) override;
117
    QString         mapVisualQML            (void) const override { return QStringLiteral("SimpleItemMapVisual.qml"); }
118
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
119
    void            applyNewAltitude        (double newAltitude) final;
120
    void            setMissionFlightStatus  (MissionController::MissionFlightStatus_t& missionFlightStatus) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
121
    ReadyForSaveState readyForSaveState     (void) const final;
122
    double          additionalTimeDelay     (void) const final;
123 124 125 126 127 128

    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;
129
    void setCoordinate      (const QGeoCoordinate& coordinate) override;
130
    void setSequenceNumber  (int sequenceNumber) final;
131 132
    int  lastSequenceNumber (void) const final;
    void save               (QJsonArray&  missionItems) final;
133 134 135 136 137 138

signals:
    void commandChanged             (int command);
    void friendlyEditAllowedChanged (bool friendlyEditAllowed);
    void headingDegreesChanged      (double heading);
    void rawEditChanged             (bool rawEdit);
139
    void cameraSectionChanged       (QObject* cameraSection);
140
    void speedSectionChanged        (QObject* cameraSection);
141
    void altitudeModeChanged        (void);
142
    void supportsTerrainFrameChanged(void);
143

144
private slots:
145 146 147 148 149 150 151 152 153 154 155 156
    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);
    void _possibleAdditionalTimeDelayChanged(void);
157
    void _setDefaultsForCommand             (void);
158
    void _possibleVehicleYawChanged   (void);
159

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

167 168 169 170
    MissionItem     _missionItem;
    bool            _rawEdit;
    bool            _dirty;
    bool            _ignoreDirtyChangeSignals;
171
    QGeoCoordinate  _mapCenterHint;
172

173
    SpeedSection*   _speedSection;
174 175
    CameraSection* _cameraSection;

176 177
    MissionCommandTree* _commandTree;

178 179
    Fact                _supportedCommandFact;

180 181 182
    QGroundControlQmlGlobal::AltitudeMode   _altitudeMode;
    Fact                                    _altitudeFact;
    Fact                                    _amslAltAboveTerrainFact;
183 184 185 186

    QmlObjectListModel  _textFieldFacts;
    QmlObjectListModel  _nanFacts;
    QmlObjectListModel  _comboboxFacts;
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
    
    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;

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

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

#endif