MissionController.h 5.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

#ifndef MissionController_H
#define MissionController_H

#include <QObject>

#include "QmlObjectListModel.h"
#include "Vehicle.h"
31
#include "QGCLoggingCategory.h"
32
#include "MavlinkQmlSingleton.h"
33
#include "VisualMissionItem.h"
34 35

Q_DECLARE_LOGGING_CATEGORY(MissionControllerLog)
36 37 38 39

class MissionController : public QObject
{
    Q_OBJECT
40

41 42 43 44
public:
    MissionController(QObject* parent = NULL);
    ~MissionController();

45 46 47 48 49
    Q_PROPERTY(QmlObjectListModel*  visualItems         READ visualItems                                NOTIFY visualItemsChanged)
    Q_PROPERTY(QmlObjectListModel*  complexVisualItems  READ complexVisualItems                         NOTIFY complexVisualItemsChanged)
    Q_PROPERTY(QmlObjectListModel*  waypointLines       READ waypointLines                              NOTIFY waypointLinesChanged)
    Q_PROPERTY(bool                 autoSync            READ autoSync               WRITE setAutoSync   NOTIFY autoSyncChanged)
    Q_PROPERTY(bool                 syncInProgress      READ syncInProgress                             NOTIFY syncInProgressChanged)
50

51
    Q_INVOKABLE void start(bool editMode);
52 53
    Q_INVOKABLE void getMissionItems(void);
    Q_INVOKABLE void sendMissionItems(void);
Don Gagne's avatar
Don Gagne committed
54 55 56 57
    Q_INVOKABLE void loadMissionFromFilePicker(void);
    Q_INVOKABLE void loadMissionFromFile(const QString& filename);
    Q_INVOKABLE void saveMissionToFilePicker(void);
    Q_INVOKABLE void saveMissionToFile(const QString& filename);
58
    Q_INVOKABLE void removeMissionItem(int index);
59
    Q_INVOKABLE void removeAllMissionItems(void);
60

61 62 63
    /// Add a new simple mission item to the list
    ///     @param i: index to insert at
    /// @return Sequence number for new item
64 65
    Q_INVOKABLE int insertSimpleMissionItem(QGeoCoordinate coordinate, int i);

66 67 68
    /// Add a new complex mission item to the list
    ///     @param i: index to insert at
    /// @return Sequence number for new item
69
    Q_INVOKABLE int insertComplexMissionItem(QGeoCoordinate coordinate, int i);
70

71 72
    // Property accessors

73 74 75 76
    QmlObjectListModel* visualItems         (void) { return _visualItems; }
    QmlObjectListModel* complexVisualItems  (void) { return _complexItems; }
    QmlObjectListModel* waypointLines       (void) { return &_waypointLines; }

77 78
    bool autoSync(void) { return _autoSync; }
    void setAutoSync(bool autoSync);
79
    bool syncInProgress(void);
80

81 82
    static const char* jsonSimpleItemsKey;  ///< Key for simple items in a json file

83
signals:
84 85
    void visualItemsChanged(void);
    void complexVisualItemsChanged(void);
86
    void waypointLinesChanged(void);
87
    void autoSyncChanged(bool autoSync);
88
    void newItemsFromVehicle(void);
89
    void syncInProgressChanged(bool syncInProgress);
90

91
private slots:
92
    void _newMissionItemsAvailableFromVehicle();
93
    void _itemCoordinateChanged(const QGeoCoordinate& coordinate);
94
    void _itemCommandChanged(void);
95
    void _activeVehicleChanged(Vehicle* activeVehicle);
96 97 98 99
    void _activeVehicleHomePositionAvailableChanged(bool homePositionAvailable);
    void _activeVehicleHomePositionChanged(const QGeoCoordinate& homePosition);
    void _dirtyChanged(bool dirty);
    void _inProgressChanged(bool inProgress);
100
    void _currentMissionItemChanged(int sequenceNumber);
101
    void _recalcWaypointLines(void);
102 103

private:
104
    void _recalcSequence(void);
105 106
    void _recalcChildItems(void);
    void _recalcAll(void);
107 108 109 110
    void _initAllVisualItems(void);
    void _deinitAllVisualItems(void);
    void _initVisualItem(VisualMissionItem* item);
    void _deinitVisualItem(VisualMissionItem* item);
111
    void _autoSyncSend(void);
Don Gagne's avatar
Don Gagne committed
112
    void _setupActiveVehicle(Vehicle* activeVehicle, bool forceLoadFromVehicle);
113
    void _calcPrevWaypointValues(double homeAlt, VisualMissionItem* currentItem, VisualMissionItem* prevItem, double* azimuth, double* distance, double* altDifference);
114 115
    bool _findLastAltitude(double* lastAltitude);
    bool _findLastAcceptanceRadius(double* lastAcceptanceRadius);
116
    void _addPlannedHomePosition(QmlObjectListModel* visualItems, bool addToCenter);
117 118
    double _normalizeLat(double lat);
    double _normalizeLon(double lon);
119
    bool _loadJsonMissionFile(const QByteArray& bytes, QmlObjectListModel* visualItems, QmlObjectListModel* complexItems, QString& errorString);
120
    bool _loadTextMissionFile(QTextStream& stream, QmlObjectListModel* visualItems, QString& errorString);
121
    int _nextSequenceNumber(void);
122 123

private:
124
    bool                _editMode;
125 126
    QmlObjectListModel* _visualItems;
    QmlObjectListModel* _complexItems;
127 128
    QmlObjectListModel  _waypointLines;
    Vehicle*            _activeVehicle;
129
    bool                _autoSync;
130
    bool                _firstItemsFromVehicle;
131 132 133
    bool                _missionItemsRequested;
    bool                _queuedSend;

134 135 136 137
    static const char*  _settingsGroup;
    static const char*  _jsonVersionKey;
    static const char*  _jsonGroundStationKey;
    static const char*  _jsonMavAutopilotKey;
138
    static const char*  _jsonComplexItemsKey;
139
    static const char*  _jsonPlannedHomePositionKey;
140 141 142
};

#endif