SurveyComplexItem.h 6.55 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10
#pragma once
11

12
#include "TransectStyleComplexItem.h"
13
#include "MissionItem.h"
14
#include "SettingsFact.h"
15 16
#include "QGCLoggingCategory.h"

17
Q_DECLARE_LOGGING_CATEGORY(SurveyComplexItemLog)
18

19
class SurveyComplexItem : public TransectStyleComplexItem
20 21 22 23
{
    Q_OBJECT

public:
24
    SurveyComplexItem(Vehicle* vehicle, bool flyView, QObject* parent);
25

26 27
    Q_PROPERTY(Fact* gridAngle              READ gridAngle              CONSTANT)
    Q_PROPERTY(Fact* flyAlternateTransects  READ flyAlternateTransects  CONSTANT)
28

29 30
    Fact* gridAngle             (void) { return &_gridAngleFact; }
    Fact* flyAlternateTransects (void) { return &_flyAlternateTransectsFact; }
DonLakeFlyer's avatar
DonLakeFlyer committed
31 32

    Q_INVOKABLE void rotateEntryPoint(void);
33 34

    // Overrides from ComplexMissionItem
35 36
    bool    load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    QString mapVisualQML        (void) const final { return QStringLiteral("SurveyMapVisual.qml"); }
37

38 39 40 41 42
    // Overrides from TransectStyleComplexItem
    void    save                (QJsonArray&  planItems) final;
    bool    specifiesCoordinate (void) const final { return true; }
    void    appendMissionItems  (QList<MissionItem*>& items, QObject* missionItemParent) final;
    void    applyNewAltitude    (double newAltitude) final;
43
    double  timeBetweenShots    (void) final;
44

45 46 47 48 49
    // Overrides from VisualMissionionItem
    QString commandDescription  (void) const final { return tr("Survey"); }
    QString commandName         (void) const final { return tr("Survey"); }
    QString abbreviation        (void) const final { return tr("S"); }
    bool    readyForSave        (void) const final;
50

51 52
    // Must match json spec for GridEntryLocation
    enum EntryLocation {
DonLakeFlyer's avatar
DonLakeFlyer committed
53 54
        EntryLocationFirst,
        EntryLocationTopLeft = EntryLocationFirst,
55 56 57
        EntryLocationTopRight,
        EntryLocationBottomLeft,
        EntryLocationBottomRight,
DonLakeFlyer's avatar
DonLakeFlyer committed
58
        EntryLocationLast = EntryLocationBottomRight
59 60
    };

Don Gagne's avatar
Don Gagne committed
61
    static const char* jsonComplexItemTypeValue;
62 63
    static const char* settingsGroup;
    static const char* gridAngleName;
DonLakeFlyer's avatar
DonLakeFlyer committed
64
    static const char* gridEntryLocationName;
65
    static const char* flyAlternateTransectsName;
66 67

    static const char* jsonV3ComplexItemTypeValue;
68

69
signals:
70
    void refly90DegreesChanged(bool refly90Degrees);
71 72

private slots:
73 74 75
    // Overrides from TransectStyleComplexItem
    void _rebuildTransectsPhase1(void) final;
    void _rebuildTransectsPhase2(void) final;
76 77

private:
78 79 80
    enum CameraTriggerCode {
        CameraTriggerNone,
        CameraTriggerOn,
DonLakeFlyer's avatar
DonLakeFlyer committed
81 82
        CameraTriggerOff,
        CameraTriggerHoverAndCapture
83 84
    };

85 86 87 88
    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);
89
    int _appendWaypointToMission(QList<MissionItem*>& items, int seqNum, QGeoCoordinate& coord, CameraTriggerCode cameraTrigger, QObject* missionItemParent);
DonLakeFlyer's avatar
DonLakeFlyer committed
90
    bool _nextTransectCoord(const QList<QGeoCoordinate>& transectPoints, int pointIndex, QGeoCoordinate& coord);
