WimaController.h 23.7 KB
Newer Older
1
#pragma once
2 3

#include <QObject>
Valentin Platzgummer's avatar
Valentin Platzgummer committed
4 5
#include <QScopedPointer>

6
#include "QGCMapPolygon.h"
7
#include "QmlObjectListModel.h"
8

9 10 11 12
#include "Geometry/WimaArea.h"
#include "Geometry/WimaMeasurementArea.h"
#include "Geometry/WimaServiceArea.h"
#include "Geometry/WimaCorridor.h"
13
#include "WimaDataContainer.h"
14 15 16
#include "Geometry/WimaMeasurementAreaData.h"
#include "Geometry/WimaCorridorData.h"
#include "Geometry/WimaServiceAreaData.h"
17 18 19

#include "PlanMasterController.h"
#include "MissionController.h"
20
#include "SurveyComplexItem.h"
21 22
#include "SimpleMissionItem.h"
#include "MissionSettingsItem.h"
23 24
#include "JsonHelper.h"
#include "QGCApplication.h"
25
#include "SettingsFact.h"
26 27
#include "WimaSettings.h"
#include "SettingsManager.h"
28

Valentin Platzgummer's avatar
Valentin Platzgummer committed
29
#include "snake.h"
30 31 32 33 34
#include "Snake/SnakeWorker.h"
#include "Snake/SnakeTiles.h"
#include "Snake/SnakeTilesLocal.h"
#include "Geometry/GeoPoint3D.h"
#include "Snake/QNemoProgress.h"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
35

Valentin Platzgummer's avatar
Valentin Platzgummer committed
36 37
#include "ros_bridge/include/ROSBridge.h"

38 39
#include "WaypointManager/DefaultManager.h"

Valentin Platzgummer's avatar
Valentin Platzgummer committed
40 41
#define CHECK_BATTERY_INTERVAL 1000 // ms
#define SMART_RTL_MAX_ATTEMPTS 3 // times
42
#define SMART_RTL_ATTEMPT_INTERVAL 200 // ms
Valentin Platzgummer's avatar
Valentin Platzgummer committed
43
#define EVENT_TIMER_INTERVAL 50 // ms
44
#define SNAKE_EVENT_LOOP_INTERVAL 5000 // ms
45

46

Valentin Platzgummer's avatar
Valentin Platzgummer committed
47 48
using namespace snake;

Valentin Platzgummer's avatar
Valentin Platzgummer committed
49 50
typedef std::unique_ptr<rapidjson::Document> JsonDocUPtr;

51 52
class WimaController : public QObject
{
53 54
    Q_OBJECT

55 56
    enum FileType {WimaFile, PlanFile};

Valentin Platzgummer's avatar
Valentin Platzgummer committed
57 58
    typedef QScopedPointer<ROSBridge::ROSBridge> ROSBridgePtr;

59
public:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
60 61 62 63

