GeoFenceController.h 4.87 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 29 30
class GeoFenceController : public PlanElementController
{
    Q_OBJECT
    
public:
    GeoFenceController(QObject* parent = NULL);
    ~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 48 49 50 51 52 53
    void start                      (bool editMode) final;
    void startStaticActiveVehicle   (Vehicle* vehicle) final;
    void loadFromVehicle            (void) final;
    void sendToVehicle              (void) final;
    void loadFromFile               (const QString& filename) final;
    void saveToFile                 (const QString& filename) final;
    void removeAll                  (void) final;
54
    void removeAllFromVehicle       (void) final;
55 56 57
    bool syncInProgress             (void) const final;
    bool dirty                      (void) const final;
    void setDirty                   (bool dirty) final;
58
    bool containsItems              (void) const final;
59

60 61
    QString fileExtension(void) const final;

62 63 64 65 66 67 68 69 70
    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; }
71 72 73 74

    void setBreachReturnPoint(const QGeoCoordinate& breachReturnPoint);

signals:
75 76 77 78 79 80 81 82 83 84 85
    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);
86 87 88

private slots:
    void _polygonDirtyChanged(bool dirty);
89
    void _setDirty(void);
90 91 92
    void _setPolygonFromManager(const QList<QGeoCoordinate>& polygon);
    void _setReturnPointFromManager(QGeoCoordinate breachReturnPoint);
    void _loadComplete(const QGeoCoordinate& breachReturn, const QList<QGeoCoordinate>& polygon);
93
    void _updateContainsItems(void);
94 95

private:
96
    void _init(void);
97
    void _signalAll(void);
98
    bool _loadJsonFile(QJsonDocument& jsonDoc, QString& errorString);
99

100
    void _activeVehicleBeingRemoved(void) final;
101 102
    void _activeVehicleSet(void) final;

103 104 105
    bool            _dirty;
    QGCMapPolygon   _mapPolygon;
    QGeoCoordinate  _breachReturnPoint;
106 107

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

#endif