TransectStyleComplexItem.h 11.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#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 28 29

Q_DECLARE_LOGGING_CATEGORY(TransectStyleComplexItemLog)

class TransectStyleComplexItem : public ComplexMissionItem
{
    Q_OBJECT

public:
    TransectStyleComplexItem(Vehicle* vehicle, QString settignsGroup, QObject* parent = NULL);

30 31 32 33 34 35 36 37 38 39 40 41
    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(double           cameraMinTriggerInterval    READ cameraMinTriggerInterval                           NOTIFY cameraMinTriggerIntervalChanged)
    Q_PROPERTY(bool             hoverAndCaptureAllowed      READ hoverAndCaptureAllowed                             CONSTANT)
42
    Q_PROPERTY(QVariantList     visualTransectPoints        READ visualTransectPoints                               NOTIFY visualTransectPointsChanged)
43 44 45 46 47

    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)
48 49 50

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

53 54 55 56 57 58 59
    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; }
    Fact* terrainAdjustMaxDescentRate   (void) { return &_terrainAdjustMaxClimbRateFact; }
    Fact* terrainAdjustMaxClimbRate     (void) { return &_terrainAdjustMaxDescentRateFact; }
60 61 62 63 64 65

    int             cameraShots             (void) const { return _cameraShots; }
    double          timeBetweenShots        (void);
    double          coveredArea             (void) const;
    double          cameraMinTriggerInterval(void) const { return _cameraMinTriggerInterval; }
    bool            hoverAndCaptureAllowed  (void) const;
66 67 68
    bool            followTerrain           (void) const { return _followTerrain; }

    void setFollowTerrain(bool followTerrain);
69 70 71

    // Overrides from ComplexMissionItem

72
    int             lastSequenceNumber  (void) const final;
73 74 75
    QString         mapVisualQML        (void) const override = 0;
    bool            load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) override = 0;

76
    double          complexDistance     (void) const final { return _complexDistance; }
77 78 79 80
    double          greatestDistanceTo  (const QGeoCoordinate &other) const final;

    // Overrides from VisualMissionItem

81
    void            save                    (QJsonArray&  planItems) override = 0;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    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; }
    QString         commandDescription      (void) const final { return tr("Corridor Scan"); }
    QString         commandName             (void) const final { return tr("Corridor Scan"); }
    QString         abbreviation            (void) const final { return "S"; }
    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;
100
    bool            readyForSave            (void) const override;
101 102 103 104 105 106 107 108 109 110 111 112 113 114

    bool coordinateHasRelativeAltitude      (void) const final { return true /*_altitudeRelative*/; }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return true /*_altitudeRelative*/; }
    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;
115 116 117
    static const char* terrainAdjustToleranceName;
    static const char* terrainAdjustMaxClimbRateName;
    static const char* terrainAdjustMaxDescentRateName;
118 119 120 121 122

signals:
    void cameraShotsChanged             (void);
    void timeBetweenShotsChanged        (void);
    void cameraMinTriggerIntervalChanged(double cameraMinTriggerInterval);
123
    void visualTransectPointsChanged    (void);
124
    void coveredAreaChanged             (void);
125
    void followTerrainChanged           (bool followTerrain);
126 127

protected slots:
128 129
    virtual void _rebuildTransectsPhase1    (void) = 0; ///< Rebuilds the _transects array
    virtual void _rebuildTransectsPhase2    (void) = 0; ///< Adjust values associated with _transects array
130 131

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

protected:
138 139 140 141 142 143 144
    void    _save                           (QJsonObject& saveObject);
    bool    _load                           (const QJsonObject& complexObject, QString& errorString);
    void    _setExitCoordinate              (const QGeoCoordinate& coordinate);
    void    _setCameraShots                 (int cameraShots);
    double  _triggerDistance                (void) const;
    bool    _hasTurnaround                  (void) const;
    double  _turnaroundDistance             (void) const;
145 146 147 148 149 150 151 152

    QString         _settingsGroup;
    int             _sequenceNumber;
    bool            _dirty;
    QGeoCoordinate  _coordinate;
    QGeoCoordinate  _exitCoordinate;
    QGCMapPolygon   _surveyAreaPolygon;

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    enum CoordType {
        CoordTypeInterior,
        CoordTypeInteriorTerrainAdded,
        CoordTypeSurveyEdge,
        CoordTypeTurnaround
    };

    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;
170

171
    bool            _ignoreRecalc;
172
    double          _complexDistance;
173 174 175 176 177
    int             _cameraShots;
    double          _timeBetweenShots;
    double          _cameraMinTriggerInterval;
    double          _cruiseSpeed;
    CameraCalc      _cameraCalc;
178
    bool            _followTerrain;
179

180 181 182
    QObject*            _loadedMissionItemsParent;	///< Parent for all items in _loadedMissionItems for simpler delete
    QList<MissionItem*> _loadedMissionItems;		///< Mission items loaded from plan file

183 184 185 186 187 188
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact _turnAroundDistanceFact;
    SettingsFact _cameraTriggerInTurnAroundFact;
    SettingsFact _hoverAndCaptureFact;
    SettingsFact _refly90DegreesFact;
189 190 191
    SettingsFact _terrainAdjustToleranceFact;
    SettingsFact _terrainAdjustMaxClimbRateFact;
    SettingsFact _terrainAdjustMaxDescentRateFact;
192 193

    static const char* _jsonCameraCalcKey;
194 195 196
    static const char* _jsonTransectStyleComplexItemKey;
    static const char* _jsonTransectPointsKey;
    static const char* _jsonItemsKey;
197
    static const char* _jsonFollowTerrainKey;
198

199 200
    static const int _terrainQueryTimeoutMsecs;

201
private slots:
202
    void _reallyQueryTransectsPathHeightInfo(void);
203

204
private:
205 206 207 208 209 210 211
    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);
212
};