GeoFenceController.h 4.34 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 40
    /// 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);
41

42 43 44 45
    /// 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);
46

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

    bool supported                  (void) const final;
59
    void start                      (bool editMode) final;
60 61
    void save                       (QJsonObject& json) final;
    bool load                       (const QJsonObject& json, QString& errorString) final;
62 63 64
    void loadFromVehicle            (void) final;
    void sendToVehicle              (void) final;
    void removeAll                  (void) final;
65
    void removeAllFromVehicle       (void) final;
66 67 68
    bool syncInProgress             (void) const final;
    bool dirty                      (void) const final;
    void setDirty                   (bool dirty) final;
69
    bool containsItems              (void) const final;
70
    void managerVehicleChanged      (Vehicle* managerVehicle) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
71
    bool showPlanFromManagerVehicle (void) final;
72

73 74 75
    QmlObjectListModel* polygons                (void) { return &_polygons; }
    QmlObjectListModel* circles                 (void) { return &_circles; }
    QGeoCoordinate      breachReturnPoint       (void) const { return _breachReturnPoint; }
76 77 78 79

    void setBreachReturnPoint(const QGeoCoordinate& breachReturnPoint);

signals:
80 81 82
    void breachReturnPointChanged       (QGeoCoordinate breachReturnPoint);
    void editorQmlChanged               (QString editorQml);
    void loadComplete                   (void);
83 84 85

private slots:
    void _polygonDirtyChanged(bool dirty);
86
    void _setDirty(void);
87 88
    void _setFenceFromManager(const QList<QGCFencePolygon>& polygons,
                              const QList<QGCFenceCircle>&  circles);
89
    void _setReturnPointFromManager(QGeoCoordinate breachReturnPoint);
90
    void _managerLoadComplete(void);
91
    void _updateContainsItems(void);
92 93
    void _managerSendComplete(bool error);
    void _managerRemoveAllComplete(bool error);
94 95

private:
96
    void _init(void);
97
    void _signalAll(void);
98

99 100
    GeoFenceManager*    _geoFenceManager;
    bool                _dirty;
101 102
    QmlObjectListModel  _polygons;
    QmlObjectListModel  _circles;
103
    QGeoCoordinate      _breachReturnPoint;
DonLakeFlyer's avatar
DonLakeFlyer committed
104
    bool                _itemsRequested;
105 106

    static const char* _jsonFileTypeValue;
107
    static const char* _jsonBreachReturnKey;
108 109 110
};

#endif