GeoFenceController.h 4.96 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 = NULL);
31
    ~GeoFenceController();
32

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

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

40 41 42 43
    /// 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);
44

45 46 47 48
    /// 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);
49

50 51 52 53 54 55 56 57 58 59 60
    /// 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);

61 62 63
    double paramCircularFence(void);

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

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

    void setBreachReturnPoint(const QGeoCoordinate& breachReturnPoint);

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

private slots:
92 93 94 95 96 97 98 99 100
    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);
101 102

private:
103
    void _init(void);
104
    void _signalAll(void);
105

106 107
    GeoFenceManager*    _geoFenceManager;
    bool                _dirty;
108 109
    QmlObjectListModel  _polygons;
    QmlObjectListModel  _circles;
110
    QGeoCoordinate      _breachReturnPoint;
DonLakeFlyer's avatar
DonLakeFlyer committed
111
    bool                _itemsRequested;
112
    Fact*               _px4ParamCircularFenceFact;
113

114 115
    static const char* _px4ParamCircularFence;

DonLakeFlyer's avatar
DonLakeFlyer committed
116
    static const int _jsonCurrentVersion = 2;
117

118
    static const char* _jsonFileTypeValue;
119
    static const char* _jsonBreachReturnKey;
120 121
    static const char* _jsonPolygonsKey;
    static const char* _jsonCirclesKey;
122 123 124
};

#endif