91
    bool _appendMissionItemsWorker(QList<MissionItem*>& items, QObject* missionItemParent, int& seqNum, bool hasRefly, bool buildRefly);
DonLakeFlyer's avatar
DonLakeFlyer committed
92
    void _optimizeTransectsForShortestDistance(const QGeoCoordinate& distanceCoord, QList<QList<QGeoCoordinate>>& transects);
93 94 95
    qreal _ccw(QPointF pt1, QPointF pt2, QPointF pt3);
    qreal _dp(QPointF pt1, QPointF pt2);
    void _swapPoints(QList<QPointF>& points, int index1, int index2);
DonLakeFlyer's avatar
DonLakeFlyer committed
96 97 98 99 100
    void _reverseTransectOrder(QList<QList<QGeoCoordinate>>& transects);
    void _reverseInternalTransectPoints(QList<QList<QGeoCoordinate>>& transects);
    void _adjustTransectsToEntryPointLocation(QList<QList<QGeoCoordinate>>& transects);
    bool _gridAngleIsNorthSouthTransects();
    double _clampGridAngle90(double gridAngle);
101 102 103 104 105 106 107 108 109
    void _buildAndAppendMissionItems(QList<MissionItem*>& items, QObject* missionItemParent);
    void _appendLoadedMissionItems  (QList<MissionItem*>& items, QObject* missionItemParent);
    bool _imagesEverywhere(void) const;
    bool _triggerCamera(void) const;
    bool _hasTurnaround(void) const;
    double _turnaroundDistance(void) const;
    bool _hoverAndCaptureEnabled(void) const;
    bool _loadV3(const QJsonObject& complexObject, int sequenceNumber, QString& errorString);
    bool _loadV4(const QJsonObject& complexObject, int sequenceNumber, QString& errorString);
110
    void _rebuildTransectsPhase1Worker(bool refly);
111

112 113 114
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact    _gridAngleFact;
115
    SettingsFact    _flyAlternateTransectsFact;
DonLakeFlyer's avatar
DonLakeFlyer committed
116
    int             _entryPoint;
117 118

    static const char* _jsonGridAngleKey;
DonLakeFlyer's avatar
DonLakeFlyer committed
119
    static const char* _jsonEntryPointKey;
120
    static const char* _jsonFlyAlternateTransectsKey;
121 122 123 124 125 126

    static const char* _jsonV3GridObjectKey;
    static const char* _jsonV3GridAltitudeKey;
    static const char* _jsonV3GridAltitudeRelativeKey;
    static const char* _jsonV3GridAngleKey;
    static const char* _jsonV3GridSpacingKey;
DonLakeFlyer's avatar
DonLakeFlyer committed
127
    static const char* _jsonV3EntryPointKey;
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    static const char* _jsonV3TurnaroundDistKey;
    static const char* _jsonV3CameraTriggerDistanceKey;
    static const char* _jsonV3CameraTriggerInTurnaroundKey;
    static const char* _jsonV3HoverAndCaptureKey;
    static const char* _jsonV3GroundResolutionKey;
    static const char* _jsonV3FrontalOverlapKey;
    static const char* _jsonV3SideOverlapKey;
    static const char* _jsonV3CameraSensorWidthKey;
    static const char* _jsonV3CameraSensorHeightKey;
    static const char* _jsonV3CameraResolutionWidthKey;
    static const char* _jsonV3CameraResolutionHeightKey;
    static const char* _jsonV3CameraFocalLengthKey;
    static const char* _jsonV3CameraMinTriggerIntervalKey;
    static const char* _jsonV3ManualGridKey;
    static const char* _jsonV3CameraObjectKey;
    static const char* _jsonV3CameraNameKey;
    static const char* _jsonV3CameraOrientationLandscapeKey;
    static const char* _jsonV3FixedValueIsAltitudeKey;
    static const char* _jsonV3Refly90DegreesKey;

148

DonLakeFlyer's avatar
DonLakeFlyer committed
149
    static const int _hoverAndCaptureDelaySeconds = 4;
150
};