MissionCommandTree.h 3.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
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#ifndef MissionCommandTree_H
#define MissionCommandTree_H

#include "QGCToolbox.h"
#include "QGCMAVLink.h"
#include "Vehicle.h"

#include <QVariantList>
#include <QMap>

class MissionCommandUIInfo;
class MissionCommandList;
22
class SettingsManager;
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
#ifdef UNITTEST_BUILD
class MissionCommandTreeTest;
#endif

/// Manages a hierarchy of MissionCommandUIInfo.
///
/// The static hierarchy allows for overriding mission command ui info based on MAV_AUTOPILOT and MAV_TYPE. The hierarchy of the tree is:
///     Any Firmware, Any Vehicle - Base set of all command definitions for any firmware, any vehicle, essentially ui defined to mavlink spec
///         Any Firmware, Fixed Wing
///             Known Firmware, Fixed Wing
///         Any Firmware, Multi Rotor (all types)
///             Known Firmware, Multi Rotor (all types)
///         Any Firmware, VTOL (all types)
///             Known Firmware, VTOL (all types)
///         Any Firmware, Rover
///             Known Firmware, Rover
///         Any Firmware, Sub
///             Known Firmware, Sub
/// For known firmwares, the override files are requested from the FirmwarePlugin.
///
/// When ui info is requested for a specific vehicle the static hierarchy in _staticCommandTree is collapsed into the set of available commands in
/// _availableCommands taking into account the appropriate set of overrides for the MAV_AUTOPILOT/MAV_TYPE combination associated with the vehicle.
///
class MissionCommandTree : public QGCTool
{
    Q_OBJECT
    
public:
51
    MissionCommandTree(QGCApplication* app, QGCToolbox* toolbox, bool unitTest = false);
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

    /// Returns the friendly name for the specified command
    QString friendlyName(MAV_CMD command);

    /// Returns the raw name for the specified command
    QString rawName(MAV_CMD command);

    const QList<MAV_CMD>& allCommandIds(void) const;

    Q_INVOKABLE QStringList categoriesForVehicle(Vehicle* vehicle) { return _availableCategoriesForVehicle(vehicle); }

    const MissionCommandUIInfo* getUIInfo(Vehicle* vehicle, MAV_CMD command);

   Q_INVOKABLE QVariantList getCommandsForCategory(Vehicle* vehicle, const QString& category);

    // Overrides from QGCTool
    virtual void setToolbox(QGCToolbox* toolbox);

private:
    void _collapseHierarchy(Vehicle* vehicle, const MissionCommandList* cmdList, QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree);
    MAV_TYPE _baseVehicleType(MAV_TYPE mavType) const;
    MAV_AUTOPILOT _baseFirmwareType(MAV_AUTOPILOT firmwareType) const;
    void _buildAvailableCommands(Vehicle* vehicle);
    QStringList _availableCategoriesForVehicle(Vehicle* vehicle);
    void _baseVehicleInfo(Vehicle* vehicle, MAV_AUTOPILOT& baseFirmwareType, MAV_TYPE& baseVehicleType) const;

private:
79 80 81 82
    QString             _allCommandsCategory;   ///< Category which contains all available commands
    QList<int>          _allCommandIds;         ///< List of all known command ids (not vehicle specific)
    SettingsManager*    _settingsManager;
    bool                _unitTest;              ///< true: running in unit test mode
83 84

    /// Full hierarchy
85
    QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, MissionCommandList*>>                    _staticCommandTree;
86 87 88 89 90 91 92 93 94 95 96 97 98 99

    /// Collapsed hierarchy for specific vehicle type
    QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QMap<MAV_CMD, MissionCommandUIInfo*>>>   _availableCommands;

    /// Collapsed hierarchy for specific vehicle type
    QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QStringList>>                            _availableCategories;


#ifdef UNITTEST_BUILD
    friend class MissionCommandTreeTest;
#endif
};

#endif