    enum SnakeConnectionStatus {Connected = 1, NotConnected = 0};


64 65 66
    WimaController(QObject *parent = nullptr);


67 68 69 70 71 72 73 74 75 76 77 78 79 80
    Q_PROPERTY(PlanMasterController*    masterController
               READ                     masterController
               WRITE                    setMasterController
               NOTIFY                   masterControllerChanged
               )
    Q_PROPERTY(MissionController*       missionController
               READ                     missionController
               WRITE                    setMissionController
               NOTIFY                   missionControllerChanged
               )
    Q_PROPERTY(QmlObjectListModel*      visualItems
               READ                     visualItems
               NOTIFY                   visualItemsChanged
               )
81 82 83 84
//    Q_PROPERTY(QString                  currentFile             READ currentFile                                            NOTIFY currentFileChanged)
//    Q_PROPERTY(QStringList              loadNameFilters         READ loadNameFilters                                        CONSTANT)
//    Q_PROPERTY(QStringList              saveNameFilters         READ saveNameFilters                                        CONSTANT)
//    Q_PROPERTY(QString                  fileExtension           READ fileExtension                                          CONSTANT)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    Q_PROPERTY(WimaDataContainer*   dataContainer
               READ                 dataContainer
               WRITE                setDataContainer
               NOTIFY               dataContainerChanged
               )
    Q_PROPERTY(QmlObjectListModel*  missionItems
               READ                 missionItems
               NOTIFY               missionItemsChanged
               )
    Q_PROPERTY(QmlObjectListModel*  currentMissionItems
               READ                 currentMissionItems
               NOTIFY               currentMissionItemsChanged
               )
    Q_PROPERTY(QVariantList waypointPath
               READ         waypointPath
               NOTIFY       waypointPathChanged
               )
    Q_PROPERTY(QVariantList currentWaypointPath
               READ         currentWaypointPath
               NOTIFY       currentWaypointPathChanged
               )
    Q_PROPERTY(Fact*                    enableWimaController
               READ enableWimaController
               CONSTANT)
    Q_PROPERTY(Fact*    overlapWaypoints
               READ     overlapWaypoints
               CONSTANT
               )
    Q_PROPERTY(Fact* maxWaypointsPerPhase
               READ  maxWaypointsPerPhase
               CONSTANT
               )
    Q_PROPERTY(Fact*    startWaypointIndex
               READ     startWaypointIndex
               CONSTANT
               )
    Q_PROPERTY(Fact*    showAllMissionItems
               READ     showAllMissionItems
               CONSTANT
               )
    Q_PROPERTY(Fact*    showCurrentMissionItems
               READ     showCurrentMissionItems
               CONSTANT
               )
    Q_PROPERTY(Fact*    flightSpeed
               READ     flightSpeed
               CONSTANT
               )
    Q_PROPERTY(Fact*    altitude
               READ     altitude
               CONSTANT
               )
    Q_PROPERTY(Fact*    arrivalReturnSpeed
               READ     arrivalReturnSpeed
               CONSTANT
               )
    Q_PROPERTY(bool     uploadOverrideRequired
               READ     uploadOverrideRequired
               WRITE    setUploadOverrideRequired
               NOTIFY   uploadOverrideRequiredChanged
               )
    Q_PROPERTY(double   phaseDistance
               READ     phaseDistance
               NOTIFY   phaseDistanceChanged
               )
    Q_PROPERTY(double   phaseDuration
               READ     phaseDuration
               NOTIFY   phaseDurationChanged
               )
    Q_PROPERTY(bool     vehicleHasLowBattery
               READ     vehicleHasLowBattery
               NOTIFY   vehicleHasLowBatteryChanged
               )
158

Valentin Platzgummer's avatar
Valentin Platzgummer committed
159
    // Snake
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    Q_PROPERTY(Fact*    enableSnake
               READ     enableSnake
               CONSTANT
               )
    Q_PROPERTY(long     snakeConnectionStatus
               READ     snakeConnectionStatus
               NOTIFY   snakeConnectionStatusChanged
               )
    Q_PROPERTY(bool     snakeCalcInProgress
               READ     snakeCalcInProgress
               NOTIFY   snakeCalcInProgressChanged
               )
    Q_PROPERTY(Fact*    snakeTileWidth
               READ     snakeTileWidth
               CONSTANT
               )
    Q_PROPERTY(Fact*    snakeTileHeight
               READ     snakeTileHeight
               CONSTANT
               )
    Q_PROPERTY(Fact*    snakeMinTileArea
               READ     snakeMinTileArea
               CONSTANT
               )
    Q_PROPERTY(Fact*    snakeLineDistance
               READ     snakeLineDistance
               CONSTANT
               )
    Q_PROPERTY(Fact*    snakeMinTransectLength
               READ     snakeMinTransectLength
               CONSTANT
               )
    Q_PROPERTY(QmlObjectListModel*  snakeTiles
               READ                 snakeTiles
               NOTIFY               snakeTilesChanged
               )
    Q_PROPERTY(QVariantList snakeTileCenterPoints
               READ         snakeTileCenterPoints
               NOTIFY       snakeTileCenterPointsChanged
               )
    Q_PROPERTY(QVector<int>     nemoProgress
               READ             nemoProgress
               NOTIFY           nemoProgressChanged
               )
Valentin Platzgummer's avatar
Valentin Platzgummer committed
204

205 206 207


    // Property accessors
208 209 210
    PlanMasterController*       masterController       (void);
    MissionController*          missionController      (void);
    QmlObjectListModel*         visualItems            (void);
