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


#ifndef SurveyMissionItem_H
#define SurveyMissionItem_H

#include "ComplexMissionItem.h"
#include "MissionItem.h"
16
#include "SettingsFact.h"
17 18 19 20 21 22 23 24 25 26 27
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(SurveyMissionItemLog)

class SurveyMissionItem : public ComplexMissionItem
{
    Q_OBJECT

public:
    SurveyMissionItem(Vehicle* vehicle, QObject* parent = NULL);

Don Gagne's avatar
Don Gagne committed
28
    Q_PROPERTY(Fact*                gridAltitude                READ gridAltitude                   CONSTANT)
29
    Q_PROPERTY(Fact*                gridAltitudeRelative        READ gridAltitudeRelative           CONSTANT)
Don Gagne's avatar
Don Gagne committed
30 31 32
    Q_PROPERTY(Fact*                gridAngle                   READ gridAngle                      CONSTANT)
    Q_PROPERTY(Fact*                gridSpacing                 READ gridSpacing                    CONSTANT)
    Q_PROPERTY(Fact*                turnaroundDist              READ turnaroundDist                 CONSTANT)
33
    Q_PROPERTY(Fact*                cameraTrigger               READ cameraTrigger                  CONSTANT)
Don Gagne's avatar
Don Gagne committed
34
    Q_PROPERTY(Fact*                cameraTriggerDistance       READ cameraTriggerDistance          CONSTANT)
35 36
    Q_PROPERTY(Fact*                cameraTriggerInTurnaround   READ cameraTriggerInTurnaround      CONSTANT)
    Q_PROPERTY(Fact*                hoverAndCapture             READ hoverAndCapture                CONSTANT)
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41 42 43 44
    Q_PROPERTY(Fact*                groundResolution            READ groundResolution               CONSTANT)
    Q_PROPERTY(Fact*                frontalOverlap              READ frontalOverlap                 CONSTANT)
    Q_PROPERTY(Fact*                sideOverlap                 READ sideOverlap                    CONSTANT)
    Q_PROPERTY(Fact*                cameraSensorWidth           READ cameraSensorWidth              CONSTANT)
    Q_PROPERTY(Fact*                cameraSensorHeight          READ cameraSensorHeight             CONSTANT)
    Q_PROPERTY(Fact*                cameraResolutionWidth       READ cameraResolutionWidth          CONSTANT)
    Q_PROPERTY(Fact*                cameraResolutionHeight      READ cameraResolutionHeight         CONSTANT)
    Q_PROPERTY(Fact*                cameraFocalLength           READ cameraFocalLength              CONSTANT)
45 46 47 48 49
    Q_PROPERTY(Fact*                fixedValueIsAltitude        READ fixedValueIsAltitude           CONSTANT)
    Q_PROPERTY(Fact*                cameraOrientationLandscape  READ cameraOrientationLandscape     CONSTANT)
    Q_PROPERTY(Fact*                manualGrid                  READ manualGrid                     CONSTANT)
    Q_PROPERTY(Fact*                camera                      READ camera                         CONSTANT)

50
    Q_PROPERTY(bool                 cameraOrientationFixed      MEMBER _cameraOrientationFixed      NOTIFY cameraOrientationFixedChanged)
DonLakeFlyer's avatar
DonLakeFlyer committed
51
    Q_PROPERTY(bool                 hoverAndCaptureAllowed      READ hoverAndCaptureAllowed         CONSTANT)
52

53
    Q_PROPERTY(double               timeBetweenShots            READ timeBetweenShots               NOTIFY timeBetweenShotsChanged)
Don Gagne's avatar
Don Gagne committed
54 55 56 57
    Q_PROPERTY(QVariantList         polygonPath                 READ polygonPath                    NOTIFY polygonPathChanged)
    Q_PROPERTY(QVariantList         gridPoints                  READ gridPoints                     NOTIFY gridPointsChanged)
    Q_PROPERTY(int                  cameraShots                 READ cameraShots                    NOTIFY cameraShotsChanged)
    Q_PROPERTY(double               coveredArea                 READ coveredArea                    NOTIFY coveredAreaChanged)
58

59 60 61 62
    // The polygon vertices are also exposed as a list mode since MapItemView will only work with a QAbstractItemModel as
    // opposed to polygonPath which is a QVariantList.
    Q_PROPERTY(QmlObjectListModel*  polygonModel                READ polygonModel                   CONSTANT)

63 64 65
    Q_INVOKABLE void clearPolygon(void);
    Q_INVOKABLE void addPolygonCoordinate(const QGeoCoordinate coordinate);
    Q_INVOKABLE void adjustPolygonCoordinate(int vertexIndex, const QGeoCoordinate coordinate);
66 67 68 69 70 71 72
    Q_INVOKABLE void removePolygonVertex(int vertexIndex);

