MissionCommands.h 6.91 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
/*=====================================================================
 
 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 MissionCommands_H
#define MissionCommands_H

#include "QGCToolbox.h"
#include "QGCMAVLink.h"
#include "QGCLoggingCategory.h"
#include "QmlObjectListModel.h"
#include "MavlinkQmlSingleton.h"

#include <QObject>
#include <QString>
#include <QJsonObject>
#include <QJsonValue>

Q_DECLARE_LOGGING_CATEGORY(MissionCommandsLog)

class MissionCommands;

class MavCmdParamInfo : public QObject {

    Q_OBJECT

public:
    MavCmdParamInfo(QObject* parent = NULL)
        : QObject(parent)
    {

    }

    Q_PROPERTY(int          decimalPlaces   READ decimalPlaces  CONSTANT)
    Q_PROPERTY(double       defaultValue    READ defaultValue   CONSTANT)
    Q_PROPERTY(QStringList  enumStrings     READ enumStrings    CONSTANT)
    Q_PROPERTY(QVariantList enumValues      READ enumValues     CONSTANT)
    Q_PROPERTY(QString      label           READ label          CONSTANT)
    Q_PROPERTY(int          param           READ param          CONSTANT)
    Q_PROPERTY(QString      units           READ units          CONSTANT)

    int             decimalPlaces   (void) const { return _decimalPlaces; }
    double          defaultValue    (void) const { return _defaultValue; }
    QStringList     enumStrings     (void) const { return _enumStrings; }
    QVariantList    enumValues      (void) const { return _enumValues; }
    QString         label           (void) const { return _label; }
    int             param           (void) const { return _param; }
    QString         units           (void) const { return _units; }

private:
    int             _decimalPlaces;
    double          _defaultValue;
    QStringList     _enumStrings;
    QVariantList    _enumValues;
    QString         _label;
    int             _param;
    QString         _units;

    friend class MissionCommands;
};

class MavCmdInfo : public QObject {
    Q_OBJECT

public:
    MavCmdInfo(QObject* parent = NULL)
        : QObject(parent)
    {

    }

91 92 93 94 95 96 97 98
    Q_PROPERTY(QString  category                READ category               CONSTANT)
    Q_PROPERTY(MavlinkQmlSingleton::Qml_MAV_CMD command READ command        CONSTANT)
    Q_PROPERTY(QString  description             READ description            CONSTANT)
    Q_PROPERTY(bool     friendlyEdit            READ friendlyEdit           CONSTANT)
    Q_PROPERTY(QString  friendlyName            READ friendlyName           CONSTANT)
    Q_PROPERTY(QString  rawName                 READ rawName                CONSTANT)
    Q_PROPERTY(bool     standaloneCoordinate    READ standaloneCoordinate   CONSTANT)
    Q_PROPERTY(bool     specifiesCoordinate     READ specifiesCoordinate    CONSTANT)
Don Gagne's avatar
Don Gagne committed
99 100 101 102 103 104 105

    QString category            (void) const { return _category; }
    MavlinkQmlSingleton::Qml_MAV_CMD command(void) const { return (MavlinkQmlSingleton::Qml_MAV_CMD)_command; }
    QString description         (void) const { return _description; }
    bool    friendlyEdit        (void) const { return _friendlyEdit; }
    QString friendlyName        (void) const { return _friendlyName; }
    QString rawName             (void) const { return _rawName; }
106
    bool    standaloneCoordinate(void) const { return _standaloneCoordinate; }
Don Gagne's avatar
Don Gagne committed
107 108 109 110 111 112 113 114 115 116 117 118
    bool    specifiesCoordinate (void) const { return _specifiesCoordinate; }

    const QMap<int, MavCmdParamInfo*>& paramInfoMap(void) const { return _paramInfoMap; }

private:
    QString                     _category;
    MAV_CMD                     _command;
    QString                     _description;
    bool                        _friendlyEdit;
    QString                     _friendlyName;
    QMap<int, MavCmdParamInfo*> _paramInfoMap;
    QString                     _rawName;
119
    bool                        _standaloneCoordinate;
Don Gagne's avatar
Don Gagne committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    bool                        _specifiesCoordinate;

    friend class MissionCommands;
};

class MissionCommands : public QGCTool
{
    Q_OBJECT
    
public:
    MissionCommands(QGCApplication* app);

    Q_PROPERTY(QStringList                  categories  READ categories CONSTANT)
    Q_PROPERTY(const QmlObjectListModel*    commands    READ commands   CONSTANT)

    Q_INVOKABLE QString         categoryFromCommand(MavlinkQmlSingleton::Qml_MAV_CMD command) { return _mavCmdInfoMap[(MAV_CMD)command]->category(); }
    Q_INVOKABLE const QVariant  getCommandsForCategory(const QString& category) const { return QVariant::fromValue(_categoryToMavCmdInfoListMap[category]); }

    const QStringList           categories  (void) const { return _categories; }
    const QmlObjectListModel*   commands    (void) const { return &_commandList; }

    const QMap<MAV_CMD, MavCmdInfo*>& commandInfoMap(void) const { return _mavCmdInfoMap; };

    static const QString _degreesUnits;
    static const QString _degreesConvertUnits;

signals:
    
private:
    void _loadMavCmdInfoJson(void);
    void _setupMetaData(void);
    bool _validateKeyTypes(QJsonObject& jsonObject, const QStringList& keys, const QList<QJsonValue::Type>& types);

private:
    QStringList                         _categories;
    QMap<QString, QmlObjectListModel*>  _categoryToMavCmdInfoListMap;
    QmlObjectListModel                  _commandList;
    QMap<MAV_CMD, MavCmdInfo*>          _mavCmdInfoMap;

    static const QString _categoryJsonKey;
    static const QString _decimalPlacesJsonKey;
    static const QString _defaultJsonKey;
    static const QString _descriptionJsonKey;
    static const QString _enumStringsJsonKey;
    static const QString _enumValuesJsonKey;
    static const QString _friendlyNameJsonKey;
    static const QString _friendlyEditJsonKey;
    static const QString _idJsonKey;
    static const QString _labelJsonKey;
    static const QString _mavCmdInfoJsonKey;
    static const QString _param1JsonKey;
    static const QString _param2JsonKey;
    static const QString _param3JsonKey;
    static const QString _param4JsonKey;
    static const QString _paramJsonKeyFormat;
    static const QString _rawNameJsonKey;
176
    static const QString _standaloneCoordinateJsonKey;
Don Gagne's avatar
Don Gagne committed
177 178 179 180 181 182
    static const QString _specifiesCoordinateJsonKey;
    static const QString _unitsJsonKey;
    static const QString _versionJsonKey;
};

#endif