TransectStyleComplexItem.h 11.9 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 10 11 12 13 14 15 16 17 18
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include "ComplexMissionItem.h"
#include "MissionItem.h"
#include "SettingsFact.h"
#include "QGCLoggingCategory.h"
#include "QGCMapPolyline.h"
#include "QGCMapPolygon.h"
#include "CameraCalc.h"
19
#include "TerrainQuery.h"
20 21 22 23 24 25 26 27

Q_DECLARE_LOGGING_CATEGORY(TransectStyleComplexItemLog)

class TransectStyleComplexItem : public ComplexMissionItem
{
    Q_OBJECT

public:
28
    TransectStyleComplexItem(Vehicle* vehicle, bool flyView, QString settignsGroup, QObject* parent);
29

30 31 32 33 34 35 36 37 38 39 40
    Q_PROPERTY(QGCMapPolygon*   surveyAreaPolygon           READ surveyAreaPolygon                                  CONSTANT)
    Q_PROPERTY(CameraCalc*      cameraCalc                  READ cameraCalc                                         CONSTANT)
    Q_PROPERTY(Fact*            turnAroundDistance          READ turnAroundDistance                                 CONSTANT)
    Q_PROPERTY(Fact*            cameraTriggerInTurnAround   READ cameraTriggerInTurnAround                          CONSTANT)
    Q_PROPERTY(Fact*            hoverAndCapture             READ hoverAndCapture                                    CONSTANT)
    Q_PROPERTY(Fact*            refly90Degrees              READ refly90Degrees                                     CONSTANT)

    Q_PROPERTY(int              cameraShots                 READ cameraShots                                        NOTIFY cameraShotsChanged)
    Q_PROPERTY(double           timeBetweenShots            READ timeBetweenShots                                   NOTIFY timeBetweenShotsChanged)
    Q_PROPERTY(double           coveredArea                 READ coveredArea                                        NOTIFY coveredAreaChanged)
    Q_PROPERTY(bool             hoverAndCaptureAllowed      READ hoverAndCaptureAllowed                             CONSTANT)
41
    Q_PROPERTY(QVariantList     visualTransectPoints        READ visualTransectPoints                               NOTIFY visualTransectPointsChanged)
42 43 44 45 46

    Q_PROPERTY(bool             followTerrain               READ followTerrain              WRITE setFollowTerrain  NOTIFY followTerrainChanged)
    Q_PROPERTY(Fact*            terrainAdjustTolerance      READ terrainAdjustTolerance                             CONSTANT)
    Q_PROPERTY(Fact*            terrainAdjustMaxDescentRate READ terrainAdjustMaxDescentRate                        CONSTANT)
    Q_PROPERTY(Fact*            terrainAdjustMaxClimbRate   READ terrainAdjustMaxClimbRate                          CONSTANT)
47 48 49

    QGCMapPolygon*  surveyAreaPolygon   (void) { return &_surveyAreaPolygon; }
    CameraCalc*     cameraCalc          (void) { return &_cameraCalc; }
50
    QVariantList    visualTransectPoints(void) { return _visualTransectPoints; }
51

52 53 54 55 56
    Fact* turnAroundDistance            (void) { return &_turnAroundDistanceFact; }
    Fact* cameraTriggerInTurnAround     (void) { return &_cameraTriggerInTurnAroundFact; }
    Fact* hoverAndCapture               (void) { return &_hoverAndCaptureFact; }
    Fact* refly90Degrees                (void) { return &_refly90DegreesFact; }
    Fact* terrainAdjustTolerance        (void) { return &_terrainAdjustToleranceFact; }
Don Gagne's avatar
Don Gagne committed
57 58
    Fact* terrainAdjustMaxDescentRate   (void) { return &_terrainAdjustMaxDescentRateFact; }
    Fact* terrainAdjustMaxClimbRate     (void) { return &_terrainAdjustMaxClimbRateFact; }
59

DonLakeFlyer's avatar
DonLakeFlyer committed
60 61
    const Fact* hoverAndCapture         (void) const { return &_hoverAndCaptureFact; }

62 63 64
    int             cameraShots             (void) const { return _cameraShots; }
    double          coveredArea             (void) const;
    bool            hoverAndCaptureAllowed  (void) const;
65 66
    bool            followTerrain           (void) const { return _followTerrain; }

67 68
    virtual double  timeBetweenShots        (void) { return 0; } // Most be overridden. Implementation here is needed for unit testing.

69
    void setFollowTerrain(bool followTerrain);
70

DonLakeFlyer's avatar
DonLakeFlyer committed
71 72 73 74
    double  triggerDistance         (void) const { return _cameraCalc.adjustedFootprintFrontal()->rawValue().toDouble(); }
    bool    hoverAndCaptureEnabled  (void) const { return hoverAndCapture()->rawValue().toBool(); }
    bool    triggerCamera           (void) const { return triggerDistance() != 0; }

75 76
    // Overrides from ComplexMissionItem

77 78 79
    int                 lastSequenceNumber  (void) const final;
    QString             mapVisualQML        (void) const override = 0;
    bool                load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) override = 0;