    // Splits the segment between vertextIndex and the next vertex in half
    Q_INVOKABLE void splitPolygonSegment(int vertexIndex);

    QVariantList        polygonPath (void) { return _polygonPath; }
    QmlObjectListModel* polygonModel(void) { return &_polygonModel; }
73

74
    QVariantList gridPoints (void) { return _simpleGridPoints; }
75

76
    Fact* manualGrid                (void) { return &_manualGridFact; }
Don Gagne's avatar
Don Gagne committed
77
    Fact* gridAltitude              (void) { return &_gridAltitudeFact; }
78
    Fact* gridAltitudeRelative      (void) { return &_gridAltitudeRelativeFact; }
Don Gagne's avatar
Don Gagne committed
79 80 81
    Fact* gridAngle                 (void) { return &_gridAngleFact; }
    Fact* gridSpacing               (void) { return &_gridSpacingFact; }
    Fact* turnaroundDist            (void) { return &_turnaroundDistFact; }
82
    Fact* cameraTrigger             (void) { return &_cameraTriggerFact; }
Don Gagne's avatar
Don Gagne committed
83
    Fact* cameraTriggerDistance     (void) { return &_cameraTriggerDistanceFact; }
84 85
    Fact* cameraTriggerInTurnaround (void) { return &_cameraTriggerInTurnaroundFact; }
    Fact* hoverAndCapture           (void) { return &_hoverAndCaptureFact; }
Don Gagne's avatar
Don Gagne committed
86 87 88 89 90 91 92 93
    Fact* groundResolution          (void) { return &_groundResolutionFact; }
    Fact* frontalOverlap            (void) { return &_frontalOverlapFact; }
    Fact* sideOverlap               (void) { return &_sideOverlapFact; }
    Fact* cameraSensorWidth         (void) { return &_cameraSensorWidthFact; }
    Fact* cameraSensorHeight        (void) { return &_cameraSensorHeightFact; }
    Fact* cameraResolutionWidth     (void) { return &_cameraResolutionWidthFact; }
    Fact* cameraResolutionHeight    (void) { return &_cameraResolutionHeightFact; }
    Fact* cameraFocalLength         (void) { return &_cameraFocalLengthFact; }
94 95 96
    Fact* cameraOrientationLandscape(void) { return &_cameraOrientationLandscapeFact; }
    Fact* fixedValueIsAltitude      (void) { return &_fixedValueIsAltitudeFact; }
    Fact* camera                    (void) { return &_cameraFact; }
97

Don Gagne's avatar
Don Gagne committed
98 99
    int     cameraShots(void) const;
    double  coveredArea(void) const { return _coveredArea; }
100
    double  timeBetweenShots(void) const;
DonLakeFlyer's avatar
DonLakeFlyer committed
101
    bool    hoverAndCaptureAllowed(void) const;
102 103 104 105 106

    // Overrides from ComplexMissionItem

    double              complexDistance     (void) const final { return _surveyDistance; }
    int                 lastSequenceNumber  (void) const final;
Don Gagne's avatar
Don Gagne committed
107
    bool                load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
108
    double              greatestDistanceTo  (const QGeoCoordinate &other) const final;
109
    QString             mapVisualQML        (void) const final { return QStringLiteral("SurveyMapVisual.qml"); }
110

111 112 113 114 115 116 117

    // 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;
118
    bool            specifiesAltitudeOnly   (void) const final { return false; }
119 120 121 122 123 124
    QString         commandDescription      (void) const final { return "Survey"; }
    QString         commandName             (void) const final { return "Survey"; }
    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; }
DonLakeFlyer's avatar
DonLakeFlyer committed
125 126
    double          specifiedFlightSpeed    (void) final { return std::numeric_limits<double>::quiet_NaN(); }
    double          specifiedGimbalYaw      (void) final { return std::numeric_limits<double>::quiet_NaN(); }
