GeoFenceController.h 5.22 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 31
class GeoFenceController : public PlanElementController
{
    Q_OBJECT
    
public:
    GeoFenceController(QObject* parent = NULL);
    ~GeoFenceController();
    
32
    Q_PROPERTY(bool                 fenceSupported          READ fenceSupported                                     NOTIFY fenceSupportedChanged)
33
    Q_PROPERTY(bool                 fenceEnabled            READ fenceEnabled                                       NOTIFY fenceEnabledChanged)
34 35 36 37 38 39 40 41
    Q_PROPERTY(bool                 circleSupported         READ circleSupported                                    NOTIFY circleSupportedChanged)
    Q_PROPERTY(bool                 polygonSupported        READ polygonSupported                                   NOTIFY polygonSupportedChanged)
    Q_PROPERTY(bool                 breachReturnSupported   READ breachReturnSupported                              NOTIFY breachReturnSupportedChanged)
    Q_PROPERTY(float                circleRadius            READ circleRadius                                       NOTIFY circleRadiusChanged)
    Q_PROPERTY(QGCMapPolygon*       polygon                 READ polygon                                            CONSTANT)
    Q_PROPERTY(QGeoCoordinate       breachReturnPoint       READ breachReturnPoint      WRITE setBreachReturnPoint  NOTIFY breachReturnPointChanged)
    Q_PROPERTY(QVariantList         params                  READ params                                             NOTIFY paramsChanged)
    Q_PROPERTY(QStringList          paramLabels             READ paramLabels                                        NOTIFY paramLabelsChanged)
42
    Q_PROPERTY(QString              editorQml               READ editorQml                                          NOTIFY editorQmlChanged)
43 44 45 46 47 48 49 50 51 52 53 54 55

    void start              (bool editMode) final;
    void loadFromVehicle    (void) final;
    void sendToVehicle      (void) final;
    void loadFromFilePicker (void) final;
    void loadFromFile       (const QString& filename) final;
    void saveToFilePicker   (void) final;
    void saveToFile         (const QString& filename) final;
    void removeAll          (void) final;
    bool syncInProgress     (void) const final;
    bool dirty              (void) const final;
    void setDirty           (bool dirty) final;

56 57
    QString fileExtension(void) const final;

58
    bool                fenceSupported          (void) const;
59
    bool                fenceEnabled            (void) const;
60 61 62 63 64 65 66 67
    bool                circleSupported         (void) const;
    bool                polygonSupported        (void) const;
    bool                breachReturnSupported   (void) const;
    float               circleRadius            (void) const;
    QGCMapPolygon*      polygon                 (void) { return &_polygon; }
    QGeoCoordinate      breachReturnPoint       (void) const { return _breachReturnPoint; }
    QVariantList        params                  (void) const;
    QStringList         paramLabels             (void) const;
68
    QString             editorQml               (void) const;
69 70 71 72

    void setBreachReturnPoint(const QGeoCoordinate& breachReturnPoint);

signals:
73
    void fenceSupportedChanged          (bool fenceSupported);
74
    void fenceEnabledChanged            (bool fenceEnabled);
75 76 77 78 79 80 81 82
    void circleSupportedChanged         (bool circleSupported);
    void polygonSupportedChanged        (bool polygonSupported);
    void breachReturnSupportedChanged   (bool breachReturnSupported);
    void circleRadiusChanged            (float circleRadius);
    void polygonPathChanged             (const QVariantList& polygonPath);
    void breachReturnPointChanged       (QGeoCoordinate breachReturnPoint);
    void paramsChanged                  (QVariantList params);
    void paramLabelsChanged             (QStringList paramLabels);
83
    void editorQmlChanged               (QString editorQml);
Don Gagne's avatar
Don Gagne committed
84
    void loadComplete                   (void);
85 86 87

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

private:
94
    void _signalAll(void);
95
    bool _loadJsonFile(QJsonDocument& jsonDoc, QString& errorString);
96

97
    void _activeVehicleBeingRemoved(void) final;
98 99
    void _activeVehicleSet(void) final;

100 101 102 103 104 105
    bool                _dirty;
    QGCMapPolygon       _polygon;
    QGeoCoordinate      _breachReturnPoint;
    QVariantList        _params;

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

#endif