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

#pragma once

#include <QObject>

#include "MissionController.h"
#include "GeoFenceController.h"
#include "RallyPointController.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"
DonLakeFlyer's avatar
DonLakeFlyer committed
19
#include "QGCLoggingCategory.h"
DonLakeFlyer's avatar
DonLakeFlyer committed
20
#include "QmlObjectListModel.h"
DonLakeFlyer's avatar
DonLakeFlyer committed
21 22

Q_DECLARE_LOGGING_CATEGORY(PlanMasterControllerLog)
23 24 25 26 27 28 29

/// Master controller for mission, fence, rally
class PlanMasterController : public QObject
{
    Q_OBJECT
    
public:
30
    PlanMasterController(QObject* parent = nullptr);
31 32 33 34 35
#ifdef QT_DEBUG
    // Used by test code to create master controll with specific firmware/vehicle type
    PlanMasterController(MAV_AUTOPILOT firmwareType, MAV_TYPE vehicleType, QObject* parent = nullptr);
#endif

36
    ~PlanMasterController();
37

38
    Q_PROPERTY(bool                     flyView                 MEMBER _flyView)
39 40
    Q_PROPERTY(Vehicle*                 controllerVehicle       READ controllerVehicle                      CONSTANT)                       ///< Offline controller vehicle
    Q_PROPERTY(Vehicle*                 managerVehicle          READ managerVehicle                         NOTIFY managerVehicleChanged)   ///< Either active vehicle or _controllerVehicle if no active vehicle
DonLakeFlyer's avatar
DonLakeFlyer committed
41 42 43 44 45 46 47 48 49 50 51 52 53
    Q_PROPERTY(MissionController*       missionController       READ missionController                      CONSTANT)
    Q_PROPERTY(GeoFenceController*      geoFenceController      READ geoFenceController                     CONSTANT)
    Q_PROPERTY(RallyPointController*    rallyPointController    READ rallyPointController                   CONSTANT)
    Q_PROPERTY(bool                     offline                 READ offline                                NOTIFY offlineChanged)          ///< true: controller is not connected to an active vehicle
    Q_PROPERTY(bool                     containsItems           READ containsItems                          NOTIFY containsItemsChanged)    ///< true: Elemement is non-empty
    Q_PROPERTY(bool                     syncInProgress          READ syncInProgress                         NOTIFY syncInProgressChanged)   ///< true: Information is currently being saved/sent, false: no active save/send in progress
    Q_PROPERTY(bool                     dirty                   READ dirty                  WRITE setDirty  NOTIFY dirtyChanged)            ///< true: Unsaved/sent changes are present, false: no changes since last save/send
    Q_PROPERTY(QString                  fileExtension           READ fileExtension                          CONSTANT)                       ///< File extension for missions
    Q_PROPERTY(QString                  kmlFileExtension        READ kmlFileExtension                       CONSTANT)
    Q_PROPERTY(QString                  currentPlanFile         READ currentPlanFile                        NOTIFY currentPlanFileChanged)
    Q_PROPERTY(QStringList              loadNameFilters         READ loadNameFilters                        CONSTANT)                       ///< File filter list loading plan files
    Q_PROPERTY(QStringList              saveNameFilters         READ saveNameFilters                        CONSTANT)                       ///< File filter list saving plan files
    Q_PROPERTY(QmlObjectListModel*      planCreators            MEMBER _planCreators                        NOTIFY planCreatorsChanged)
54 55

    /// Should be called immediately upon Component.onCompleted.
56
    Q_INVOKABLE void start(void);
57 58

    /// Starts the controller using a single static active vehicle. Will not track global active vehicle changes.
59 60
    ///     @param deleteWhenSendCmplete The PlanMasterController object should be deleted after the first send is completed.
    Q_INVOKABLE void startStaticActiveVehicle(Vehicle* vehicle, bool deleteWhenSendCompleted = false);
61

62 63 64 65
    /// Determines if the plan has all information needed to be saved or sent to the vehicle.
    /// IMPORTANT NOTE: The return value is a VisualMissionItem::ReadForSaveState value. It is an int here to work around
    /// a nightmare of circular header dependency problems.
    Q_INVOKABLE int readyForSaveState(void) const { return _missionController.readyForSaveState(); }
66 67 68 69 70 71 72 73 74

    /// Sends a plan to the specified file
    ///     @param[in] vehicle Vehicle we are sending a plan to
    ///     @param[in] filename Plan file to load
    static void sendPlanToVehicle(Vehicle* vehicle, const QString& filename);

