GeoFenceController.h 4.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/****************************************************************************
 *
 *   (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"
#include "QGCMapPolygon.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(GeoFenceControllerLog)

22 23
class GeoFenceManager;

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

32 33
    Q_PROPERTY(QGCMapPolygon*   mapPolygon              READ mapPolygon                                         CONSTANT)
    Q_PROPERTY(QGeoCoordinate   breachReturnPoint       READ breachReturnPoint      WRITE setBreachReturnPoint  NOTIFY breachReturnPointChanged)
34

35 36 37 38 39 40 41 42
    // The following properties are reflections of properties from GeoFenceManager
    Q_PROPERTY(bool             circleEnabled           READ circleEnabled          NOTIFY circleEnabledChanged)
    Q_PROPERTY(Fact*            circleRadiusFact        READ circleRadiusFact       NOTIFY circleRadiusFactChanged)
    Q_PROPERTY(bool             polygonSupported        READ polygonSupported       NOTIFY polygonSupportedChanged)
    Q_PROPERTY(bool             polygonEnabled          READ polygonEnabled         NOTIFY polygonEnabledChanged)
    Q_PROPERTY(bool             breachReturnSupported   READ breachReturnSupported  NOTIFY breachReturnSupportedChanged)
    Q_PROPERTY(QVariantList     params                  READ params                 NOTIFY paramsChanged)
    Q_PROPERTY(QStringList      paramLabels             READ paramLabels            NOTIFY paramLabelsChanged)
43

44 45
    Q_INVOKABLE void addPolygon     (void) { emit addInitialFencePolygon(); }
    Q_INVOKABLE void removePolygon  (void) { _mapPolygon.clear(); }
46

47
    void start                      (bool editMode) final;
48 49
    void save                       (QJsonObject& json) final;
    bool load                       (const QJsonObject& json, QString& errorString) final;
50 51 52
    void loadFromVehicle            (void) final;
    void sendToVehicle              (void) final;
    void removeAll                  (void) final;
53
    void removeAllFromVehicle       (void) final;
54 55 56
    bool syncInProgress             (void) const final;
    bool dirty                      (void) const final;
    void setDirty                   (bool dirty) final;
57
    bool containsItems              (void) const final;
58
    void managerVehicleChanged      (Vehicle* managerVehicle) final;
DonLakeFlyer's avatar
DonLakeFlyer committed
59
    bool showPlanFromManagerVehicle (void) final;
60

61 62 63 64 65 66 67 68 69
    bool            circleEnabled           (void) const;
    Fact*           circleRadiusFact        (void) const;
    bool            polygonSupported        (void) const;
    bool            polygonEnabled          (void) const;
    bool            breachReturnSupported   (void) const;
    QVariantList    params                  (void) const;
    QStringList     paramLabels             (void) const;
    QGCMapPolygon*  mapPolygon              (void) { return &_mapPolygon; }
    QGeoCoordinate  breachReturnPoint       (void) const { return _breachReturnPoint; }
70 71 72 73

    void setBreachReturnPoint(const QGeoCoordinate& breachReturnPoint);

signals:
74 75 76 77 78 79 80 81 82 83 84
    void breachReturnPointChanged       (QGeoCoordinate breachReturnPoint);
    void editorQmlChanged               (QString editorQml);
    void loadComplete                   (void);
    void addInitialFencePolygon         (void);
    void circleEnabledChanged           (bool circleEnabled);
    void circleRadiusFactChanged        (Fact* circleRadiusFact);
    void polygonSupportedChanged        (bool polygonSupported);
    void polygonEnabledChanged          (bool polygonEnabled);
    void breachReturnSupportedChanged   (bool breachReturnSupported);
    void paramsChanged                  (QVariantList params);
    void paramLabelsChanged             (QStringList paramLabels);
85 86 87

private slots:
    void _polygonDirtyChanged(bool dirty);
88
    void _setDirty(void);
89 90
    void _setPolygonFromManager(const QList<QGeoCoordinate>& polygon);
    void _setReturnPointFromManager(QGeoCoordinate breachReturnPoint);
DonLakeFlyer's avatar
DonLakeFlyer committed
91
    void _managerLoadComplete(const QGeoCoordinate& breachReturn, const QList<QGeoCoordinate>& polygon);
92
    void _updateContainsItems(void);
93 94
    void _managerSendComplete(bool error);
    void _managerRemoveAllComplete(bool error);
95 96

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

100 101 102 103
    GeoFenceManager*    _geoFenceManager;
    bool                _dirty;
    QGCMapPolygon       _mapPolygon;
    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