AirspaceFlightPlanProvider.h 10.4 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
Gus Grubba's avatar
Gus Grubba committed
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

/**
 * @file AirspaceFlightPlanProvider.h
 * Create and maintain a flight plan
 */

17 18 19
#include "AirspaceAdvisoryProvider.h"
#include "QmlObjectListModel.h"

Gus Grubba's avatar
Gus Grubba committed
20
#include <QObject>
21
#include <QDateTime>
Gus Grubba's avatar
Gus Grubba committed
22
#include <QAbstractListModel>
23
#include <QDebug>
Gus Grubba's avatar
Gus Grubba committed
24

25
class PlanMasterController;
Gus Grubba's avatar
Gus Grubba committed
26
class AirspaceFlightInfo;
Gus Grubba's avatar
Gus Grubba committed
27

Gus Grubba's avatar
Gus Grubba committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
//-----------------------------------------------------------------------------
class AirspaceFlightAuthorization : public QObject
{
    Q_OBJECT
public:
    AirspaceFlightAuthorization                     (QObject *parent = nullptr);

    enum AuthorizationStatus {
        Accepted,
        Rejected,
        Pending,
        AcceptedOnSubmission,
        RejectedOnSubmission,
        Unknown
    };

    Q_ENUM(AuthorizationStatus)

    Q_PROPERTY(QString              name            READ name           CONSTANT)
    Q_PROPERTY(QString              id              READ id             CONSTANT)
    Q_PROPERTY(AuthorizationStatus  status          READ status         CONSTANT)
    Q_PROPERTY(QString              message         READ message        CONSTANT)

    virtual QString                 name            () = 0;
    virtual QString                 id              () = 0;
    virtual AuthorizationStatus     status          () = 0;
    virtual QString                 message         () = 0;

};


Gus Grubba's avatar
Gus Grubba committed
59 60 61 62 63
//-----------------------------------------------------------------------------
class AirspaceFlightInfo : public QObject
{
    Q_OBJECT
public:
Gus Grubba's avatar
Gus Grubba committed
64
    AirspaceFlightInfo                              (QObject *parent = nullptr);
Gus Grubba's avatar
Gus Grubba committed
65

Gus Grubba's avatar
Gus Grubba committed
66 67 68 69 70 71
    Q_PROPERTY(QString              flightID        READ flightID       CONSTANT)
    Q_PROPERTY(QString              flightPlanID    READ flightPlanID   CONSTANT)
    Q_PROPERTY(QString              createdTime     READ createdTime    CONSTANT)
    Q_PROPERTY(QString              startTime       READ startTime      CONSTANT)
    Q_PROPERTY(QString              endTime         READ endTime        CONSTANT)
    Q_PROPERTY(QGeoCoordinate       takeOff         READ takeOff        CONSTANT)
72 73
    Q_PROPERTY(QVariantList         boundingBox     READ boundingBox    CONSTANT)
    Q_PROPERTY(bool                 active          READ active         NOTIFY activeChanged)
Gus Grubba's avatar
Gus Grubba committed
74 75 76 77 78

    virtual QString                 flightID        () = 0;
    virtual QString                 flightPlanID    () = 0;
    virtual QString                 createdTime     () = 0;
    virtual QString                 startTime       () = 0;
79
    virtual QDateTime               qStartTime      () = 0;
Gus Grubba's avatar
Gus Grubba committed
80 81
    virtual QString                 endTime         () = 0;
    virtual QGeoCoordinate          takeOff         () = 0;
82 83
    virtual QVariantList            boundingBox     () = 0;
    virtual bool                    active          () = 0;
Gus Grubba's avatar
Gus Grubba committed
84 85

signals:
86
    void    activeChanged                           ();
Gus Grubba's avatar
Gus Grubba committed
87 88
};

Gus Grubba's avatar
Gus Grubba committed
89 90 91 92 93 94 95 96 97 98
//-----------------------------------------------------------------------------
class AirspaceFlightModel : public QAbstractListModel
{
    Q_OBJECT
public:

    enum QGCLogModelRoles {
        ObjectRole = Qt::UserRole + 1
    };

Gus Grubba's avatar
Gus Grubba committed
99
    AirspaceFlightModel         (QObject *parent = 0);
Gus Grubba's avatar
Gus Grubba committed
100 101

