MissionController.h 4.86 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 32 33
#include "QGCLoggingCategory.h"

Q_DECLARE_LOGGING_CATEGORY(MissionControllerLog)
34 35 36 37

class MissionController : public QObject
{
    Q_OBJECT
38

39 40 41 42
public:
    MissionController(QObject* parent = NULL);
    ~MissionController();

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    Q_PROPERTY(QmlObjectListModel*  missionItems                READ missionItems                   NOTIFY missionItemsChanged)
    Q_PROPERTY(QmlObjectListModel*  waypointLines               READ waypointLines                  NOTIFY waypointLinesChanged)
    Q_PROPERTY(bool                 canEdit                     READ canEdit                        NOTIFY canEditChanged)
    Q_PROPERTY(bool                 liveHomePositionAvailable   READ liveHomePositionAvailable      NOTIFY liveHomePositionAvailableChanged)
    Q_PROPERTY(QGeoCoordinate       liveHomePosition            READ liveHomePosition               NOTIFY liveHomePositionChanged)
    Q_PROPERTY(bool                 autoSync                    READ autoSync   WRITE setAutoSync   NOTIFY autoSyncChanged)

    Q_INVOKABLE void start(bool editMode)    ;
    Q_INVOKABLE int addMissionItem(QGeoCoordinate coordinate);
    Q_INVOKABLE void getMissionItems(void);
    Q_INVOKABLE void sendMissionItems(void);
    Q_INVOKABLE void loadMissionFromFile(void);
    Q_INVOKABLE void saveMissionToFile(void);
    Q_INVOKABLE void removeMissionItem(int index);
    Q_INVOKABLE void deleteCurrentMissionItem(void);
58

59 60
    // Property accessors

61 62 63 64 65 66 67
    QmlObjectListModel* missionItems(void);
    QmlObjectListModel* waypointLines(void) { return &_waypointLines; }
    bool canEdit(void) { return _canEdit; }
    bool liveHomePositionAvailable(void) { return _liveHomePositionAvailable; }
    QGeoCoordinate liveHomePosition(void) { return _liveHomePosition; }
    bool autoSync(void) { return _autoSync; }
    void setAutoSync(bool autoSync);
68

69 70
signals:
    void missionItemsChanged(void);
71
    void canEditChanged(bool canEdit);
72
    void waypointLinesChanged(void);
73 74 75 76
    void liveHomePositionAvailableChanged(bool homePositionAvailable);
    void liveHomePositionChanged(const QGeoCoordinate& homePosition);
    void autoSyncChanged(bool autoSync);

77
private slots:
78
    void _newMissionItemsAvailableFromVehicle();
79
    void _itemCoordinateChanged(const QGeoCoordinate& coordinate);
80
    void _itemFrameChanged(int frame);
81
    void _itemCommandChanged(MavlinkQmlSingleton::Qml_MAV_CMD command);
82
    void _activeVehicleChanged(Vehicle* activeVehicle);
83 84 85 86
    void _activeVehicleHomePositionAvailableChanged(bool homePositionAvailable);
    void _activeVehicleHomePositionChanged(const QGeoCoordinate& homePosition);
    void _dirtyChanged(bool dirty);
    void _inProgressChanged(bool inProgress);
87 88

private:
89
    void _recalcSequence(void);
90 91 92 93
    void _recalcWaypointLines(void);
    void _recalcChildItems(void);
    void _recalcAll(void);
    void _initAllMissionItems(void);
94 95 96 97
    void _deinitAllMissionItems(void);
    void _initMissionItem(MissionItem* item);
    void _deinitMissionItem(MissionItem* item);
    void _autoSyncSend(void);
Don Gagne's avatar
Don Gagne committed
98 99
    void _setupMissionItems(bool loadFromVehicle, bool forceLoad);
    void _setupActiveVehicle(Vehicle* activeVehicle, bool forceLoadFromVehicle);
100
    double _calcDistance(bool homePositionValid, double homeAlt, MissionItem* item1, MissionItem* item2);
101 102

private:
103
    bool                _editMode;
104 105
    QmlObjectListModel* _missionItems;
    QmlObjectListModel  _waypointLines;
106
    bool                _canEdit;           ///< true: UI can edit these items, false: can't edit, can only send to vehicle or save
107
    Vehicle*            _activeVehicle;
108 109 110
    bool                _liveHomePositionAvailable;
    QGeoCoordinate      _liveHomePosition;
    bool                _autoSync;
111
    bool                _firstItemsFromVehicle;
112 113 114 115
    bool                _missionItemsRequested;
    bool                _queuedSend;

    static const char* _settingsGroup;
116 117 118
};

#endif