127
    void            appendMissionItems      (QList<MissionItem*>& items, QObject* missionItemParent) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
128
    void            setMissionFlightStatus  (MissionController::MissionFlightStatus_t& missionFlightStatus) final;
129

130 131
    bool coordinateHasRelativeAltitude      (void) const final { return _gridAltitudeRelativeFact.rawValue().toBool(); }
    bool exitCoordinateHasRelativeAltitude  (void) const final { return _gridAltitudeRelativeFact.rawValue().toBool(); }
132 133 134 135 136
    bool exitCoordinateSameAsEntry          (void) const final { return false; }

    void setDirty           (bool dirty) final;
    void setCoordinate      (const QGeoCoordinate& coordinate) final;
    void setSequenceNumber  (int sequenceNumber) final;
137
    void setTurnaroundDist  (double dist) { _turnaroundDistFact.setRawValue(dist); }
138
    void save               (QJsonArray&  missionItems) final;
139

Don Gagne's avatar
Don Gagne committed
140 141
    static const char* jsonComplexItemTypeValue;

142 143 144 145 146 147 148 149
    static const char* settingsGroup;
    static const char* manualGridName;
    static const char* gridAltitudeName;
    static const char* gridAltitudeRelativeName;
    static const char* gridAngleName;
    static const char* gridSpacingName;
    static const char* turnaroundDistName;
    static const char* cameraTriggerDistanceName;
150 151
    static const char* cameraTriggerInTurnaroundName;
    static const char* hoverAndCaptureName;
152 153 154 155 156 157 158 159 160 161 162 163 164
    static const char* groundResolutionName;
    static const char* frontalOverlapName;
    static const char* sideOverlapName;
    static const char* cameraSensorWidthName;
    static const char* cameraSensorHeightName;
    static const char* cameraResolutionWidthName;
    static const char* cameraResolutionHeightName;
    static const char* cameraFocalLengthName;
    static const char* cameraTriggerName;
    static const char* cameraOrientationLandscapeName;
    static const char* fixedValueIsAltitudeName;
    static const char* cameraName;

165
signals:
166 167 168 169 170 171 172 173
    void polygonPathChanged             (void);
    void gridPointsChanged              (void);
    void cameraShotsChanged             (int cameraShots);
    void coveredAreaChanged             (double coveredArea);
    void cameraValueChanged             (void);
    void gridTypeChanged                (QString gridType);
    void timeBetweenShotsChanged        (void);
    void cameraOrientationFixedChanged  (bool cameraOrientationFixed);
174 175

private slots:
176
    void _setDirty(void);
177 178

private:
179 180 181
    enum CameraTriggerCode {
        CameraTriggerNone,
        CameraTriggerOn,
DonLakeFlyer's avatar
DonLakeFlyer committed
182 183
        CameraTriggerOff,
        CameraTriggerHoverAndCapture
184 185
    };

186 187 188 189
    void _clear(void);
    void _setExitCoordinate(const QGeoCoordinate& coordinate);
    void _clearGrid(void);
    void _generateGrid(void);
190
    void _updateCoordinateAltitude(void);
DonLakeFlyer's avatar
DonLakeFlyer committed
191
    void _gridGenerator(const QList<QPointF>& polygonPoints, QList<QPointF>& simpleGridPoints, QList<QList<QPointF>>& transectSegments);
192 193 194 195 196 197 198
    QPointF _rotatePoint(const QPointF& point, const QPointF& origin, double angle);
    void _intersectLinesWithRect(const QList<QLineF>& lineList, const QRectF& boundRect, QList<QLineF>& resultLines);
    void _intersectLinesWithPolygon(const QList<QLineF>& lineList, const QPolygonF& polygon, QList<QLineF>& resultLines);
    void _adjustLineDirection(const QList<QLineF>& lineList, QList<QLineF>& resultLines);
    void _setSurveyDistance(double surveyDistance);
    void _setCameraShots(int cameraShots);
    void _setCoveredArea(double coveredArea);
Don Gagne's avatar
Don Gagne committed
199
    void _cameraValueChanged(void);
200
    int _appendWaypointToMission(QList<MissionItem*>& items, int seqNum, QGeoCoordinate& coord, CameraTriggerCode cameraTrigger, QObject* missionItemParent);
