SurveyComplexItem.h 7.79 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
 *
 * 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 20
class PlanMasterController;

21
class SurveyComplexItem : public TransectStyleComplexItem
22 23 24 25
{
    Q_OBJECT

public:
26
    /// @param flyView true: Created for use in the Fly View, false: Created for use in the Plan View
27
    /// @param kmlOrShpFile Polygon comes from this file, empty for default polygon
28
    SurveyComplexItem(PlanMasterController* masterController, bool flyView, const QString& kmlOrShpFile, QObject* parent);
29

30 31
    Q_PROPERTY(Fact* gridAngle              READ gridAngle              CONSTANT)
    Q_PROPERTY(Fact* flyAlternateTransects  READ flyAlternateTransects  CONSTANT)
32
    Q_PROPERTY(Fact* splitConcavePolygons   READ splitConcavePolygons   CONSTANT)
33

34 35
    Fact* gridAngle             (void) { return &_gridAngleFact; }
    Fact* flyAlternateTransects (void) { return &_flyAlternateTransectsFact; }
36
    Fact* splitConcavePolygons  (void) { return &_splitConcavePolygonsFact; }
DonLakeFlyer's avatar
DonLakeFlyer committed
37 38

    Q_INVOKABLE void rotateEntryPoint(void);
39 40

    // Overrides from ComplexMissionItem
41
    QString patternName         (void) const final { return name; }
42 43
    bool    load                (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) final;
    QString mapVisualQML        (void) const final { return QStringLiteral("SurveyMapVisual.qml"); }
Don Gagne's avatar
Don Gagne committed
44 45 46
    QString presetsSettingsGroup(void) { return settingsGroup; }
    void    savePreset          (const QString& name);
    void    loadPreset          (const QString& name);
47

48 49 50
    // Overrides from TransectStyleComplexItem
    void    save                (QJsonArray&  planItems) final;
    bool    specifiesCoordinate (void) const final { return true; }
51
    double  timeBetweenShots    (void) final;
52

53
    // Overrides from VisualMissionionItem
DonLakeFlyer's avatar
DonLakeFlyer committed
54 55 56 57 58
    QString             commandDescription  (void) const final { return tr("Survey"); }
    QString             commandName         (void) const final { return tr("Survey"); }
    QString             abbreviation        (void) const final { return tr("S"); }
    ReadyForSaveState   readyForSaveState    (void) const final;
    double              additionalTimeDelay (void) const final;
59

60 61
    // Must match json spec for GridEntryLocation
    enum EntryLocation {
DonLakeFlyer's avatar
DonLakeFlyer committed
62 63
        EntryLocationFirst,
        EntryLocationTopLeft = EntryLocationFirst,
64 65 66
        EntryLocationTopRight,
        EntryLocationBottomLeft,
        EntryLocationBottomRight,
DonLakeFlyer's avatar
DonLakeFlyer committed
67
        EntryLocationLast = EntryLocationBottomRight
68 69
    };

70 71
    static const QString name;

Don Gagne's avatar
Don Gagne committed
72
    static const char* jsonComplexItemTypeValue;
73 74
    static const char* settingsGroup;
    static const char* gridAngleName;
DonLakeFlyer's avatar
DonLakeFlyer committed
75
    static const char* gridEntryLocationName;
76
    static const char* flyAlternateTransectsName;
77
    static const char* splitConcavePolygonsName;
78 79

    static const char* jsonV3ComplexItemTypeValue;
80

81
signals:
82
    void refly90DegreesChanged(bool refly90Degrees);
83 84

private slots:
DoinLakeFlyer's avatar
DoinLakeFlyer committed
85 86
    void _updateWizardMode              (void);

87
    // Overrides from TransectStyleComplexItem
DoinLakeFlyer's avatar
DoinLakeFlyer committed
88 89
    void _rebuildTransectsPhase1        (void) final;
    void _recalcCameraShots             (void) final;
90 91

private:
92 93 94
    enum CameraTriggerCode {
        CameraTriggerNone,
        CameraTriggerOn,
DonLakeFlyer's avatar
DonLakeFlyer committed
95 96
        CameraTriggerOff,
        CameraTriggerHoverAndCapture
97 98
    };

99 100 101 102
    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);
DonLakeFlyer's avatar
DonLakeFlyer committed
103
    bool _nextTransectCoord(const QList<QGeoCoordinate>& transectPoints, int pointIndex, QGeoCoordinate& coord);
104
    bool _appendMissionItemsWorker(QList<MissionItem*>& items, QObject* missionItemParent, int& seqNum, bool hasRefly, bool buildRefly);
DonLakeFlyer's avatar
DonLakeFlyer committed
105
    void _optimizeTransectsForShortestDistance(const QGeoCoordinate& distanceCoord, QList<QList<QGeoCoordinate>>& transects);
106 107 108
    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
109 110 111 112 113
    void _reverseTransectOrder(QList<QList<QGeoCoordinate>>& transects);
    void _reverseInternalTransectPoints(QList<QList<QGeoCoordinate>>& transects);
    void _adjustTransectsToEntryPointLocation(QList<QList<QGeoCoordinate>>& transects);
    bool _gridAngleIsNorthSouthTransects();
    double _clampGridAngle90(double gridAngle);
114 115 116 117 118 119
    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);
Don Gagne's avatar
Don Gagne committed
120 121
    bool _loadV4V5(const QJsonObject& complexObject, int sequenceNumber, QString& errorString, int version, bool forPresets);
    void _saveWorker(QJsonObject& complexObject);
122
    void _rebuildTransectsPhase1Worker(bool refly);
123 124
    void _rebuildTransectsPhase1WorkerSinglePolygon(bool refly);
    void _rebuildTransectsPhase1WorkerSplitPolygons(bool refly);
125
    /// Adds to the _transects array from one polygon
126
    void _rebuildTransectsFromPolygon(bool refly, const QPolygonF& polygon, const QGeoCoordinate& tangentOrigin, const QPointF* const transitionPoint);
127 128 129
    // Decompose polygon into list of convex sub polygons
    void _PolygonDecomposeConvex(const QPolygonF& polygon, QList<QPolygonF>& decomposedPolygons);
    // return true if vertex a can see vertex b
130 131
    bool _VertexCanSeeOther(const QPolygonF& polygon, const QPointF* vertexA, const QPointF* vertexB);
    bool _VertexIsReflex(const QPolygonF& polygon, const QPointF* vertex);
132

133 134 135
    QMap<QString, FactMetaData*> _metaDataMap;

    SettingsFact    _gridAngleFact;
136
    SettingsFact    _flyAlternateTransectsFact;
137
    SettingsFact    _splitConcavePolygonsFact;
DonLakeFlyer's avatar
DonLakeFlyer committed
138
    int             _entryPoint;
139 140

    static const char* _jsonGridAngleKey;
DonLakeFlyer's avatar
DonLakeFlyer committed
141
    static const char* _jsonEntryPointKey;
142
    static const char* _jsonFlyAlternateTransectsKey;
143
    static const char* _jsonSplitConcavePolygonsKey;
144 145 146 147 148 149

    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
150
    static const char* _jsonV3EntryPointKey;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    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;
170
};