    Q_PROPERTY(int count READ count NOTIFY countChanged)
Gus Grubba's avatar
Gus Grubba committed
102 103

    Q_INVOKABLE AirspaceFlightInfo* get                 (int index);
104
    Q_INVOKABLE int                 findFlightID        (QString flightID);
Gus Grubba's avatar
Gus Grubba committed
105

106
    int         count           () const;
Gus Grubba's avatar
Gus Grubba committed
107
    void        append          (AirspaceFlightInfo *entry);
108
    void        remove          (const QString& flightID);
Gus Grubba's avatar
Gus Grubba committed
109
    void        remove          (int index);
110 111
    void        clear           ();
    void        sortStartFlight ();
Gus Grubba's avatar
Gus Grubba committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

    AirspaceFlightInfo*
                operator[]      (int i);

    int         rowCount        (const QModelIndex & parent = QModelIndex()) const;
    QVariant    data            (const QModelIndex & index, int role = Qt::DisplayRole) const;

signals:
    void        countChanged    ();

protected:
    QHash<int, QByteArray> roleNames() const;
private:
    QList<AirspaceFlightInfo*> _flightEntries;
};

Gus Grubba's avatar
Gus Grubba committed
128 129 130 131 132 133 134
//-----------------------------------------------------------------------------
class AirspaceFlightPlanProvider : public QObject
{
    Q_OBJECT
public:

    enum PermitStatus {
135
        PermitNone = 0,     //-- No flght plan
Gus Grubba's avatar
Gus Grubba committed
136 137 138
        PermitPending,
        PermitAccepted,
        PermitRejected,
139
        PermitNotRequired,
Gus Grubba's avatar
Gus Grubba committed
140 141 142 143
    };

    Q_ENUM(PermitStatus)

144
    AirspaceFlightPlanProvider                      (QObject *parent = nullptr);
Gus Grubba's avatar
Gus Grubba committed
145

Gus Grubba's avatar
Gus Grubba committed
146
    ///< Flight Planning and Filing
147
    Q_PROPERTY(QDateTime            flightStartTime         READ flightStartTime    WRITE  setFlightStartTime   NOTIFY flightStartTimeChanged)      ///< Start of flight
148 149
    Q_PROPERTY(int                  flightDuration          READ flightDuration     WRITE  setFlightDuration    NOTIFY flightDurationChanged)       ///< Flight Duration
    Q_PROPERTY(bool                 flightStartsNow         READ flightStartsNow    WRITE  setFlightStartsNow   NOTIFY flightStartsNowChanged)
Gus Grubba's avatar
Gus Grubba committed
150 151 152

    ///< Flight Briefing
    Q_PROPERTY(PermitStatus         flightPermitStatus      READ flightPermitStatus                             NOTIFY flightPermitStatusChanged)   ///< State of flight permission
153 154
    Q_PROPERTY(bool                 valid                   READ valid                                          NOTIFY advisoryChanged)
    Q_PROPERTY(QmlObjectListModel*  advisories              READ advisories                                     NOTIFY advisoryChanged)
Gus Grubba's avatar
Gus Grubba committed
155
    Q_PROPERTY(QmlObjectListModel*  ruleSets                READ ruleSets                                       NOTIFY advisoryChanged)
156
    Q_PROPERTY(QGCGeoBoundingCube*  missionArea             READ missionArea                                    NOTIFY missionAreaChanged)
157
    Q_PROPERTY(AirspaceAdvisoryProvider::AdvisoryColor airspaceColor READ airspaceColor                         NOTIFY advisoryChanged)
158 159 160 161
    Q_PROPERTY(QmlObjectListModel*  rulesViolation          READ rulesViolation                                 NOTIFY rulesChanged)
    Q_PROPERTY(QmlObjectListModel*  rulesInfo               READ rulesInfo                                      NOTIFY rulesChanged)
    Q_PROPERTY(QmlObjectListModel*  rulesReview             READ rulesReview                                    NOTIFY rulesChanged)
    Q_PROPERTY(QmlObjectListModel*  rulesFollowing          READ rulesFollowing                                 NOTIFY rulesChanged)
162
    Q_PROPERTY(QmlObjectListModel*  briefFeatures           READ briefFeatures                                  NOTIFY rulesChanged)
Gus Grubba's avatar
Gus Grubba committed
163 164 165
    Q_PROPERTY(QmlObjectListModel*  authorizations          READ authorizations                                 NOTIFY rulesChanged)

