MissionSettingsItem.h 6.57 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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 23
class PlanMasterController;

24
class MissionSettingsItem : public ComplexMissionItem
25 26 27 28
{
    Q_OBJECT

public:
29
    MissionSettingsItem(PlanMasterController* masterController, bool flyView, QObject* parent);
30

31 32 33
    Q_PROPERTY(Fact*    plannedHomePositionAltitude READ plannedHomePositionAltitude                            CONSTANT)
    Q_PROPERTY(QObject* cameraSection               READ cameraSection                                          CONSTANT)
    Q_PROPERTY(QObject* speedSection                READ speedSection                                           CONSTANT)
DonLakeFlyer's avatar
DonLakeFlyer committed
34

35 36 37
    Fact*           plannedHomePositionAltitude (void) { return &_plannedHomePositionAltitudeFact; }
    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
    /// Called to update home position coordinate when it comes from a connected vehicle
    void setHomePositionFromVehicle(Vehicle* vehicle);
51

52 53
    // Called to set the initial home position. Vehicle can still update home position after this.
    void setInitialHomePosition(const QGeoCoordinate& coordinate);
54

55 56
    // Called to set the initial home position specified by user. Vehicle will no longer affect home position.
    void setInitialHomePositionFromUser(const QGeoCoordinate& coordinate);
57

58 59 60 61 62 63 64 65 66
    // Overrides from ComplexMissionItem
    QString patternName         (void) const final { return QString(); }
    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("SimpleItemMapVisual.qml"); }
    bool    isSingleItem        (void) const final { return true; }
    bool    terrainCollision    (void) const final { return false; }
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    // 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;
    bool            specifiesAltitudeOnly       (void) const final { return false; }
    QString         commandDescription          (void) const final { return "Mission Start"; }
    QString         commandName                 (void) const final { return "Mission Start"; }
    QString         abbreviation                (void) const final;
    QGeoCoordinate  coordinate                  (void) const final { return _plannedHomePositionCoordinate; } // Includes altitude
    QGeoCoordinate  exitCoordinate              (void) const final { return _plannedHomePositionCoordinate; }
    int             sequenceNumber              (void) const final { return _sequenceNumber; }
    double          specifiedGimbalYaw          (void) final;
    double          specifiedGimbalPitch        (void) final;
    void            appendMissionItems          (QList<MissionItem*>& items, QObject* missionItemParent) final;
    void            applyNewAltitude            (double /*newAltitude*/) final { /* no action */ }
    double          specifiedFlightSpeed        (void) final;
    double          additionalTimeDelay         (void) const final { return 0; }
    bool            exitCoordinateSameAsEntry   (void) const final { return true; }
    void            setDirty                    (bool dirty) final;
    void            setCoordinate               (const QGeoCoordinate& coordinate) final;   // Should only be called if the end user is moving
    void            setSequenceNumber           (int sequenceNumber) final;
    void            save                        (QJsonArray&  missionItems) final;
    double          amslEntryAlt                (void) const final { return _plannedHomePositionCoordinate.altitude(); }
    double          amslExitAlt                 (void) const final { return amslEntryAlt(); }
    double          minAMSLAltitude             (void) const final { return amslEntryAlt(); }
    double          maxAMSLAltitude             (void) const final { return amslEntryAlt(); }
95 96

signals:
97
    void specifyMissionFlightSpeedChanged   (bool specifyMissionFlightSpeed);
98 99

private slots:
DonLakeFlyer's avatar
DonLakeFlyer committed
100 101
    void _setDirtyAndUpdateLastSequenceNumber   (void);
    void _setDirty                              (void);
102
    void _sectionDirtyChanged                   (bool dirty);
103
    void _updateAltitudeInCoordinate            (QVariant value);
104
    void _setHomeAltFromTerrain                 (double terrainAltitude);
105 106
    void _setCoordinateWorker                   (const QGeoCoordinate& coordinate);
    void _updateHomePosition                    (const QGeoCoordinate& homePosition);
107 108

private:
109
    Vehicle*        _managerVehicle =                   nullptr;
110
    QGeoCoordinate  _plannedHomePositionCoordinate;     // Does not include altitude
111
    Fact            _plannedHomePositionAltitudeFact;
112 113 114
    int             _sequenceNumber =                   0;
    bool            _plannedHomePositionFromVehicle =   false;
    bool            _plannedHomePositionMovedByUser =   false;
115
    CameraSection   _cameraSection;
116
    SpeedSection    _speedSection;
117 118 119 120 121 122 123

    static QMap<QString, FactMetaData*> _metaDataMap;

    static const char* _plannedHomePositionAltitudeName;
};

#endif