@ -31,6 +31,7 @@
# include "KML.h"
# include "KML.h"
# include "QGCCorePlugin.h"
# include "QGCCorePlugin.h"
# include "TakeoffMissionItem.h"
# include "TakeoffMissionItem.h"
# include "PlanViewSettings.h"
# define UPDATE_TIMEOUT 5000 ///< How often we check for bounding box changes
# define UPDATE_TIMEOUT 5000 ///< How often we check for bounding box changes
@ -59,6 +60,7 @@ const QString MissionController::patternCorridorScanName (QT_TRANSLATE_NOOP("
MissionController : : MissionController ( PlanMasterController * masterController , QObject * parent )
MissionController : : MissionController ( PlanMasterController * masterController , QObject * parent )
: PlanElementController ( masterController , parent )
: PlanElementController ( masterController , parent )
, _planViewSettings ( qgcApp ( ) - > toolbox ( ) - > settingsManager ( ) - > planViewSettings ( ) )
, _missionManager ( _managerVehicle - > missionManager ( ) )
, _missionManager ( _managerVehicle - > missionManager ( ) )
, _missionItemCount ( 0 )
, _missionItemCount ( 0 )
, _visualItems ( nullptr )
, _visualItems ( nullptr )
@ -77,6 +79,8 @@ MissionController::MissionController(PlanMasterController* masterController, QOb
managerVehicleChanged ( _managerVehicle ) ;
managerVehicleChanged ( _managerVehicle ) ;
_updateTimer . setSingleShot ( true ) ;
_updateTimer . setSingleShot ( true ) ;
connect ( & _updateTimer , & QTimer : : timeout , this , & MissionController : : _updateTimeout ) ;
connect ( & _updateTimer , & QTimer : : timeout , this , & MissionController : : _updateTimeout ) ;
connect ( _planViewSettings - > takeoffItemNotRequired ( ) , & Fact : : rawValueChanged , this , & MissionController : : _takeoffItemNotRequiredChanged ) ;
}
}
MissionController : : ~ MissionController ( )
MissionController : : ~ MissionController ( )
@ -355,7 +359,7 @@ int MissionController::_nextSequenceNumber(void)
VisualMissionItem * MissionController : : _insertSimpleMissionItemWorker ( QGeoCoordinate coordinate , MAV_CMD command , int visualItemIndex , bool makeCurrentItem )
VisualMissionItem * MissionController : : _insertSimpleMissionItemWorker ( QGeoCoordinate coordinate , MAV_CMD command , int visualItemIndex , bool makeCurrentItem )
{
{
int sequenceNumber = _nextSequenceNumber ( ) ;
int sequenceNumber = _nextSequenceNumber ( ) ;
SimpleMissionItem * newItem = new SimpleMissionItem ( _controllerVehicle , _flyView , this ) ;
SimpleMissionItem * newItem = new SimpleMissionItem ( _controllerVehicle , _flyView , false /* forLoad */ , this ) ;
newItem - > setSequenceNumber ( sequenceNumber ) ;
newItem - > setSequenceNumber ( sequenceNumber ) ;
newItem - > setCoordinate ( coordinate ) ;
newItem - > setCoordinate ( coordinate ) ;
newItem - > setCommand ( command ) ;
newItem - > setCommand ( command ) ;
@ -669,7 +673,7 @@ bool MissionController::_loadJsonMissionFileV1(const QJsonObject& json, QmlObjec
MissionSettingsItem * settingsItem = _addMissionSettings ( visualItems ) ;
MissionSettingsItem * settingsItem = _addMissionSettings ( visualItems ) ;
if ( json . contains ( _jsonPlannedHomePositionKey ) ) {
if ( json . contains ( _jsonPlannedHomePositionKey ) ) {
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , visualItems ) ;
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , true /* forLoad */ , visualItems ) ;
if ( item - > load ( json [ _jsonPlannedHomePositionKey ] . toObject ( ) , 0 , errorString ) ) {
if ( item - > load ( json [ _jsonPlannedHomePositionKey ] . toObject ( ) , 0 , errorString ) ) {
settingsItem - > setInitialHomePositionFromUser ( item - > coordinate ( ) ) ;
settingsItem - > setInitialHomePositionFromUser ( item - > coordinate ( ) ) ;
item - > deleteLater ( ) ;
item - > deleteLater ( ) ;
@ -705,11 +709,11 @@ bool MissionController::_loadJsonMissionFileV1(const QJsonObject& json, QmlObjec
}
}
const QJsonObject itemObject = itemValue . toObject ( ) ;
const QJsonObject itemObject = itemValue . toObject ( ) ;
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , visualItems ) ;
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , true /* forLoad */ , visualItems ) ;
if ( item - > load ( itemObject , itemObject [ " id " ] . toInt ( ) , errorString ) ) {
if ( item - > load ( itemObject , itemObject [ " id " ] . toInt ( ) , errorString ) ) {
if ( TakeoffMissionItem : : isTakeoffCommand ( item - > mavCommand ( ) ) ) {
if ( TakeoffMissionItem : : isTakeoffCommand ( item - > mavCommand ( ) ) ) {
// This needs to be a TakeoffMissionItem
// This needs to be a TakeoffMissionItem
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , visualItems ) ;
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , true /* forLoad */ , visualItems ) ;
takeoffItem - > load ( itemObject , itemObject [ " id " ] . toInt ( ) , errorString ) ;
takeoffItem - > load ( itemObject , itemObject [ " id " ] . toInt ( ) , errorString ) ;
item - > deleteLater ( ) ;
item - > deleteLater ( ) ;
item = takeoffItem ;
item = takeoffItem ;
@ -793,11 +797,11 @@ bool MissionController::_loadJsonMissionFileV2(const QJsonObject& json, QmlObjec
QString itemType = itemObject [ VisualMissionItem : : jsonTypeKey ] . toString ( ) ;
QString itemType = itemObject [ VisualMissionItem : : jsonTypeKey ] . toString ( ) ;
if ( itemType = = VisualMissionItem : : jsonTypeSimpleItemValue ) {
if ( itemType = = VisualMissionItem : : jsonTypeSimpleItemValue ) {
SimpleMissionItem * simpleItem = new SimpleMissionItem ( _controllerVehicle , _flyView , visualItems ) ;
SimpleMissionItem * simpleItem = new SimpleMissionItem ( _controllerVehicle , _flyView , true /* forLoad */ , visualItems ) ;
if ( simpleItem - > load ( itemObject , nextSequenceNumber , errorString ) ) {
if ( simpleItem - > load ( itemObject , nextSequenceNumber , errorString ) ) {
if ( TakeoffMissionItem : : isTakeoffCommand ( static_cast < MAV_CMD > ( simpleItem - > command ( ) ) ) ) {
if ( TakeoffMissionItem : : isTakeoffCommand ( static_cast < MAV_CMD > ( simpleItem - > command ( ) ) ) ) {
// This needs to be a TakeoffMissionItem
// This needs to be a TakeoffMissionItem
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , this ) ;
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , true /* forLoad */ , this ) ;
takeoffItem - > load ( itemObject , nextSequenceNumber , errorString ) ;
takeoffItem - > load ( itemObject , nextSequenceNumber , errorString ) ;
simpleItem - > deleteLater ( ) ;
simpleItem - > deleteLater ( ) ;
simpleItem = takeoffItem ;
simpleItem = takeoffItem ;
@ -937,14 +941,14 @@ bool MissionController::_loadTextMissionFile(QTextStream& stream, QmlObjectListM
MissionSettingsItem * settingsItem = _addMissionSettings ( visualItems ) ;
MissionSettingsItem * settingsItem = _addMissionSettings ( visualItems ) ;
while ( ! stream . atEnd ( ) ) {
while ( ! stream . atEnd ( ) ) {
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , visualItems ) ;
SimpleMissionItem * item = new SimpleMissionItem ( _controllerVehicle , _flyView , true /* forLoad */ , visualItems ) ;
if ( item - > load ( stream ) ) {
if ( item - > load ( stream ) ) {
if ( firstItem & & plannedHomePositionInFile ) {
if ( firstItem & & plannedHomePositionInFile ) {
settingsItem - > setInitialHomePositionFromUser ( item - > coordinate ( ) ) ;
settingsItem - > setInitialHomePositionFromUser ( item - > coordinate ( ) ) ;
} else {
} else {
if ( TakeoffMissionItem : : isTakeoffCommand ( static_cast < MAV_CMD > ( item - > command ( ) ) ) ) {
if ( TakeoffMissionItem : : isTakeoffCommand ( static_cast < MAV_CMD > ( item - > command ( ) ) ) ) {
// This needs to be a TakeoffMissionItem
// This needs to be a TakeoffMissionItem
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , visualItems ) ;
TakeoffMissionItem * takeoffItem = new TakeoffMissionItem ( _controllerVehicle , _flyView , settingsItem , true /* forLoad */ , visualItems ) ;
takeoffItem - > load ( stream ) ;
takeoffItem - > load ( stream ) ;
item - > deleteLater ( ) ;
item - > deleteLater ( ) ;
item = takeoffItem ;
item = takeoffItem ;
@ -2301,6 +2305,7 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
_currentPlanViewItem = nullptr ;
_currentPlanViewItem = nullptr ;
_currentPlanViewSeqNum = - 1 ;
_currentPlanViewSeqNum = - 1 ;
_currentPlanViewVIIndex = - 1 ;
_currentPlanViewVIIndex = - 1 ;
_onlyInsertTakeoffValid = ! _planViewSettings - > takeoffItemNotRequired ( ) - > rawValue ( ) . toBool ( ) & & _visualItems - > count ( ) = = 1 ; // First item must be takeoff
_isInsertTakeoffValid = true ;
_isInsertTakeoffValid = true ;
_isInsertLandValid = true ;
_isInsertLandValid = true ;
_isROIActive = false ;
_isROIActive = false ;
@ -2430,10 +2435,15 @@ void MissionController::setCurrentPlanViewSeqNum(int sequenceNumber, bool force)
}
}
}
}
// These are not valid when only takeoff is allowed
_isInsertLandValid = _isInsertLandValid & & ! _onlyInsertTakeoffValid ;
_flyThroughCommandsAllowed = _flyThroughCommandsAllowed & & ! _onlyInsertTakeoffValid ;
emit currentPlanViewSeqNumChanged ( ) ;
emit currentPlanViewSeqNumChanged ( ) ;
emit currentPlanViewVIIndexChanged ( ) ;
emit currentPlanViewVIIndexChanged ( ) ;
emit currentPlanViewItemChanged ( ) ;
emit currentPlanViewItemChanged ( ) ;
emit splitSegmentChanged ( ) ;
emit splitSegmentChanged ( ) ;
emit onlyInsertTakeoffValidChanged ( ) ;
emit isInsertTakeoffValidChanged ( ) ;
emit isInsertTakeoffValidChanged ( ) ;
emit isInsertLandValidChanged ( ) ;
emit isInsertLandValidChanged ( ) ;
emit isROIActiveChanged ( ) ;
emit isROIActiveChanged ( ) ;
@ -2531,3 +2541,9 @@ bool MissionController::isEmpty(void) const
{
{
return _visualItems - > count ( ) < = 1 ;
return _visualItems - > count ( ) < = 1 ;
}
}
void MissionController : : _takeoffItemNotRequiredChanged ( void )
{
// Force a recalc of allowed bits
setCurrentPlanViewSeqNum ( _currentPlanViewSeqNum , true /* force */ ) ;
}