@ -1,4 +1,3 @@
@@ -1,4 +1,3 @@
/****************************************************************************
*
* ( c ) 2009 - 2020 QGROUNDCONTROL PROJECT < http : //www.qgroundcontrol.org>
@ -8,7 +7,6 @@
@@ -8,7 +7,6 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "MissionCommandTree.h"
# include "FactMetaData.h"
# include "Vehicle.h"
@ -21,10 +19,10 @@
@@ -21,10 +19,10 @@
# include <QQmlEngine>
MissionCommandTree : : MissionCommandTree ( QGCApplication * app , QGCToolbox * toolbox , bool unitTest )
: QGCTool ( app , toolbox )
, _allCommandsCategory ( tr ( " All commands " ) )
, _settingsManager ( nullptr )
, _unitTest ( unitTest )
: QGCTool ( app , toolbox )
, _allCommandsCategory ( tr ( " All commands " ) )
, _settingsManager ( nullptr )
, _unitTest ( unitTest )
{
}
@ -37,25 +35,22 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
@@ -37,25 +35,22 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
# ifdef UNITTEST_BUILD
if ( _unitTest ) {
// Load unit testing tree
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GENERIC ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoCommon.json " , true , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_FIXED_WING ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoFixedWing.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_QUADROTOR ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoMultiRotor.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_VTOL_QUADROTOR ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoVTOL.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_SUBMARINE ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoSub.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GROUND_ROVER ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoRover.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassGeneric ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoCommon.json " , true , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassFixedWing ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoFixedWing.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassMultiRotor ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoMultiRotor.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassVTOL ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoVTOL.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassSub ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoSub.json " , false , this ) ;
_staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassRoverBoat ] = new MissionCommandList ( " :/unittest/UT-MavCmdInfoRover.json " , false , this ) ;
} else {
# endif
// Load all levels of hierarchy
for ( MAV_AUTOPILOT firmwareType : _toolbox - > firmwarePluginManager ( ) - > supportedFirmwareTypes ( ) ) {
FirmwarePlugin * plugin = _toolbox - > firmwarePluginManager ( ) - > firmwarePluginForAutopilot ( firmwareType , MAV_TYPE_QUADROTOR ) ;
QList < MAV_TYPE > vehicleTypes ;
vehicleTypes < < MAV_TYPE_GENERIC < < MAV_TYPE_FIXED_WING < < MAV_TYPE_QUADROTOR < < MAV_TYPE_VTOL_QUADROTOR < < MAV_TYPE_GROUND_ROVER < < MAV_TYPE_SUBMARINE ;
for ( const QGCMAVLink : : FirmwareClass_t firmwareClass : _toolbox - > firmwarePluginManager ( ) - > supportedFirmwareClasses ( ) ) {
FirmwarePlugin * plugin = _toolbox - > firmwarePluginManager ( ) - > firmwarePluginForAutopilot ( QGCMAVLink : : firmwareClassToAutopilot ( firmwareClass ) , MAV_TYPE_QUADROTOR ) ;
for ( MAV_TYPE vehicleType : vehicleTypes ) {
QString overrideFile = plugin - > missionCommandOverrides ( vehicleType ) ;
for ( const QGCMAVLink : : VehicleClass_t vehicleClass : QGCMAVLink : : allVehicleClasses ( ) ) {
QString overrideFile = plugin - > missionCommandOverrides ( vehicleClass ) ;
if ( ! overrideFile . isEmpty ( ) ) {
_staticCommandTree [ firmwareType ] [ vehicleType ] = new MissionCommandList ( overrideFile , firmwareType = = MAV_AUTOPILOT_GENERIC & & vehicleType = = MAV_TYPE_GENERIC /* baseCommandList */ , this ) ;
_staticCommandTree [ firmwareClass ] [ vehicleClass ] = new MissionCommandList ( overrideFile , firmwareClass = = QGCMAVLink : : FirmwareClassGeneric & & vehicleClass = = QGCMAVLink : : VehicleClassGeneric /* baseCommandList */ , this ) ;
}
}
}
@ -64,45 +59,15 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
@@ -64,45 +59,15 @@ void MissionCommandTree::setToolbox(QGCToolbox* toolbox)
# endif
}
MAV_AUTOPILOT MissionCommandTree : : _baseFirmwareType ( MAV_AUTOPILOT firmwareType ) const
{
if ( qgcApp ( ) - > toolbox ( ) - > firmwarePluginManager ( ) - > supportedFirmwareTypes ( ) . contains ( firmwareType ) ) {
return firmwareType ;
} else {
return MAV_AUTOPILOT_GENERIC ;
}
}
MAV_TYPE MissionCommandTree : : _baseVehicleType ( MAV_TYPE mavType ) const
{
if ( QGCMAVLink : : isFixedWing ( mavType ) ) {
return MAV_TYPE_FIXED_WING ;
} else if ( QGCMAVLink : : isMultiRotor ( mavType ) ) {
return MAV_TYPE_QUADROTOR ;
} else if ( QGCMAVLink : : isVTOL ( mavType ) ) {
return MAV_TYPE_VTOL_QUADROTOR ;
} else if ( QGCMAVLink : : isRover ( mavType ) ) {
return MAV_TYPE_GROUND_ROVER ;
} else if ( QGCMAVLink : : isSub ( mavType ) ) {
return MAV_TYPE_SUBMARINE ;
} else {
return MAV_TYPE_GENERIC ;
}
}
/// Add the next level of the hierarchy to a collapsed tree.
/// @param vehicle Collapsed tree is for this vehicle
/// @param cmdList List of mission commands to collapse into ui info
/// @param collapsedTree Tree we are collapsing into
void MissionCommandTree : : _collapseHierarchy ( Vehicle * vehicle ,
const MissionCommandList * cmdList ,
/// @param cmdList List of mission commands to collapse into ui info
/// @param collapsedTree Tree we are collapsing into
void MissionCommandTree : : _collapseHierarchy ( const MissionCommandList * cmdList ,
QMap < MAV_CMD , MissionCommandUIInfo * > & collapsedTree )
{
MAV_AUTOPILOT baseFirmwareType ;
MAV_TYPE baseVehicleType ;
_baseVehicleInfo ( vehicle , baseFirmwareType , baseVehicleType ) ;
if ( ! cmdList ) {
return ;
}
for ( MAV_CMD command : cmdList - > commandIds ( ) ) {
MissionCommandUIInfo * uiInfo = cmdList - > getUIInfo ( command ) ;
@ -118,34 +83,33 @@ void MissionCommandTree::_collapseHierarchy(Vehicle*
@@ -118,34 +83,33 @@ void MissionCommandTree::_collapseHierarchy(Vehicle*
void MissionCommandTree : : _buildAllCommands ( Vehicle * vehicle )
{
MAV_AUTOPILOT baseFirmwareType ;
MAV_TYPE baseVehicleType ;
QGCMAVLink : : FirmwareClass_t firmwareClass ;
QGCMAVLink : : VehicleClass_t vehicleClass ;
_baseVehicle Info ( vehicle , baseFirmwareType , baseVehicleType ) ;
_firmwareAndVehicleClass Info ( vehicle , firmwareClass , vehicleClass ) ;
if ( _allCommands . contains ( baseFirmwareType ) & &
_allCommands [ baseFirmwareType ] . contains ( baseVehicleType ) ) {
if ( _allCommands . contains ( firmwareClass ) & & _allCommands [ firmwareClass ] . contains ( vehicleClass ) ) {
// Already built
return ;
}
QMap < MAV_CMD , MissionCommandUIInfo * > & collapsedTree = _allCommands [ baseFirmwareType ] [ baseVehicleType ] ;
QMap < MAV_CMD , MissionCommandUIInfo * > & collapsedTree = _allCommands [ firmwareClass ] [ vehicleClass ] ;
// Any Firmware, Any Vehicle
_collapseHierarchy ( vehicle , _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GENERIC ] , collapsedTree ) ;
// Base of the tree is all commands
_collapseHierarchy ( _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ QGCMAVLink : : VehicleClassGeneric ] , collapsedTree ) ;
// Any Firmware, Specific Vehicle
if ( baseVehicleType ! = MAV_TYPE_GENERIC ) {
_collapseHierarchy ( vehicle , _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ baseVehicleType ] , collapsedTree ) ;
// Add the overrides for specific vehicle types
if ( vehicleClass ! = QGCMAVLink : : VehicleClassGeneric ) {
_collapseHierarchy ( _staticCommandTree [ QGCMAVLink : : FirmwareClassGeneric ] [ vehicleClass ] , collapsedTree ) ;
}
// Known Firmware, Any Vehicle
if ( baseFirmwareType ! = MAV_AUTOPILOT_GENERIC ) {
_collapseHierarchy ( vehicle , _staticCommandTree [ baseFirmwareType ] [ MAV_TYPE_GENERIC ] , collapsedTree ) ;
// Add the overrides for specific firmware class, all vehicles
if ( firmwareClass ! = QGCMAVLink : : FirmwareClassGeneric ) {
_collapseHierarchy ( _staticCommandTree [ firmwareClass ] [ QGCMAVLink : : VehicleClassGeneric ] , collapsedTree ) ;
// Known Firmware, Specific Vehicle
if ( baseVehicleType ! = MAV_TYPE_GENERIC ) {
_collapseHierarchy ( vehicle , _staticCommandTree [ baseFirmwareType ] [ baseVehicleType ] , collapsedTree ) ;
// Add overrides for specific vehicle class
if ( vehicleClass ! = QGCMAVLink : : VehicleClassGeneric ) {
_collapseHierarchy ( _staticCommandTree [ firmwareClass ] [ vehicleClass ] , collapsedTree ) ;
}
}
@ -154,28 +118,28 @@ void MissionCommandTree::_buildAllCommands(Vehicle* vehicle)
@@ -154,28 +118,28 @@ void MissionCommandTree::_buildAllCommands(Vehicle* vehicle)
for ( MAV_CMD cmd : collapsedTree . keys ( ) ) {
if ( supportedCommands . contains ( cmd ) ) {
QString newCategory = collapsedTree [ cmd ] - > category ( ) ;
if ( ! _supportedCategories [ baseFirmwareType ] [ baseVehicleType ] . contains ( newCategory ) ) {
_supportedCategories [ baseFirmwareType ] [ baseVehicleType ] . append ( newCategory ) ;
if ( ! _supportedCategories [ firmwareClass ] [ vehicleClass ] . contains ( newCategory ) ) {
_supportedCategories [ firmwareClass ] [ vehicleClass ] . append ( newCategory ) ;
}
}
}
_supportedCategories [ baseFirmwareType ] [ baseVehicleType ] . append ( _allCommandsCategory ) ;
_supportedCategories [ firmwareClass ] [ vehicleClass ] . append ( _allCommandsCategory ) ;
}
QStringList MissionCommandTree : : _availableCategoriesForVehicle ( Vehicle * vehicle )
{
MAV_AUTOPILOT baseFirmwareType ;
MAV_TYPE baseVehicleType ;
QGCMAVLink : : FirmwareClass_t firmwareClass ;
QGCMAVLink : : VehicleClass_t vehicleClass ;
_baseVehicle Info ( vehicle , baseFirmwareType , baseVehicleType ) ;
_firmwareAndVehicleClass Info ( vehicle , firmwareClass , vehicleClass ) ;
_buildAllCommands ( vehicle ) ;
return _supportedCategories [ baseFirmwareType ] [ baseVehicleType ] ;
return _supportedCategories [ firmwareClass ] [ vehicleClass ] ;
}
QString MissionCommandTree : : friendlyName ( MAV_CMD command )
{
MissionCommandList * commandList = _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GENERIC ] ;
MissionCommandList * commandList = _staticCommandTree [ QGCMAVLink : : FirmwareClassGeneric ] [ QGCMAVLink : : VehicleClassGeneric ] ;
MissionCommandUIInfo * uiInfo = commandList - > getUIInfo ( command ) ;
if ( uiInfo ) {
@ -187,7 +151,7 @@ QString MissionCommandTree::friendlyName(MAV_CMD command)
@@ -187,7 +151,7 @@ QString MissionCommandTree::friendlyName(MAV_CMD command)
QString MissionCommandTree : : rawName ( MAV_CMD command )
{
MissionCommandList * commandList = _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GENERIC ] ;
MissionCommandList * commandList = _staticCommandTree [ QGCMAVLink : : FirmwareClassGeneric ] [ QGCMAVLink : : VehicleClassGeneric ] ;
MissionCommandUIInfo * uiInfo = commandList - > getUIInfo ( command ) ;
if ( uiInfo ) {
@ -199,18 +163,18 @@ QString MissionCommandTree::rawName(MAV_CMD command)
@@ -199,18 +163,18 @@ QString MissionCommandTree::rawName(MAV_CMD command)
const QList < MAV_CMD > & MissionCommandTree : : allCommandIds ( void ) const
{
return _staticCommandTree [ MAV_AUTOPILOT_GENERIC ] [ MAV_TYPE_GENERIC ] - > commandIds ( ) ;
return _staticCommandTree [ QGCMAVLink : : FirmwareClassGeneric ] [ QGCMAVLink : : VehicleClassGeneric ] - > commandIds ( ) ;
}
const MissionCommandUIInfo * MissionCommandTree : : getUIInfo ( Vehicle * vehicle , MAV_CMD command )
{
MAV_AUTOPILOT baseFirmwareType ;
MAV_TYPE baseVehicleType ;
QGCMAVLink : : FirmwareClass_t firmwareClass ;
QGCMAVLink : : VehicleClass_t vehicleClass ;
_baseVehicle Info ( vehicle , baseFirmwareType , baseVehicleType ) ;
_firmwareAndVehicleClass Info ( vehicle , firmwareClass , vehicleClass ) ;
_buildAllCommands ( vehicle ) ;
const QMap < MAV_CMD , MissionCommandUIInfo * > & infoMap = _allCommands [ baseFirmwareType ] [ baseVehicleType ] ;
const QMap < MAV_CMD , MissionCommandUIInfo * > & infoMap = _allCommands [ firmwareClass ] [ vehicleClass ] ;
if ( infoMap . contains ( command ) ) {
return infoMap [ command ] ;
} else {
@ -220,19 +184,19 @@ const MissionCommandUIInfo* MissionCommandTree::getUIInfo(Vehicle* vehicle, MAV_
@@ -220,19 +184,19 @@ const MissionCommandUIInfo* MissionCommandTree::getUIInfo(Vehicle* vehicle, MAV_
QVariantList MissionCommandTree : : getCommandsForCategory ( Vehicle * vehicle , const QString & category , bool showFlyThroughCommands )
{
MAV_AUTOPILOT baseFirmwareType ;
MAV_TYPE baseVehicleType ;
QGCMAVLink : : FirmwareClass_t firmwareClass ;
QGCMAVLink : : VehicleClass_t vehicleClass ;
_baseVehicle Info ( vehicle , baseFirmwareType , baseVehicleType ) ;
_firmwareAndVehicleClass Info ( vehicle , firmwareClass , vehicleClass ) ;
_buildAllCommands ( vehicle ) ;
// vehicle can be null in which case _baseVehicle Info will tell of the firmware/vehicle type for the offline editing vehicle.
// vehicle can be null in which case _firmwareAndVehicleClass Info will tell of the firmware/vehicle type for the offline editing vehicle.
// We then use that to get a firmware plugin so we can get the list of supported commands.
FirmwarePlugin * firmwarePlugin = qgcApp ( ) - > toolbox ( ) - > firmwarePluginManager ( ) - > firmwarePluginForAutopilot ( baseFirmwareType , baseVehicleType ) ;
FirmwarePlugin * firmwarePlugin = qgcApp ( ) - > toolbox ( ) - > firmwarePluginManager ( ) - > firmwarePluginForAutopilot ( QGCMAVLink : : firmwareClassToAutopilot ( firmwareClass ) , QGCMAVLink : : vehicleClassToMavType ( vehicleClass ) ) ;
QList < MAV_CMD > supportedCommands = firmwarePlugin - > supportedMissionCommands ( ) ;
QVariantList list ;
QMap < MAV_CMD , MissionCommandUIInfo * > commandMap = _allCommands [ baseFirmwareType ] [ baseVehicleType ] ;
QMap < MAV_CMD , MissionCommandUIInfo * > commandMap = _allCommands [ firmwareClass ] [ vehicleClass ] ;
for ( MAV_CMD command : commandMap . keys ( ) ) {
if ( supportedCommands . contains ( command ) ) {
MissionCommandUIInfo * uiInfo = commandMap [ command ] ;
@ -246,14 +210,8 @@ QVariantList MissionCommandTree::getCommandsForCategory(Vehicle* vehicle, const
@@ -246,14 +210,8 @@ QVariantList MissionCommandTree::getCommandsForCategory(Vehicle* vehicle, const
return list ;
}
void MissionCommandTree : : _baseVehicle Info ( Vehicle * vehicle , MAV_AUTOPILOT & baseFirmwareType , MAV_TYPE & baseVehicleType ) const
void MissionCommandTree : : _firmwareAndVehicleClass Info ( Vehicle * vehicle , QGCMAVLink : : FirmwareClass_t & firmwareClass , QGCMAVLink : : VehicleClass_t & vehicleClass ) const
{
if ( vehicle ) {
baseFirmwareType = _baseFirmwareType ( vehicle - > firmwareType ( ) ) ;
baseVehicleType = _baseVehicleType ( vehicle - > vehicleType ( ) ) ;
} else {
// No Vehicle means offline editing
baseFirmwareType = _baseFirmwareType ( ( MAV_AUTOPILOT ) _settingsManager - > appSettings ( ) - > offlineEditingFirmwareType ( ) - > rawValue ( ) . toInt ( ) ) ;
baseVehicleType = _baseVehicleType ( ( MAV_TYPE ) _settingsManager - > appSettings ( ) - > offlineEditingVehicleType ( ) - > rawValue ( ) . toInt ( ) ) ;
}
firmwareClass = QGCMAVLink : : firmwareClass ( vehicle - > firmwareType ( ) ) ;
vehicleClass = QGCMAVLink : : vehicleClass ( vehicle - > vehicleType ( ) ) ;
}