MissionEditorController.h 4.45 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

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/>.

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

24 25 26 27
#ifndef MissionEditorController_H
#define MissionEditorController_H

#include <QObject>
Don Gagne's avatar
Don Gagne committed
28 29

#include "QmlObjectListModel.h"
30
#include "Vehicle.h"
Don Gagne's avatar
Don Gagne committed
31

32
class MissionEditorController : public QObject
Don Gagne's avatar
Don Gagne committed
33 34 35 36
{
    Q_OBJECT
    
public:
37
    MissionEditorController(QObject* parent = NULL);
38
    ~MissionEditorController();
Don Gagne's avatar
Don Gagne committed
39

40 41 42 43 44 45
    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)
Don Gagne's avatar
Don Gagne committed
46
    
47
    Q_INVOKABLE int addMissionItem(QGeoCoordinate coordinate);
Don Gagne's avatar
Don Gagne committed
48
    Q_INVOKABLE void getMissionItems(void);
49
    Q_INVOKABLE void sendMissionItems(void);
Don Gagne's avatar
Don Gagne committed
50 51
    Q_INVOKABLE void loadMissionFromFile(void);
    Q_INVOKABLE void saveMissionToFile(void);
52
    Q_INVOKABLE void removeMissionItem(int index);
53
    Q_INVOKABLE void deleteCurrentMissionItem(void);
Don Gagne's avatar
Don Gagne committed
54 55 56

    // Property accessors
    
57
    QmlObjectListModel* missionItems(void);
58
    QmlObjectListModel* waypointLines(void) { return &_waypointLines; }
Don Gagne's avatar
Don Gagne committed
59
    bool canEdit(void) { return _canEdit; }
60 61
    bool liveHomePositionAvailable(void) { return _liveHomePositionAvailable; }
    QGeoCoordinate liveHomePosition(void) { return _liveHomePosition; }
62 63
    bool autoSync(void) { return _autoSync; }
    void setAutoSync(bool autoSync);
64

Don Gagne's avatar
Don Gagne committed
65 66
signals:
    void missionItemsChanged(void);
Don Gagne's avatar
Don Gagne committed
67
    void canEditChanged(bool canEdit);
68
    void waypointLinesChanged(void);
69 70
    void liveHomePositionAvailableChanged(bool homePositionAvailable);
    void liveHomePositionChanged(const QGeoCoordinate& homePosition);
71
    void autoSyncChanged(bool autoSync);
Don Gagne's avatar
Don Gagne committed
72 73 74
    
private slots:
    void _newMissionItemsAvailable();
Don Gagne's avatar
Don Gagne committed
75 76
    void _itemCoordinateChanged(const QGeoCoordinate& coordinate);
    void _itemCommandChanged(MavlinkQmlSingleton::Qml_MAV_CMD command);
77 78 79
    void _activeVehicleChanged(Vehicle* activeVehicle);
    void _activeVehicleHomePositionAvailableChanged(bool homePositionAvailable);
    void _activeVehicleHomePositionChanged(const QGeoCoordinate& homePosition);
80 81
    void _dirtyChanged(bool dirty);
    void _inProgressChanged(bool inProgress);
Don Gagne's avatar
Don Gagne committed
82

83
private:
Don Gagne's avatar
Don Gagne committed
84 85 86 87 88 89 90 91
    void _recalcSequence(void);
    void _recalcWaypointLines(void);
    void _recalcChildItems(void);
    void _recalcAll(void);
    void _initAllMissionItems(void);
    void _deinitAllMissionItems(void);
    void _initMissionItem(MissionItem* item);
    void _deinitMissionItem(MissionItem* item);
92
    void _autoSyncSend(void);
Don Gagne's avatar
Don Gagne committed
93

Don Gagne's avatar
Don Gagne committed
94
private:
Don Gagne's avatar
Don Gagne committed
95
    QmlObjectListModel* _missionItems;
96
    QmlObjectListModel  _waypointLines;
Don Gagne's avatar
Don Gagne committed
97
    bool                _canEdit;           ///< true: UI can edit these items, false: can't edit, can only send to vehicle or save
98 99 100
    Vehicle*            _activeVehicle;
    bool                _liveHomePositionAvailable;
    QGeoCoordinate      _liveHomePosition;
101 102
    bool                _autoSync;
    bool                _firstMissionItemSync;
103
    bool                _missionItemsRequested;
104
    bool                _queuedSend;
105

Don Gagne's avatar
Don Gagne committed
106 107 108 109
    static const char* _settingsGroup;
};

#endif