MissionCommandTree.h 4.12 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10
#pragma once
11 12 13 14 15 16 17 18 19 20

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

#include <QVariantList>
#include <QMap>

class MissionCommandUIInfo;
class MissionCommandList;
21
class SettingsManager;
22 23 24 25 26 27
#ifdef UNITTEST_BUILD
class MissionCommandTreeTest;
#endif

/// Manages a hierarchy of MissionCommandUIInfo.
///
28 29 30
/// The static hierarchy allows for overriding mission command ui info based on firmware and vehicle class. The hierarchy of the tree is:
///     FirmwareClassGeneric - VehicleClassGeneric - Base set of all command definitions for any firmware, any vehicle, ui defined by mavlink spec
///         FirmwareClassGeneric - VehicleClassFixedWing
31 32 33 34 35 36 37 38 39 40 41 42
///             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
Don Gagne's avatar
Don Gagne committed
43
/// _allCommands taking into account the appropriate set of overrides for the MAV_AUTOPILOT/MAV_TYPE combination associated with the vehicle.
44 45 46 47 48 49
///
class MissionCommandTree : public QGCTool
{
    Q_OBJECT
    
public:
50
    MissionCommandTree(QGCApplication* app, QGCToolbox* toolbox, bool unitTest = false);
51 52 53 54 55 56 57 58 59 60 61 62 63

    /// 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);

64
    /// @param showFlyThroughCommands - true: all commands shows, false: filter out commands which the vehicle flies through (specifiedCoordinate=true, standaloneCoordinate=false)
65
    Q_INVOKABLE QVariantList getCommandsForCategory(Vehicle* vehicle, const QString& category, bool showFlyThroughCommands);
66 67 68 69 70

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

private:
71 72 73 74
    void                        _collapseHierarchy              (const MissionCommandList* cmdList, QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree);
    void                        _buildAllCommands               (Vehicle* vehicle);
    QStringList                 _availableCategoriesForVehicle  (Vehicle* vehicle);
    void                        _firmwareAndVehicleClassInfo    (Vehicle* vehicle, QGCMAVLink::FirmwareClass_t& firmwareClass, QGCMAVLink::VehicleClass_t& vehicleClass) const;
75 76

private:
77 78 79 80
    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
81 82

    /// Full hierarchy
83
    QMap<QGCMAVLink::FirmwareClass_t, QMap<QGCMAVLink::VehicleClass_t, MissionCommandList*>>                    _staticCommandTree;
84 85

    /// Collapsed hierarchy for specific vehicle type
86
    QMap<QGCMAVLink::FirmwareClass_t, QMap<QGCMAVLink::VehicleClass_t, QMap<MAV_CMD, MissionCommandUIInfo*>>>   _allCommands;
87 88

    /// Collapsed hierarchy for specific vehicle type
89
    QMap<QGCMAVLink::FirmwareClass_t, QMap<QGCMAVLink::VehicleClass_t, QStringList /* category */>>             _supportedCategories;
90 91 92 93 94 95


#ifdef UNITTEST_BUILD
    friend class MissionCommandTreeTest;
#endif
};