    Q_INVOKABLE void loadFromVehicle(void);
    Q_INVOKABLE void sendToVehicle(void);
    Q_INVOKABLE void loadFromFile(const QString& filename);
75
    Q_INVOKABLE void saveToCurrent();
76
    Q_INVOKABLE void saveToFile(const QString& filename);
77
    Q_INVOKABLE void saveToKml(const QString& filename);
78 79 80 81 82 83 84
    Q_INVOKABLE void removeAll(void);                       ///< Removes all from controller only, synce required to remove from vehicle
    Q_INVOKABLE void removeAllFromVehicle(void);            ///< Removes all from vehicle and controller

    MissionController*      missionController(void)     { return &_missionController; }
    GeoFenceController*     geoFenceController(void)    { return &_geoFenceController; }
    RallyPointController*   rallyPointController(void)  { return &_rallyPointController; }

85
    bool        offline         (void) const { return _offline; }
86
    bool        containsItems   (void) const;
87
    bool        syncInProgress  (void) const;
88 89 90
    bool        dirty           (void) const;
    void        setDirty        (bool dirty);
    QString     fileExtension   (void) const;
91
    QString     kmlFileExtension(void) const;
92
    QString     currentPlanFile (void) const { return _currentPlanFile; }
93 94
    QStringList loadNameFilters (void) const;
    QStringList saveNameFilters (void) const;
95
    bool        isEmpty         (void) const;
96

97 98
    void        setFlyView(bool flyView) { _flyView = flyView; }

Gus Grubba's avatar
Gus Grubba committed
99 100
    QJsonDocument saveToJson    ();

101 102
    Vehicle* controllerVehicle(void) { return _controllerVehicle; }
    Vehicle* managerVehicle(void) { return _managerVehicle; }
103

104 105 106 107 108 109
    static const int    kPlanFileVersion;
    static const char*  kPlanFileType;
    static const char*  kJsonMissionObjectKey;
    static const char*  kJsonGeoFenceObjectKey;
    static const char*  kJsonRallyPointsObjectKey;

110 111
signals:
    void containsItemsChanged   (bool containsItems);
112
    void syncInProgressChanged  (void);
113
    void dirtyChanged           (bool dirty);
114
    void offlineChanged  		(bool offlineEditing);
115
    void currentPlanFileChanged ();
DonLakeFlyer's avatar
DonLakeFlyer committed
116
    void planCreatorsChanged    (QmlObjectListModel* planCreators);
117
    void managerVehicleChanged  (Vehicle* managerVehicle);
118 119

private slots:
DonLakeFlyer's avatar
DonLakeFlyer committed
120 121 122 123 124 125 126 127
    void _activeVehicleChanged      (Vehicle* activeVehicle);
    void _loadMissionComplete       (void);
    void _loadGeoFenceComplete      (void);
    void _loadRallyPointsComplete   (void);
    void _sendMissionComplete       (void);
    void _sendGeoFenceComplete      (void);
    void _sendRallyPointsComplete   (void);
    void _updatePlanCreatorsList    (void);
128
#if defined(QGC_AIRMAP_ENABLED)
DonLakeFlyer's avatar
DonLakeFlyer committed
129
    void _startFlightPlanning       (void);
130
#endif
131 132

private:
133
    void _commonInit                (void);
DonLakeFlyer's avatar
DonLakeFlyer committed
134 135
    void _showPlanFromManagerVehicle(void);

136 137 138 139 140
    MultiVehicleManager*    _multiVehicleMgr =          nullptr;
    Vehicle*                _controllerVehicle =        nullptr;    ///< Offline controller vehicle
    Vehicle*                _managerVehicle =           nullptr;    ///< Either active vehicle or _controllerVehicle if none
    bool                    _flyView =                  true;
    bool                    _offline =                  true;
141 142 143
    MissionController       _missionController;
    GeoFenceController      _geoFenceController;
    RallyPointController    _rallyPointController;
144 145 146 147
    bool                    _loadGeoFence =             false;
    bool                    _loadRallyPoints =          false;
    bool                    _sendGeoFence =             false;
    bool                    _sendRallyPoints =          false;
148
    QString                 _currentPlanFile;
149 150
    bool                    _deleteWhenSendCompleted =  false;
    QmlObjectListModel*     _planCreators =             nullptr;
151
};