GeoFenceController.h 5.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/****************************************************************************
 *
 *   (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 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 42 43 44
    /// Add a new inclusion polygon to the fence
    ///     @param topLeft - Top left coordinate or map viewport
    ///     @param topLeft - Bottom right left coordinate or map viewport
    Q_INVOKABLE void addInclusionPolygon(QGeoCoordinate topLeft, QGeoCoordinate bottomRight);
45

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

51 52 53 54 55 56 57 58 59 60 61
    /// Deletes the specified polygon from the polygon list
    ///     @param index Index of poygon to delete
    Q_INVOKABLE void deletePolygon(int index);

    /// Deletes the specified circle from the circle list
    ///     @param index Index of circle to delete
    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;
78
    void managerVehicleChanged      (Vehicle* managerVehicle) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
79
    bool showPlanFromManagerVehicle (void) final;
80

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

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

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

private slots:
95 96 97 98 99 100 101 102 103
    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);
104 105

private:
106
    void _init(void);
107

108 109
    GeoFenceManager*    _geoFenceManager;
    bool                _dirty;
110 111
    QmlObjectListModel  _polygons;
    QmlObjectListModel  _circles;
112
    QGeoCoordinate      _breachReturnPoint;
113 114
    Fact                _breachReturnAltitudeFact;
    double              _breachReturnDefaultAltitude;
DonLakeFlyer's avatar
DonLakeFlyer committed
115
    bool                _itemsRequested;
116
    Fact*               _px4ParamCircularFenceFact;
117

118 119
    static QMap<QString, FactMetaData*> _metaDataMap;

120 121
    static const char* _px4ParamCircularFence;

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

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

    static const char* _breachReturnAltitudeFactName;
130 131 132
};

#endif