GeoFenceController.h 5.58 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#ifndef GeoFenceController_H
#define GeoFenceController_H

#include "PlanElementController.h"
#include "GeoFenceManager.h"
15 16
#include "QGCFencePolygon.h"
#include "QGCFenceCircle.h"
17 18 19 20 21 22
#include "Vehicle.h"
#include "MultiVehicleManager.h"
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(GeoFenceControllerLog)

23 24
class GeoFenceManager;

25 26 27 28 29
class GeoFenceController : public PlanElementController
{
    Q_OBJECT
    
public:
30
    GeoFenceController(PlanMasterController* masterController, QObject* parent = nullptr);
31
    ~GeoFenceController();
32

33 34 35 36
    Q_PROPERTY(QmlObjectListModel*  polygons                READ polygons                                           CONSTANT)
    Q_PROPERTY(QmlObjectListModel*  circles                 READ circles                                            CONSTANT)
    Q_PROPERTY(QGeoCoordinate       breachReturnPoint       READ breachReturnPoint      WRITE setBreachReturnPoint  NOTIFY breachReturnPointChanged)
    Q_PROPERTY(Fact*                breachReturnAltitude    READ breachReturnAltitude                               CONSTANT)
37

38 39 40
    // Hack to expose PX4 circular fence controlled by GF_MAX_HOR_DIST
    Q_PROPERTY(double               paramCircularFence  READ paramCircularFence                             NOTIFY paramCircularFenceChanged)

41
    /// Add a new inclusion polygon to the fence
42 43
    ///     @param topLeft: Top left coordinate or map viewport
    ///     @param bottomRight: Bottom right left coordinate or map viewport
44
    Q_INVOKABLE void addInclusionPolygon(QGeoCoordinate topLeft, QGeoCoordinate bottomRight);
45

46
    /// Add a new inclusion circle to the fence
47 48
    ///     @param topLeft: Top left coordinate or map viewport
    ///     @param bottomRight: Bottom right left coordinate or map viewport
49
    Q_INVOKABLE void addInclusionCircle(QGeoCoordinate topLeft, QGeoCoordinate bottomRight);
50

51
    /// Deletes the specified polygon from the polygon list
52
    ///     @param index: Index of poygon to delete
53 54 55
    Q_INVOKABLE void deletePolygon(int index);

    /// Deletes the specified circle from the circle list
56
    ///     @param index: Index of circle to delete
57 58 59 60 61
    Q_INVOKABLE void deleteCircle(int index);

    /// Clears the interactive bit from all fence items
    Q_INVOKABLE void clearAllInteractive(void);

62 63
    double  paramCircularFence  (void);
    Fact*   breachReturnAltitude(void) { return &_breachReturnAltitudeFact; }
64 65

    // Overrides from PlanElementController
66
    bool supported                  (void) const final;
67
    void start                      (bool flyView) final;
68 69
    void save                       (QJsonObject& json) final;
    bool load                       (const QJsonObject& json, QString& errorString) final;
70 71 72
    void loadFromVehicle            (void) final;
    void sendToVehicle              (void) final;
    void removeAll                  (void) final;
73
    void removeAllFromVehicle       (void) final;
74 75 76
    bool syncInProgress             (void) const final;
    bool dirty                      (void) const final;
    void setDirty                   (bool dirty) final;
77
    bool containsItems              (void) const final;
DonLakeFlyer's avatar
DonLakeFlyer committed
78
    bool showPlanFromManagerVehicle (void) final;
79

80 81 82
    QmlObjectListModel* polygons                (void) { return &_polygons; }
    QmlObjectListModel* circles                 (void) { return &_circles; }
    QGeoCoordinate      breachReturnPoint       (void) const { return _breachReturnPoint; }
83

84 85
    void setBreachReturnPoint   (const QGeoCoordinate& breachReturnPoint);
    bool isEmpty                (void) const;
86 87

signals:
88 89 90
    void breachReturnPointChanged       (QGeoCoordinate breachReturnPoint);
    void editorQmlChanged               (QString editorQml);
    void loadComplete                   (void);
91
    void paramCircularFenceChanged      (void);
92 93

private slots:
94 95 96 97 98 99 100 101 102
    void _polygonDirtyChanged       (bool dirty);
    void _setDirty                  (void);
    void _setFenceFromManager       (const QList<QGCFencePolygon>& polygons, const QList<QGCFenceCircle>&  circles);
    void _setReturnPointFromManager (QGeoCoordinate breachReturnPoint);
    void _managerLoadComplete       (void);
    void _updateContainsItems       (void);
    void _managerSendComplete       (bool error);
    void _managerRemoveAllComplete  (bool error);
    void _parametersReady           (void);
103
    void _managerVehicleChanged      (Vehicle* managerVehicle);
104 105

private:
106
    void _init(void);
107

108 109 110
    Vehicle*            _managerVehicle =               nullptr;
    GeoFenceManager*    _geoFenceManager =              nullptr;
    bool                _dirty =                        false;
111 112
    QmlObjectListModel  _polygons;
    QmlObjectListModel  _circles;
113
    QGeoCoordinate      _breachReturnPoint;
114 115 116 117 118 119
    Fact                _breachReturnAltitudeFact;
    double              _breachReturnDefaultAltitude =  qQNaN();
    bool                _itemsRequested =               false;
    Fact*               _px4ParamCircularFenceFact =    nullptr;

    static QMap<QString, FactMetaData*> _metaDataMap;
120

121 122
    static const char* _px4ParamCircularFence;

DonLakeFlyer's avatar
DonLakeFlyer committed
123
    static const int _jsonCurrentVersion = 2;
124

125
    static const char* _jsonFileTypeValue;
126
    static const char* _jsonBreachReturnKey;
127 128
    static const char* _jsonPolygonsKey;
    static const char* _jsonCirclesKey;
129 130

    static const char* _breachReturnAltitudeFactName;
131 132 133
};

#endif