Browse Source

Merge pull request #7414 from DonLakeFlyer/AllCommands

Command Tree contains all commands
QGC4.4
Don Gagne 6 years ago committed by GitHub
parent
commit
d6ad774ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      src/MissionManager/MissionCommandTree.cc
  2. 18
      src/MissionManager/MissionCommandTree.h

69
src/MissionManager/MissionCommandTree.cc

@ -106,14 +106,6 @@ void MissionCommandTree::_collapseHierarchy(Vehicle*
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType); _baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
for (MAV_CMD command: cmdList->commandIds()) { for (MAV_CMD command: cmdList->commandIds()) {
// Only add supported command to tree (MAV_CMD_NAV_LAST is used for planned home position)
if (!qgcApp()->runningUnitTests()
&& !vehicle->firmwarePlugin()->supportedMissionCommands().isEmpty()
&& !vehicle->firmwarePlugin()->supportedMissionCommands().contains(command)
&& command != MAV_CMD_NAV_LAST) {
continue;
}
MissionCommandUIInfo* uiInfo = cmdList->getUIInfo(command); MissionCommandUIInfo* uiInfo = cmdList->getUIInfo(command);
if (uiInfo) { if (uiInfo) {
if (collapsedTree.contains(command)) { if (collapsedTree.contains(command)) {
@ -125,22 +117,20 @@ void MissionCommandTree::_collapseHierarchy(Vehicle*
} }
} }
void MissionCommandTree::_buildAvailableCommands(Vehicle* vehicle) void MissionCommandTree::_buildAllCommands(Vehicle* vehicle)
{ {
MAV_AUTOPILOT baseFirmwareType; MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType; MAV_TYPE baseVehicleType;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType); _baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
if (_availableCommands.contains(baseFirmwareType) && if (_allCommands.contains(baseFirmwareType) &&
_availableCommands[baseFirmwareType].contains(baseVehicleType)) { _allCommands[baseFirmwareType].contains(baseVehicleType)) {
// Available commands list already built // Already built
return; return;
} }
// Build new available commands list QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree = _allCommands[baseFirmwareType][baseVehicleType];
QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree = _availableCommands[baseFirmwareType][baseVehicleType];
// Any Firmware, Any Vehicle // Any Firmware, Any Vehicle
_collapseHierarchy(vehicle, _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC], collapsedTree); _collapseHierarchy(vehicle, _staticCommandTree[MAV_AUTOPILOT_GENERIC][MAV_TYPE_GENERIC], collapsedTree);
@ -160,16 +150,17 @@ void MissionCommandTree::_buildAvailableCommands(Vehicle* vehicle)
} }
} }
// Build category list // Build category list from supported commands
QMapIterator<MAV_CMD, MissionCommandUIInfo*> iter(collapsedTree); QList<MAV_CMD> supportedCommands = vehicle->firmwarePlugin()->supportedMissionCommands();
while (iter.hasNext()) { for (MAV_CMD cmd: collapsedTree.keys()) {
iter.next(); if (supportedCommands.contains(cmd)) {
QString newCategory = iter.value()->category(); QString newCategory = collapsedTree[cmd]->category();
if (!_availableCategories[baseFirmwareType][baseVehicleType].contains(newCategory)) { if (!_supportedCategories[baseFirmwareType][baseVehicleType].contains(newCategory)) {
_availableCategories[baseFirmwareType][baseVehicleType].append(newCategory); _supportedCategories[baseFirmwareType][baseVehicleType].append(newCategory);
}
} }
} }
_availableCategories[baseFirmwareType][baseVehicleType].append(_allCommandsCategory); _supportedCategories[baseFirmwareType][baseVehicleType].append(_allCommandsCategory);
} }
QStringList MissionCommandTree::_availableCategoriesForVehicle(Vehicle* vehicle) QStringList MissionCommandTree::_availableCategoriesForVehicle(Vehicle* vehicle)
@ -178,9 +169,9 @@ QStringList MissionCommandTree::_availableCategoriesForVehicle(Vehicle* vehicle)
MAV_TYPE baseVehicleType; MAV_TYPE baseVehicleType;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType); _baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_buildAvailableCommands(vehicle); _buildAllCommands(vehicle);
return _availableCategories[baseFirmwareType][baseVehicleType]; return _supportedCategories[baseFirmwareType][baseVehicleType];
} }
QString MissionCommandTree::friendlyName(MAV_CMD command) QString MissionCommandTree::friendlyName(MAV_CMD command)
@ -191,7 +182,7 @@ QString MissionCommandTree::friendlyName(MAV_CMD command)
if (uiInfo) { if (uiInfo) {
return uiInfo->friendlyName(); return uiInfo->friendlyName();
} else { } else {
return QString("MAV_CMD(%1)").arg((int)command); return QStringLiteral("MAV_CMD(%1)").arg((int)command);
} }
} }
@ -203,7 +194,7 @@ QString MissionCommandTree::rawName(MAV_CMD command)
if (uiInfo) { if (uiInfo) {
return uiInfo->rawName(); return uiInfo->rawName();
} else { } else {
return QString("MAV_CMD(%1)").arg((int)command); return QStringLiteral("MAV_CMD(%1)").arg((int)command);
} }
} }
@ -218,13 +209,13 @@ const MissionCommandUIInfo* MissionCommandTree::getUIInfo(Vehicle* vehicle, MAV_
MAV_TYPE baseVehicleType; MAV_TYPE baseVehicleType;
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType); _baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_buildAvailableCommands(vehicle); _buildAllCommands(vehicle);
const QMap<MAV_CMD, MissionCommandUIInfo*>& infoMap = _availableCommands[baseFirmwareType][baseVehicleType]; const QMap<MAV_CMD, MissionCommandUIInfo*>& infoMap = _allCommands[baseFirmwareType][baseVehicleType];
if (infoMap.contains(command)) { if (infoMap.contains(command)) {
return infoMap[command]; return infoMap[command];
} else { } else {
return NULL; return nullptr;
} }
} }
@ -232,21 +223,19 @@ QVariantList MissionCommandTree::getCommandsForCategory(Vehicle* vehicle, const
{ {
MAV_AUTOPILOT baseFirmwareType; MAV_AUTOPILOT baseFirmwareType;
MAV_TYPE baseVehicleType; MAV_TYPE baseVehicleType;
QList<MAV_CMD> supportedCommands = vehicle->firmwarePlugin()->supportedMissionCommands();
_baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType); _baseVehicleInfo(vehicle, baseFirmwareType, baseVehicleType);
_buildAvailableCommands(vehicle); _buildAllCommands(vehicle);
QVariantList list; QVariantList list;
QMap<MAV_CMD, MissionCommandUIInfo*> commandMap = _availableCommands[baseFirmwareType][baseVehicleType]; QMap<MAV_CMD, MissionCommandUIInfo*> commandMap = _allCommands[baseFirmwareType][baseVehicleType];
for (MAV_CMD command: commandMap.keys()) { for (MAV_CMD command: commandMap.keys()) {
if (command == MAV_CMD_NAV_LAST) { if (supportedCommands.contains(command)) {
// MAV_CMD_NAV_LAST is used for Mission Settings item. Although we want to be able to get command info for it. MissionCommandUIInfo* uiInfo = commandMap[command];
// The user should not be able to use it as a command. if (uiInfo->category() == category || category == _allCommandsCategory) {
continue; list.append(QVariant::fromValue(uiInfo));
} }
MissionCommandUIInfo* uiInfo = commandMap[command];
if (uiInfo->category() == category || category == _allCommandsCategory) {
list.append(QVariant::fromValue(uiInfo));
} }
} }

18
src/MissionManager/MissionCommandTree.h

@ -41,7 +41,7 @@ class MissionCommandTreeTest;
/// For known firmwares, the override files are requested from the FirmwarePlugin. /// 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 /// 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. /// _allCommands taking into account the appropriate set of overrides for the MAV_AUTOPILOT/MAV_TYPE combination associated with the vehicle.
/// ///
class MissionCommandTree : public QGCTool class MissionCommandTree : public QGCTool
{ {
@ -68,12 +68,12 @@ public:
virtual void setToolbox(QGCToolbox* toolbox); virtual void setToolbox(QGCToolbox* toolbox);
private: private:
void _collapseHierarchy(Vehicle* vehicle, const MissionCommandList* cmdList, QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree); void _collapseHierarchy(Vehicle* vehicle, const MissionCommandList* cmdList, QMap<MAV_CMD, MissionCommandUIInfo*>& collapsedTree);
MAV_TYPE _baseVehicleType(MAV_TYPE mavType) const; MAV_TYPE _baseVehicleType(MAV_TYPE mavType) const;
MAV_AUTOPILOT _baseFirmwareType(MAV_AUTOPILOT firmwareType) const; MAV_AUTOPILOT _baseFirmwareType(MAV_AUTOPILOT firmwareType) const;
void _buildAvailableCommands(Vehicle* vehicle); void _buildAllCommands(Vehicle* vehicle);
QStringList _availableCategoriesForVehicle(Vehicle* vehicle); QStringList _availableCategoriesForVehicle(Vehicle* vehicle);
void _baseVehicleInfo(Vehicle* vehicle, MAV_AUTOPILOT& baseFirmwareType, MAV_TYPE& baseVehicleType) const; void _baseVehicleInfo(Vehicle* vehicle, MAV_AUTOPILOT& baseFirmwareType, MAV_TYPE& baseVehicleType) const;
private: private:
QString _allCommandsCategory; ///< Category which contains all available commands QString _allCommandsCategory; ///< Category which contains all available commands
@ -85,10 +85,10 @@ private:
QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, MissionCommandList*>> _staticCommandTree; QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, MissionCommandList*>> _staticCommandTree;
/// Collapsed hierarchy for specific vehicle type /// Collapsed hierarchy for specific vehicle type
QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QMap<MAV_CMD, MissionCommandUIInfo*>>> _availableCommands; QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QMap<MAV_CMD, MissionCommandUIInfo*>>> _allCommands;
/// Collapsed hierarchy for specific vehicle type /// Collapsed hierarchy for specific vehicle type
QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QStringList>> _availableCategories; QMap<MAV_AUTOPILOT, QMap<MAV_TYPE, QStringList /* category */>> _supportedCategories;
#ifdef UNITTEST_BUILD #ifdef UNITTEST_BUILD

Loading…
Cancel
Save