211 212 213 214
//    QString                     currentFile            (void) const     { return _currentFile; }
//    QStringList                 loadNameFilters        (void) const;
//    QStringList                 saveNameFilters        (void) const;
//    QString                     fileExtension          (void) const     { return wimaFileExtension; }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
215
    QGCMapPolygon               joinedArea             (void) const;
216
    WimaDataContainer*          dataContainer          (void)           { return _container; }
217 218 219 220
    QmlObjectListModel*         missionItems           (void);
    QmlObjectListModel*         currentMissionItems    (void);
    QVariantList                waypointPath           (void);
    QVariantList                currentWaypointPath    (void);
221 222 223 224 225 226 227
    Fact*                       enableWimaController   (void)           { return &_enableWimaController; }
    Fact*                       overlapWaypoints       (void)           { return &_overlapWaypoints; }
    Fact*                       maxWaypointsPerPhase   (void)           { return &_maxWaypointsPerPhase; }
    Fact*                       startWaypointIndex     (void)           { return &_nextPhaseStartWaypointIndex; }
    Fact*                       showAllMissionItems    (void)           { return &_showAllMissionItems; }
    Fact*                       showCurrentMissionItems(void)           { return &_showCurrentMissionItems; }
    Fact*                       flightSpeed            (void)           { return &_flightSpeed; }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
228
    Fact*                       arrivalReturnSpeed     (void)           { return &_arrivalReturnSpeed; }
229 230 231 232 233 234 235 236
    Fact*                       altitude               (void)           { return &_altitude; }

    Fact*                       enableSnake            (void)           { return &_enableSnake; }
    Fact*                       snakeTileWidth         (void)           { return &_snakeTileWidth;}
    Fact*                       snakeTileHeight        (void)           { return &_snakeTileHeight;}
    Fact*                       snakeMinTileArea       (void)           { return &_snakeMinTileArea;}
    Fact*                       snakeLineDistance      (void)           { return &_snakeLineDistance;}
    Fact*                       snakeMinTransectLength (void)           { return &_snakeMinTransectLength;}
237
    QmlObjectListModel*         snakeTiles             (void)           { return _snakeTiles.QmlObjectListModel();}
238
    QVariantList                snakeTileCenterPoints  (void)           { return _snakeTileCenterPoints;}
239
    QVector<int>                nemoProgress           (void)           { return _nemoProgress.progress();}
240

241
    bool                        uploadOverrideRequired (void) const;
242 243
    double                      phaseDistance          (void) const;
    double                      phaseDuration          (void) const;
244
    bool                        vehicleHasLowBattery   (void) const;
245

Valentin Platzgummer's avatar
Valentin Platzgummer committed
246 247 248
    long                        snakeConnectionStatus (void) const;
    bool                        snakeCalcInProgress   (void) const;

249 250 251 252

    // Property setters
    void setMasterController        (PlanMasterController* masterController);
    void setMissionController       (MissionController* missionController);
253
    void setDataContainer           (WimaDataContainer* container);
254
    void setUploadOverrideRequired  (bool overrideRequired);
255

256
    // Member Methodes
257
    Q_INVOKABLE void nextPhase();
258 259
    Q_INVOKABLE void previousPhase();
    Q_INVOKABLE void resetPhase();
260
    Q_INVOKABLE bool uploadToVehicle();
261
    Q_INVOKABLE bool forceUploadToVehicle();
262 263
    Q_INVOKABLE void removeFromVehicle();    
    Q_INVOKABLE bool checkSmartRTLPreCondition(); // wrapper for _checkSmartRTLPreCondition(QString &errorString)
264
    Q_INVOKABLE bool calcReturnPath(); // wrapper for _calcReturnPath(QString &errorSring)#
265 266
    Q_INVOKABLE void executeSmartRTL(); // wrapper for _executeSmartRTL(QString &errorSring)
    Q_INVOKABLE void initSmartRTL();
267
    Q_INVOKABLE void removeVehicleTrajectoryHistory();
268

269

270 271 272 273
//    Q_INVOKABLE void saveToCurrent  ();
//    Q_INVOKABLE void saveToFile     (const QString& filename);
//    Q_INVOKABLE bool loadFromCurrent();
//    Q_INVOKABLE bool loadFromFile   (const QString& filename);
274 275


276
    // static Members
