MissionItem.h 5.35 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 - 2014 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 MissionItem_H
#define MissionItem_H

#include <QObject>
#include <QString>
#include <QtQml>
#include <QTextStream>
31
#include <QJsonObject>
32 33 34 35 36 37 38 39 40
#include <QGeoCoordinate>

#include "QGCMAVLink.h"
#include "QGC.h"
#include "MavlinkQmlSingleton.h"
#include "QmlObjectListModel.h"
#include "Fact.h"
#include "QGCLoggingCategory.h"
#include "QmlObjectListModel.h"
Don Gagne's avatar
Don Gagne committed
41
#include "MissionCommands.h"
42

43 44 45 46 47 48 49 50
class ComplexMissionItem;
class SimpleMissionItem;
class MissionController;
#ifdef UNITTEST_BUILD
    class MissionItemTest;
#endif

// Represents a Mavlink mission command.
51 52 53 54 55
class MissionItem : public QObject
{
    Q_OBJECT
    
public:
56
    MissionItem(QObject* parent = NULL);
57

58
    MissionItem(int             sequenceNumber,
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
                MAV_CMD         command,
                MAV_FRAME       frame,
                double          param1,
                double          param2,
                double          param3,
                double          param4,
                double          param5,
                double          param6,
                double          param7,
                bool            autoContinue,
                bool            isCurrentItem,
                QObject*        parent = NULL);

    MissionItem(const MissionItem& other, QObject* parent = NULL);

    ~MissionItem();

    const MissionItem& operator=(const MissionItem& other);
    
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    MAV_CMD         command         (void) const { return (MAV_CMD)_commandFact.rawValue().toInt(); }
    bool            isCurrentItem   (void) const { return _isCurrentItem; }
    int             sequenceNumber  (void) const { return _sequenceNumber; }
    MAV_FRAME       frame           (void) const { return (MAV_FRAME)_frameFact.rawValue().toInt(); }
    bool            autoContinue    (void) const { return _autoContinueFact.rawValue().toBool(); }
    double          param1          (void) const { return _param1Fact.rawValue().toDouble(); }
    double          param2          (void) const { return _param2Fact.rawValue().toDouble(); }
    double          param3          (void) const { return _param3Fact.rawValue().toDouble(); }
    double          param4          (void) const { return _param4Fact.rawValue().toDouble(); }
    double          param5          (void) const { return _param5Fact.rawValue().toDouble(); }
    double          param6          (void) const { return _param6Fact.rawValue().toDouble(); }
    double          param7          (void) const { return _param7Fact.rawValue().toDouble(); }
    QGeoCoordinate  coordinate      (void) const;

    void setCommand         (MAV_CMD command);
    void setSequenceNumber  (int sequenceNumber);
    void setIsCurrentItem   (bool isCurrentItem);
    void setFrame           (MAV_FRAME frame);
    void setAutoContinue    (bool autoContinue);
    void setParam1          (double param1);
    void setParam2          (double param2);
    void setParam3          (double param3);
    void setParam4          (double param4);
    void setParam5          (double param5);
    void setParam6          (double param6);
    void setParam7          (double param7);
    void setCoordinate      (const QGeoCoordinate& coordinate);
105
    
106
    void save(QJsonObject& json) const;
107
    bool load(QTextStream &loadStream);
108
    bool load(const QJsonObject& json, QString& errorString);
109

110
    bool relativeAltitude(void) const { return frame() == MAV_FRAME_GLOBAL_RELATIVE_ALT; }
Don Gagne's avatar
Don Gagne committed
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
signals:
    void isCurrentItemChanged       (bool isCurrentItem);
    void sequenceNumberChanged      (int sequenceNumber);
    
private:
    int         _sequenceNumber;
    bool        _isCurrentItem;

    Fact    _autoContinueFact;
    Fact    _commandFact;
    Fact    _frameFact;
    Fact    _param1Fact;
    Fact    _param2Fact;
    Fact    _param3Fact;
    Fact    _param4Fact;
    Fact    _param5Fact;
    Fact    _param6Fact;
    Fact    _param7Fact;
    
131
    // Keys for Json save
132 133 134 135 136 137 138 139 140 141 142
    static const char*  _itemType;
    static const char*  _jsonTypeKey;
    static const char*  _jsonIdKey;
    static const char*  _jsonFrameKey;
    static const char*  _jsonCommandKey;
    static const char*  _jsonParam1Key;
    static const char*  _jsonParam2Key;
    static const char*  _jsonParam3Key;
    static const char*  _jsonParam4Key;
    static const char*  _jsonAutoContinueKey;
    static const char*  _jsonCoordinateKey;
143 144 145 146 147 148 149

    friend class ComplexMissionItem;
    friend class SimpleMissionItem;
    friend class MissionController;
#ifdef UNITTEST_BUILD
    friend class MissionItemTest;
#endif
150 151 152
};

#endif