GeoFenceManager.h 3.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/****************************************************************************
 *
 *   (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 GeoFenceManager_H
#define GeoFenceManager_H

#include <QObject>
#include <QGeoCoordinate>

#include "QGCLoggingCategory.h"
17
#include "FactSystem.h"
18 19 20
#include "PlanManager.h"
#include "QGCFencePolygon.h"
#include "QGCFenceCircle.h"
21 22

class Vehicle;
23
class QmlObjectListModel;
24
class PlanManager;
25 26 27

Q_DECLARE_LOGGING_CATEGORY(GeoFenceManagerLog)

28 29
/// This is the base class for firmware specific geofence managers. A geofence manager is responsible
/// for communicating with the vehicle to set/get geofence settings.
30 31 32 33 34 35 36 37
class GeoFenceManager : public QObject
{
    Q_OBJECT
    
public:
    GeoFenceManager(Vehicle* vehicle);
    ~GeoFenceManager();
    
38 39 40
    /// Returns true if GeoFence is supported by this vehicle
    virtual bool supported(void) const;

41
    /// Returns true if the manager is currently communicating with the vehicle
42
    virtual bool inProgress(void) const;
43

44
    /// Load the current settings from the vehicle
DonLakeFlyer's avatar
DonLakeFlyer committed
45
    ///     Signals loadComplete when done
46
    virtual void loadFromVehicle(void);
47

48
    /// Send the geofence settings to the vehicle
DonLakeFlyer's avatar
DonLakeFlyer committed
49
    ///     Signals sendComplete when done
50 51 52
    virtual void sendToVehicle(const QGeoCoordinate&    breachReturn,   ///< Breach return point
                               QmlObjectListModel&      polygons,       ///< List of QGCFencePolygons
                               QmlObjectListModel&      circles);       ///< List of QGCFenceCircles
53

Patrick José Pereira's avatar
Patrick José Pereira committed
54
    /// Remove all fence related items from vehicle (does not affect parameters)
DonLakeFlyer's avatar
DonLakeFlyer committed
55 56
    ///     Signals removeAllComplete when done
    virtual void removeAll(void);
57

58 59
    /// Returns true if polygon fence is currently enabled on this vehicle
    ///     Signal: polygonEnabledChanged
60
    virtual bool polygonEnabled(void) const { return true; }
61

62 63 64
    const QList<QGCFencePolygon>&   polygons(void) { return _polygons; }
    const QList<QGCFenceCircle>&    circles(void) { return _circles; }
    const QGeoCoordinate&           breachReturnPoint(void) const { return _breachReturnPoint; }
65

66 67 68
    /// Error codes returned in error signal
    typedef enum {
        InternalError,
69 70 71 72 73
        PolygonTooFewPoints,    ///< Too few points for valid fence polygon
        PolygonTooManyPoints,   ///< Too many points for valid fence polygon
        IncompletePolygonLoad,  ///< Incomplete polygon loaded
        UnsupportedCommand,     ///< Usupported command in mission type
        BadPolygonItemFormat,   ///< Error re-creating polygons from mission items
74 75 76 77
        InvalidCircleRadius,
    } ErrorCode_t;
    
signals:
78
    void loadComplete                   (void);
79 80
    void inProgressChanged              (bool inProgress);
    void error                          (int errorCode, const QString& errorMsg);
81 82
    void removeAllComplete              (bool error);
    void sendComplete                   (bool error);
83

84 85 86 87 88
private slots:
    void _sendComplete              (bool error);
    void _planManagerLoadComplete   (bool removeAllRequested);

private:
89 90
    void _sendError(ErrorCode_t errorCode, const QString& errorMsg);

91
    Vehicle*                _vehicle;
92 93 94
    PlanManager             _planManager;
    QList<QGCFencePolygon>  _polygons;
    QList<QGCFenceCircle>   _circles;
95
    QGeoCoordinate          _breachReturnPoint;
96 97 98
    bool                    _firstParamLoadComplete;
    QList<QGCFencePolygon>  _sendPolygons;
    QList<QGCFenceCircle>   _sendCircles;
99 100 101
};

#endif