277
//    static const char* wimaFileExtension;
278
    static const char* areaItemsName;
279 280 281 282 283 284 285 286 287
    static const char* missionItemsName;    
    static const char* settingsGroup;
    static const char* endWaypointIndexName;
    static const char* enableWimaControllerName;
    static const char* overlapWaypointsName;
    static const char* maxWaypointsPerPhaseName;
    static const char* startWaypointIndexName;
    static const char* showAllMissionItemsName;
    static const char* showCurrentMissionItemsName;
288
    static const char* flightSpeedName;
289
    static const char* arrivalReturnSpeedName;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
290 291 292 293 294 295
    static const char* altitudeName;
    static const char* snakeTileWidthName;
    static const char* snakeTileHeightName;
    static const char* snakeMinTileAreaName;
    static const char* snakeLineDistanceName;
    static const char* snakeMinTransectLengthName;
296 297

    // Member Methodes
298
    QJsonDocument saveToJson(FileType fileType);
299

300
    bool calcShortestPath(const QGeoCoordinate &start, const QGeoCoordinate &destination, QVector<QGeoCoordinate> &path);
301

302
signals:
303 304 305
    void masterControllerChanged            (void);
    void missionControllerChanged           (void);
    void visualItemsChanged                 (void);
306
//    void currentFileChanged                 ();
307 308 309 310 311 312 313 314 315 316 317 318
    void dataContainerChanged               ();
    void readyForSaveSendChanged            (bool ready);
    void missionItemsChanged                (void);
    void currentMissionItemsChanged         (void);
    void waypointPathChanged                (void);
    void currentWaypointPathChanged         (void);
    void uploadOverrideRequiredChanged      (void);
    void phaseDistanceChanged               (void);
    void phaseDurationChanged               (void);
    void vehicleHasLowBatteryChanged        (void);
    void returnBatteryLowConfirmRequired    (void);
    void returnUserRequestConfirmRequired   (void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
319 320
    void snakeConnectionStatusChanged       (void);
    void snakeCalcInProgressChanged         (void);
321
    void snakeTilesChanged                  (void);
322
    void snakeTileCenterPointsChanged       (void);
323
    void nemoProgressChanged                (void);
324 325
private:
    enum SRTL_Reason {BatteryLow, UserRequest};
326
private slots:
Valentin Platzgummer's avatar
Valentin Platzgummer committed
327 328
    bool _fetchContainerData();
    bool _calcNextPhase(void);
329 330 331
    //void _updateWaypointPath                 (void);
    //void _updateCurrentPath                  (void);
    //void _updateNextWaypoint                 (void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
332
    void _recalcCurrentPhase                 (void);
333 334 335
    //bool _setTakeoffLandPosition             (void);
    void _updateOverlap                      (void);
    void _updateMaxWaypoints                 (void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
336 337 338 339 340 341 342 343 344 345 346 347 348
    void _updateflightSpeed                  (void);
    void _updateArrivalReturnSpeed           (void);
    void _updateAltitude                     (void);
    void _checkBatteryLevel                  (void);
    void _eventTimerHandler                  (void);
    void _smartRTLCleanUp                    (bool flying); // cleans up after successfull smart RTL
    void _enableDisableLowBatteryHandling    (QVariant enable);
    void _initSmartRTL                       ();
    void _executeSmartRTL                    ();
    void _setSnakeConnectionStatus           (SnakeConnectionStatus status);
    void _setSnakeCalcInProgress             (bool inProgress);
    bool _verifyScenarioDefined                    (void);
    bool _verifyScenarioDefinedWithErrorMessage    (void);
349
    void _snakeStoreWorkerResults            ();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
350
    void _startStopRosBridge                 ();
351
    void _initStartSnakeWorker               ();
352 353 354 355

private:
    void _setPhaseDistance(double distance);
    void _setPhaseDuration(double duration);
356 357 358
    bool _checkSmartRTLPreCondition(QString &errorString); // should be called from gui, befor calcReturnPath()
    bool _calcReturnPath(QString &errorSring); // Calculates return path (destination: service area center) for a flying vehicle
    void _setVehicleHasLowBattery(bool batteryLow);
359 360
    void _loadCurrentMissionItemsFromBuffer();
    void _saveCurrentMissionItemsToBuffer();
361

362 363 364
    void _progressFromJson(JsonDocUPtr pDoc,
                           QNemoProgress &progress);

365 366
    PlanMasterController   *_masterController;
    MissionController      *_missionController;
367
//    QString                 _currentFile; // file for saveing
368
    WimaDataContainer      *_container; // container for data exchange with WimaController
369
    QmlObjectListModel      _areas; // contains all visible areas
370
    WimaJoinedAreaData      _joinedArea; // joined area fromed by opArea, serArea, _corridor
371 372 373 374
    WimaMeasurementAreaData _measurementArea; // measurement area
    WimaServiceAreaData     _serviceArea; // area for supplying
    WimaCorridorData        _corridor; // corridor connecting opArea and serArea
    bool                    _localPlanDataValid;
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389


    WaypointManager::AreaInterface  _areaInterface;
    WaypointManager::Settings       _managerSettings;
    WaypointManager::DefaultManager _defaultManager;
    WaypointManager::DefaultManager _snakeManager;
    WaypointManager::ManagerBase   &_currentManager;

//    QmlObjectListModel      _missionItems; // all mission itmes (Mission Items) generaded by wimaPlaner, displayed in flightView
//    QmlObjectListModel      _currentMissionItems; // contains the current mission items, which are a sub set of _missionItems,
//                                                  // _currentMissionItems contains a number of mission items which can be worked off with a single battery chrage
//    QmlObjectListModel      _missionItemsBuffer; // Buffer to store mission items, e.g. for storing _currentMissionItems when smartRTL() is invoked
//    QVector<QGeoCoordinate> _waypoints; // path connecting the items in _missionItems
//    QVariantList            _currentWaypointPath; // path connecting the items in _currentMissionItems
//    QGeoCoordinate          _takeoffLandPostion;
390

391 392 393 394 395

    QMap<QString, FactMetaData*> _metaDataMap;
    SettingsFact                 _enableWimaController; // enables or disables the wimaControler
    SettingsFact                 _overlapWaypoints; // determines the number of overlapping waypoints between two consecutive mission phases
    SettingsFact                 _maxWaypointsPerPhase; // determines the maximum number waypoints per phase
396
    SettingsFact                 _nextPhaseStartWaypointIndex; // index (displayed on the map, -1 to get index of item in _missionItems) of the mission item
397
                                                      // defining the first element of the next phase
398 399
    SettingsFact                 _showAllMissionItems; // bool value, Determines whether the mission items of the overall mission are displayed or not.
    SettingsFact                 _showCurrentMissionItems; // bool value, Determines whether the mission items of the current mission phase are displayed or not.
400
    SettingsFact                 _flightSpeed; // mission flight speed
401
    SettingsFact                 _arrivalReturnSpeed; // arrival and return path speed
402
    SettingsFact                 _altitude; // mission altitude
Valentin Platzgummer's avatar
Valentin Platzgummer committed
403
    SettingsFact                 _enableSnake; // Enable Snake (see snake.h)
404

405 406 407 408
//    int                          _endWaypointIndex; // index of the mission item stored in _missionItems defining the last element
//                                                    // (which is not part of the return path) of _currentMissionItem
//    int                          _startWaypointIndex; // index of the mission item stored in _missionItems defining the first element
//                                                      // (which is not part of the arrival path) of _currentMissionItem
409 410
    bool                         _uploadOverrideRequired; // Is set to true if uploadToVehicle() did not suceed because the vehicle is not inside the service area.
                                                          // The user can override the upload lock with a slider, this will reset this variable to false.
411 412 413
    double                       _measurementPathLength; // the lenght of the phase in meters
    double                       _arrivalPathLength; // the length of the arrival and return path in meters
    double                       _returnPathLength; // the length of the arrival and return path in meters
414 415
    double                       _phaseDistance; // the lenth in meters of the current phase
    double                       _phaseDuration; // the phase duration in seconds
416 417
    double                       _phaseDistanceBuffer; // buffer for storing _phaseDistance when doing smart RTL
    double                       _phaseDurationBuffer; // buffer for storing _phaseDuration when doing smart RTL
418

Valentin Platzgummer's avatar
Valentin Platzgummer committed
419
    QTimer                       _eventTimer;
420 421 422
    QTimer                       _smartRTLAttemptTimer;
    SRTL_Reason                  _srtlReason;

423 424
    bool                         _vehicleHasLowBattery;
    bool                         _lowBatteryHandlingTriggered;
425 426
    bool                         _executingSmartRTL;

Valentin Platzgummer's avatar
Valentin Platzgummer committed
427 428 429 430 431 432 433 434 435 436 437 438
    // Snake
    SnakeConnectionStatus        _snakeConnectionStatus;
    bool                         _snakeCalcInProgress;
    bool                         _snakeRecalcNecessary;
    bool                         _scenarioDefinedBool;
    SnakeWorker                  _snakeWorker;
    Scenario                     _scenario;
    SettingsFact                 _snakeTileWidth;
    SettingsFact                 _snakeTileHeight;
    SettingsFact                 _snakeMinTileArea;
    SettingsFact                 _snakeLineDistance;
    SettingsFact                 _snakeMinTransectLength;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
439
    ::GeoPoint3D                 _snakeOrigin;
440
    SnakeTiles                   _snakeTiles; // tiles
441
    SnakeTilesLocal              _snakeTilesLocal; // tiles local coordinate system
442
    QVariantList                 _snakeTileCenterPoints;
443
    QNemoProgress                _nemoProgress; // measurement progress
Valentin Platzgummer's avatar
Valentin Platzgummer committed
444

Valentin Platzgummer's avatar
Valentin Platzgummer committed
445
    ROSBridgePtr                 _pRosBridge;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
446

447
};
448

449 450
/*
 * The following explains the structure of
Valentin Platzgummer's avatar
Valentin Platzgummer committed
451
 * _missionController.visualItems().
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
 *
 * Index        Description
 * --------------------------------------------
 * 0            MissionSettingsItem
 * 1            Takeoff Command
 * 2            Speed Command: arrivalReturnSpeed
 * 3            Arrival Path Waypoint 0
 * ...
 * 3+n-1        Arrival Path Waypoint n-1
 * 3+n          Speed Command: flightSpeed
 * 3+n+1        Circular Survey Waypoint 0
 * ...
 * 3+n+m        Circular Survey Waypoint m-1
 * 3+n+m+1      Speed Command: arrivalReturnSpeed
 * 3+n+m+2      Return Path Waypoint 0
 * ...
 * 3+n+m+2+l    Return Path Waypoint l-1
 * 3+n+m+2+l+1  Land command
 *
471 472 473
 * _currentMissionItems is equal to
 * _missionController.visualItems() except that it
 * is missing the MissionSettingsItem
474 475
 */

476

477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526

template<class CoordinateType>
CoordinateType getCoordinate(const SimpleMissionItem* item){
    return item->coordinate();
}

template<>
QVariant getCoordinate<QVariant>(const SimpleMissionItem* item);


/// extracts the coordinates stored in missionItems (list of MissionItems) and stores them in coordinateList.
template <class CoordinateType, template <class, class...> class ContainerType>
bool getCoordinates(QmlObjectListModel &missionItems,
                    ContainerType<CoordinateType> &coordinateList,
                    std::size_t startIndex,
                    std::size_t  endIndex){

    if (   startIndex < std::size_t(missionItems.count())
        && endIndex < std::size_t(missionItems.count()) ) {
        if (startIndex > endIndex) {
            if (!getCoordinates(missionItems, coordinateList, startIndex, missionItems.count()-1))
                return false;
            if (!getCoordinates(missionItems, coordinateList, 0, endIndex))
                return false;
        } else {
            for (std::size_t i = startIndex; i <= endIndex; i++) {
                SimpleMissionItem *mItem = missionItems.value<SimpleMissionItem *>(int(i));

                if (mItem == nullptr) {
                    coordinateList.clear();
                    return false;
                }
                coordinateList.append(getCoordinate<CoordinateType>(mItem));
            }
        }
    } else
        return false;

    return true;
}

/// extracts the coordinates stored in missionItems (list of MissionItems) and stores them in coordinateList.
template <class CoordinateType, template <class, class...> class ContainerType>
bool getCoordinates(QmlObjectListModel &missionItems,
                    ContainerType<CoordinateType> &coordinateList){

    return getCoordinates(missionItems, coordinateList, 0, missionItems.count());
}