DonLakeFlyer's avatar
DonLakeFlyer committed
201 202 203 204 205 206 207
    bool _nextTransectCoord(const QList<QGeoCoordinate>& transectPoints, int pointIndex, QGeoCoordinate& coord);
    double _triggerDistance(void) const;
    bool _triggerCamera(void) const;
    bool _imagesEverywhere(void) const;
    bool _hoverAndCaptureEnabled(void) const;
    bool _hasTurnaround(void) const;
    double _turnaroundDistance(void) const;
208 209 210 211 212 213

    int                             _sequenceNumber;
    bool                            _dirty;
    QVariantList                    _polygonPath;
    QmlObjectListModel              _polygonModel;
    QVariantList                    _simpleGridPoints;      ///< Grid points for drawing simple grid visuals
DonLakeFlyer's avatar
DonLakeFlyer committed
214
    QList<QList<QGeoCoordinate>>    _transectSegments;      ///< Internal transect segments including grid exit, turnaround and internal camera points
215 216 217
    QGeoCoordinate                  _coordinate;
    QGeoCoordinate                  _exitCoordinate;
    bool                            _cameraOrientationFixed;
DonLakeFlyer's avatar
DonLakeFlyer committed
218
    int                             _missionCommandCount;
Don Gagne's avatar
Don Gagne committed
219 220 221 222

    double          _surveyDistance;
    int             _cameraShots;
    double          _coveredArea;
223 224
    double          _timeBetweenShots;
    double          _cruiseSpeed;
225

226 227 228 229 230 231 232 233 234 235
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact    _manualGridFact;
    SettingsFact    _gridAltitudeFact;
    SettingsFact    _gridAltitudeRelativeFact;
    SettingsFact    _gridAngleFact;
    SettingsFact    _gridSpacingFact;
    SettingsFact    _turnaroundDistFact;
    SettingsFact    _cameraTriggerFact;
    SettingsFact    _cameraTriggerDistanceFact;
236 237
    SettingsFact    _cameraTriggerInTurnaroundFact;
    SettingsFact    _hoverAndCaptureFact;
238 239 240 241 242 243 244 245 246 247 248
    SettingsFact    _groundResolutionFact;
    SettingsFact    _frontalOverlapFact;
    SettingsFact    _sideOverlapFact;
    SettingsFact    _cameraSensorWidthFact;
    SettingsFact    _cameraSensorHeightFact;
    SettingsFact    _cameraResolutionWidthFact;
    SettingsFact    _cameraResolutionHeightFact;
    SettingsFact    _cameraFocalLengthFact;
    SettingsFact    _cameraOrientationLandscapeFact;
    SettingsFact    _fixedValueIsAltitudeFact;
    SettingsFact    _cameraFact;
249

Don Gagne's avatar
Don Gagne committed
250 251
    static const char* _jsonPolygonObjectKey;
    static const char* _jsonGridObjectKey;
252 253 254 255
    static const char* _jsonGridAltitudeKey;
    static const char* _jsonGridAltitudeRelativeKey;
    static const char* _jsonGridAngleKey;
    static const char* _jsonGridSpacingKey;
Andreas Bircher's avatar
Andreas Bircher committed
256
    static const char* _jsonTurnaroundDistKey;
257 258
    static const char* _jsonCameraTriggerKey;
    static const char* _jsonCameraTriggerDistanceKey;
259 260
    static const char* _jsonCameraTriggerInTurnaroundKey;
    static const char* _jsonHoverAndCaptureKey;
Don Gagne's avatar
Don Gagne committed
261 262 263 264 265 266 267 268 269 270 271 272 273
    static const char* _jsonGroundResolutionKey;
    static const char* _jsonFrontalOverlapKey;
    static const char* _jsonSideOverlapKey;
    static const char* _jsonCameraSensorWidthKey;
    static const char* _jsonCameraSensorHeightKey;
    static const char* _jsonCameraResolutionWidthKey;
    static const char* _jsonCameraResolutionHeightKey;
    static const char* _jsonCameraFocalLengthKey;
    static const char* _jsonManualGridKey;
    static const char* _jsonCameraObjectKey;
    static const char* _jsonCameraNameKey;
    static const char* _jsonCameraOrientationLandscapeKey;
    static const char* _jsonFixedValueIsAltitudeKey;
274 275 276
};

#endif