80

81
    double          complexDistance     (void) const final { return _complexDistance; }
82 83 84 85
    double          greatestDistanceTo  (const QGeoCoordinate &other) const final;

    // Overrides from VisualMissionItem

86
    void            save                    (QJsonArray&  planItems) override = 0;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    bool            specifiesCoordinate     (void) const override = 0;
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) override = 0;
    void            applyNewAltitude        (double newAltitude) override = 0;

    bool            dirty                   (void) const final { return _dirty; }
    bool            isSimpleItem            (void) const final { return false; }
    bool            isStandaloneCoordinate  (void) const final { return false; }
    bool            specifiesAltitudeOnly   (void) const final { return false; }
    QGeoCoordinate  coordinate              (void) const final { return _coordinate; }
    QGeoCoordinate  exitCoordinate          (void) const final { return _exitCoordinate; }
    int             sequenceNumber          (void) const final { return _sequenceNumber; }
    double          specifiedFlightSpeed    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalYaw      (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalPitch    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    void            setMissionFlightStatus  (MissionController::MissionFlightStatus_t& missionFlightStatus) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
102
    ReadyForSaveState readyForSaveState     (void) const override;
103 104 105
    QString         commandDescription      (void) const override { return tr("Transect"); }
    QString         commandName             (void) const override { return tr("Transect"); }
    QString         abbreviation            (void) const override { return tr("T"); }
106

107 108
    bool coordinateHasRelativeAltitude      (void) const final;
    bool exitCoordinateHasRelativeAltitude  (void) const final;
109 110 111 112 113 114 115 116 117 118 119
    bool exitCoordinateSameAsEntry          (void) const final { return false; }

    void            setDirty                (bool dirty) final;
    void            setCoordinate           (const QGeoCoordinate& coordinate) final { Q_UNUSED(coordinate); }
    void            setSequenceNumber       (int sequenceNumber) final;

    static const char* turnAroundDistanceName;
    static const char* turnAroundDistanceMultiRotorName;
    static const char* cameraTriggerInTurnAroundName;
    static const char* hoverAndCaptureName;
    static const char* refly90DegreesName;
120 121 122
    static const char* terrainAdjustToleranceName;
    static const char* terrainAdjustMaxClimbRateName;
    static const char* terrainAdjustMaxDescentRateName;
123 124 125 126

signals:
    void cameraShotsChanged             (void);
    void timeBetweenShotsChanged        (void);
127
    void visualTransectPointsChanged    (void);
128
    void coveredAreaChanged             (void);
129
    void followTerrainChanged           (bool followTerrain);
130 131 132

protected slots:
    void _setDirty                          (void);
133
    void _setIfDirty                        (bool dirty);
134
    void _updateCoordinateAltitudes         (void);
135
    void _polyPathTerrainData               (bool success, const QList<TerrainPathQuery::PathHeightInfo_t>& rgPathHeightInfo);
136
    void _rebuildTransects                  (void);
137 138

protected:
139 140 141 142
    virtual void _rebuildTransectsPhase1    (void) = 0; ///< Rebuilds the _transects array
    virtual void _recalcComplexDistance     (void) = 0;
    virtual void _recalcCameraShots         (void) = 0;

143
    void    _save                           (QJsonObject& saveObject);
Don Gagne's avatar
Don Gagne committed
144
    bool    _load                           (const QJsonObject& complexObject, bool forPresets, QString& errorString);
145 146 147 148 149
    void    _setExitCoordinate              (const QGeoCoordinate& coordinate);
    void    _setCameraShots                 (int cameraShots);
    double  _triggerDistance                (void) const;
    bool    _hasTurnaround                  (void) const;
    double  _turnaroundDistance             (void) const;
150 151 152 153 154

    int                 _sequenceNumber;
    QGeoCoordinate      _coordinate;
    QGeoCoordinate      _exitCoordinate;
    QGCMapPolygon       _surveyAreaPolygon;
155

156
    enum CoordType {
DonLakeFlyer's avatar
DonLakeFlyer committed
157 158 159 160 161
        CoordTypeInterior,              ///< Interior waypoint for flight path only
        CoordTypeInteriorHoverTrigger,  ///< Interior waypoint for hover and capture trigger
        CoordTypeInteriorTerrainAdded,  ///< Interior waypoint added for terrain
        CoordTypeSurveyEdge,            ///< Waypoint at edge of survey polygon
        CoordTypeTurnaround             ///< Waypoint outside of survey polygon for turnaround
162 163 164 165 166 167 168 169 170 171 172 173
    };

    typedef struct {
        QGeoCoordinate  coord;
        CoordType       coordType;
    } CoordInfo_t;

    QVariantList                                        _visualTransectPoints;
    QList<QList<CoordInfo_t>>                           _transects;
    QList<QList<TerrainPathQuery::PathHeightInfo_t>>    _transectsPathHeightInfo;
    TerrainPolyPathQuery*                               _terrainPolyPathQuery;
    QTimer                                              _terrainQueryTimer;
174

175
    bool            _ignoreRecalc;
176
    double          _complexDistance;
177 178 179 180
    int             _cameraShots;
    double          _timeBetweenShots;
    double          _cruiseSpeed;
    CameraCalc      _cameraCalc;
181
    bool            _followTerrain;
182

183 184 185
    QObject*            _loadedMissionItemsParent;	///< Parent for all items in _loadedMissionItems for simpler delete
    QList<MissionItem*> _loadedMissionItems;		///< Mission items loaded from plan file

186 187 188 189 190 191
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact _turnAroundDistanceFact;
    SettingsFact _cameraTriggerInTurnAroundFact;
    SettingsFact _hoverAndCaptureFact;
    SettingsFact _refly90DegreesFact;
192 193 194
    SettingsFact _terrainAdjustToleranceFact;
    SettingsFact _terrainAdjustMaxClimbRateFact;
    SettingsFact _terrainAdjustMaxDescentRateFact;
195 196

    static const char* _jsonCameraCalcKey;
197
    static const char* _jsonTransectStyleComplexItemKey;
DonLakeFlyer's avatar
DonLakeFlyer committed
198
    static const char* _jsonVisualTransectPointsKey;
199
    static const char* _jsonItemsKey;
200
    static const char* _jsonFollowTerrainKey;
201
    static const char* _jsonCameraShotsKey;
202

203 204
    static const int _terrainQueryTimeoutMsecs;

205
private slots:
206
    void _reallyQueryTransectsPathHeightInfo(void);
207
    void _followTerrainChanged              (bool followTerrain);
208
    void _handleHoverAndCaptureEnabled      (QVariant enabled);
209

210
private:
211 212 213 214 215 216 217
    void    _queryTransectsPathHeightInfo   (void);
    void    _adjustTransectsForTerrain      (void);
    void    _addInterstitialTerrainPoints   (QList<CoordInfo_t>& transect, const QList<TerrainPathQuery::PathHeightInfo_t>& transectPathHeightInfo);
    void    _adjustForMaxRates              (QList<CoordInfo_t>& transect);
    void    _adjustForTolerance             (QList<CoordInfo_t>& transect);
    double  _altitudeBetweenCoords          (const QGeoCoordinate& fromCoord, const QGeoCoordinate& toCoord, double percentTowardsTo);
    int     _maxPathHeight                  (const TerrainPathQuery::PathHeightInfo_t& pathHeightInfo, int fromIndex, int toIndex, double& maxHeight);
218
};