    ///< Flight Management
Gus Grubba's avatar
Gus Grubba committed
166
    Q_PROPERTY(AirspaceFlightModel* flightList              READ flightList                                     NOTIFY flightListChanged)
Gus Grubba's avatar
Gus Grubba committed
167
    Q_PROPERTY(bool                 loadingFlightList       READ loadingFlightList                              NOTIFY loadingFlightListChanged)
168
    Q_PROPERTY(bool                 dirty                   READ dirty                  WRITE setDirty          NOTIFY dirtyChanged)
169

Gus Grubba's avatar
Gus Grubba committed
170
    //-- TODO: This will submit the current flight plan in memory.
Gus Grubba's avatar
Gus Grubba committed
171 172 173
    Q_INVOKABLE virtual void    submitFlightPlan            () = 0;
    Q_INVOKABLE virtual void    updateFlightPlan            () = 0;
    Q_INVOKABLE virtual void    loadFlightList              (QDateTime startTime, QDateTime endTime) = 0;
174
    Q_INVOKABLE virtual void    endFlight                   (QString flighID) = 0;
175

176
    virtual PermitStatus        flightPermitStatus  () const { return PermitNone; }
177
    virtual QDateTime           flightStartTime     () const = 0;
178 179
    virtual int                 flightDuration      () const = 0;
    virtual bool                flightStartsNow     () const = 0;
180
    virtual QGCGeoBoundingCube* missionArea         () = 0;
Gus Grubba's avatar
Gus Grubba committed
181 182 183 184
    virtual bool                valid               () = 0;                     ///< Current advisory list is valid
    virtual QmlObjectListModel* advisories          () = 0;                     ///< List of AirspaceAdvisory
    virtual QmlObjectListModel* ruleSets            () = 0;                     ///< List of AirspaceRuleSet
    virtual AirspaceAdvisoryProvider::AdvisoryColor  airspaceColor () = 0;      ///< Aispace overall color
Gus Grubba's avatar
Gus Grubba committed
185

186 187 188 189
    virtual QmlObjectListModel* rulesViolation      () = 0;                     ///< List of AirspaceRule in violation
    virtual QmlObjectListModel* rulesInfo           () = 0;                     ///< List of AirspaceRule need more information
    virtual QmlObjectListModel* rulesReview         () = 0;                     ///< List of AirspaceRule should review
    virtual QmlObjectListModel* rulesFollowing      () = 0;                     ///< List of AirspaceRule following
190
    virtual QmlObjectListModel* briefFeatures       () = 0;                     ///< List of AirspaceRule in violation
Gus Grubba's avatar
Gus Grubba committed
191
    virtual QmlObjectListModel* authorizations      () = 0;                     ///< List of AirspaceFlightAuthorization
Gus Grubba's avatar
Gus Grubba committed
192
    virtual AirspaceFlightModel*flightList          () = 0;                     ///< List of AirspaceFlightInfo
Gus Grubba's avatar
Gus Grubba committed
193
    virtual bool                loadingFlightList   () = 0;
194
    virtual bool                dirty               () { return _dirty; }
195

196
    virtual void                setFlightStartTime  (QDateTime start) = 0;
197 198
    virtual void                setFlightDuration   (int seconds) = 0;
    virtual void                setFlightStartsNow  (bool now) = 0;
199
    virtual void                startFlightPlanning (PlanMasterController* planController) = 0;
200
    virtual void                setDirty            (bool dirt) { if(_dirty != dirt) { _dirty = dirt; emit dirtyChanged(); }}
Gus Grubba's avatar
Gus Grubba committed
201 202

signals:
203 204
    void flightPermitStatusChanged                  ();
    void flightStartTimeChanged                     ();
205 206
    void flightStartsNowChanged                     ();
    void flightDurationChanged                      ();
207
    void advisoryChanged                            ();
208
    void missionAreaChanged                         ();
209
    void rulesChanged                               ();
Gus Grubba's avatar
Gus Grubba committed
210
    void flightListChanged                          ();
Gus Grubba's avatar
Gus Grubba committed
211
    void loadingFlightListChanged                   ();
212 213 214 215
    void dirtyChanged                               ();

protected:
    bool _dirty = false;
Gus Grubba's avatar
Gus Grubba committed
216
};