PlanMasterController.h 6.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#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 20 21
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(PlanMasterControllerLog)
22 23 24 25 26 27 28 29 30 31 32 33 34 35

/// Master controller for mission, fence, rally
class PlanMasterController : public QObject
{
    Q_OBJECT
    
public:
    PlanMasterController(QObject* parent = NULL);
    ~PlanMasterController();
    
    Q_PROPERTY(MissionController*       missionController       READ missionController      CONSTANT)
    Q_PROPERTY(GeoFenceController*      geoFenceController      READ geoFenceController     CONSTANT)
    Q_PROPERTY(RallyPointController*    rallyPointController    READ rallyPointController   CONSTANT)

36
    Q_PROPERTY(Vehicle*     controllerVehicle   MEMBER _controllerVehicle               CONSTANT)
37
    Q_PROPERTY(bool         offline             READ offline                            NOTIFY offlineChanged)          ///< true: controller is not connected to an active vehicle
38 39 40
    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
Patrick José Pereira's avatar
Patrick José Pereira committed
41
    Q_PROPERTY(QString      fileExtension       READ fileExtension                      CONSTANT)                       ///< File extension for missions
42
    Q_PROPERTY(QString      kmlFileExtension    READ kmlFileExtension                   CONSTANT)
43
    Q_PROPERTY(QString      currentPlanFile     READ currentPlanFile                    NOTIFY currentPlanFileChanged)
44
    ///< kml file extension for missions
45 46
    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
47 48

    /// Should be called immediately upon Component.onCompleted.
49
    Q_INVOKABLE void start(bool flyView);
50 51

    /// Starts the controller using a single static active vehicle. Will not track global active vehicle changes.
52 53 54 55 56
    Q_INVOKABLE void startStaticActiveVehicle(Vehicle* vehicle);

    /// Determines if the plan has all data needed to be saved or sent to the vehicle. Currently the only case where this
    /// would return false is when it is still waiting on terrain data to determine correct altitudes.
    Q_INVOKABLE bool readyForSaveSend(void) const { return _missionController.readyForSaveSend(); }
57 58 59 60 61 62 63 64 65

    /// 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);
66
    Q_INVOKABLE void saveToCurrent();
67
    Q_INVOKABLE void saveToFile(const QString& filename);
68
    Q_INVOKABLE void saveToKml(const QString& filename);
69 70 71 72 73 74 75
    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; }

76
    bool        offline         (void) const { return _offline; }
77
    bool        containsItems   (void) const;
78
    bool        syncInProgress  (void) const;
79 80 81
    bool        dirty           (void) const;
    void        setDirty        (bool dirty);
    QString     fileExtension   (void) const;
82
    QString     kmlFileExtension(void) const;
83
    QString     currentPlanFile (void) const { return _currentPlanFile; }
84 85 86
    QStringList loadNameFilters (void) const;
    QStringList saveNameFilters (void) const;

Gus Grubba's avatar
Gus Grubba committed
87 88
    QJsonDocument saveToJson    ();

89 90
    Vehicle* controllerVehicle(void) { return _controllerVehicle; }
    Vehicle* managerVehicle(void) { return _managerVehicle; }
91

92 93 94 95 96 97
    static const int    kPlanFileVersion;
    static const char*  kPlanFileType;
    static const char*  kJsonMissionObjectKey;
    static const char*  kJsonGeoFenceObjectKey;
    static const char*  kJsonRallyPointsObjectKey;

98 99
signals:
    void containsItemsChanged   (bool containsItems);
100
    void syncInProgressChanged  (void);
101
    void dirtyChanged           (bool dirty);
102
    void offlineChanged  		(bool offlineEditing);
103
    void currentPlanFileChanged ();
104 105 106

private slots:
    void _activeVehicleChanged(Vehicle* activeVehicle);
DonLakeFlyer's avatar
DonLakeFlyer committed
107 108 109 110 111 112
    void _loadMissionComplete(void);
    void _loadGeoFenceComplete(void);
    void _loadRallyPointsComplete(void);
    void _sendMissionComplete(void);
    void _sendGeoFenceComplete(void);
    void _sendRallyPointsComplete(void);
113 114

private:
DonLakeFlyer's avatar
DonLakeFlyer committed
115 116
    void _showPlanFromManagerVehicle(void);

117
    MultiVehicleManager*    _multiVehicleMgr;
118 119
    Vehicle*                _controllerVehicle; ///< Offline controller vehicle
    Vehicle*                _managerVehicle;    ///< Either active vehicle or _controllerVehicle if none
120
    bool                    _flyView;
121
    bool                    _offline;
122 123 124
    MissionController       _missionController;
    GeoFenceController      _geoFenceController;
    RallyPointController    _rallyPointController;
125 126 127 128
    bool                    _loadGeoFence;
    bool                    _loadRallyPoints;
    bool                    _sendGeoFence;
    bool                    _sendRallyPoints;
129
    QString                 _currentPlanFile;
130 131

};