WimaPlaner.h 9.08 KB
Newer Older
1
#pragma once
2

3 4 5
#include <QObject>
#include "QGCMapPolygon.h"
#include "QmlObjectListModel.h"
6

7
#include "WimaArea.h"
8
#include "WimaAreaData.h"
9
#include "WimaServiceArea.h"
10
#include "WimaServiceAreaData.h"
11
#include "WimaMeasurementArea.h"
12
#include "WimaMeasurementAreaData.h"
13
#include "WimaCorridor.h"
14
#include "WimaCorridorData.h"
15 16 17 18
#include "WimaJoinedArea.h"
#include "WimaJoinedAreaData.h"
#include "WimaPlanData.h"
#include "WimaDataContainer.h"
19 20 21 22 23 24 25 26 27

#include "PlanMasterController.h"
#include "MissionController.h"
#include "SurveyComplexItem.h"
#include "SimpleMissionItem.h"
#include "MissionSettingsItem.h"
#include "JsonHelper.h"
#include "QGCApplication.h"

28 29 30 31
#include "OptimisationTools.h"
#include "PlanimetryCalculus.h"
#include "GeoUtilities.h"

32
#define TEST_FUN 0
33 34 35 36 37

#if TEST_FUN
    #include "TestPolygonCalculus.h"
    #include "testplanimetrycalculus.h"
#endif
38 39

class WimaPlaner : public QObject
40
{
41 42 43 44
    Q_OBJECT

    enum FileType {WimaFile, PlanFile};

45
public:
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    WimaPlaner(QObject *parent = nullptr);
    template<class T>
    WimaPlaner(T t, QObject *parent = nullptr) = delete;
    template<class T>
    WimaPlaner(T t) = delete;

    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)
    Q_PROPERTY(int                      currentPolygonIndex READ currentPolygonIndex    WRITE setCurrentPolygonIndex    NOTIFY currentPolygonIndexChanged)
    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)
    Q_PROPERTY(QGeoCoordinate           joinedAreaCenter    READ joinedAreaCenter                                       CONSTANT)
61
    Q_PROPERTY(WimaDataContainer*       dataContainer       READ dataContainer          WRITE setDataContainer          NOTIFY dataContainerChanged)
62
    Q_PROPERTY(bool                     syncronized         READ syncronizedWithController                              NOTIFY syncronizedWithControllerChanged)
63
    Q_PROPERTY(bool                     readyForSync        READ readyForSync                                           NOTIFY readyForSyncChanged)
64 65

    // Property accessors
66 67
    PlanMasterController*       masterController       (void)          { return _masterController; }
    MissionController*          missionController      (void)          { return _missionController; }
68 69 70 71 72 73 74
    QmlObjectListModel*         visualItems            (void) ;
    int                         currentPolygonIndex    (void) const    { return _currentAreaIndex; }
    QString                     currentFile            (void) const    { return _currentFile; }
    QStringList                 loadNameFilters        (void) const;
    QStringList                 saveNameFilters        (void) const;
    QString                     fileExtension          (void) const    { return wimaFileExtension; }
    QGeoCoordinate              joinedAreaCenter       (void) const;
75
    WimaDataContainer*          dataContainer          (void)          { return _container;}
76

77 78 79 80 81 82 83
    // Property setters
    void setMasterController        (PlanMasterController* masterController);
    void setMissionController       (MissionController* missionController);
    /// Sets the integer index pointing to the current polygon. Current polygon is set interactive.
    void setCurrentPolygonIndex     (int index);
    void setDataContainer           (WimaDataContainer* container);

84 85
    // Property acessors
    bool syncronizedWithController  ();
86
    bool readyForSync               ();
87

88
    // Member Methodes
89
    Q_INVOKABLE bool addMeasurementArea();
90 91 92 93
    /// Removes an area from _visualItems
    /// @param index Index of the area to be removed
    Q_INVOKABLE void removeArea(int index);
    Q_INVOKABLE bool addServiceArea();
94
    Q_INVOKABLE bool addCorridor();
95 96 97 98
    /// Remove all areas from WimaPlaner and all mission items from MissionController
    Q_INVOKABLE void removeAll();
    /// Recalculates vehicle corridor, flight path, etc.
    Q_INVOKABLE bool updateMission();
99 100
    /// Pushes the generated mission data to the container, for exchange with wimaController
    Q_INVOKABLE void pushToContainer();
101 102 103 104 105 106 107 108 109

    Q_INVOKABLE void saveToCurrent();
    Q_INVOKABLE void saveToFile(const QString& filename);
    Q_INVOKABLE bool loadFromCurrent();
    Q_INVOKABLE bool loadFromFile(const QString& filename);

    Q_INVOKABLE void resetAllInteractive(void);
    Q_INVOKABLE void setInteractive(void);

110
    QJsonDocument saveToJson(FileType fileType);
111

112 113
    bool calcShortestPath(const QGeoCoordinate &start, const QGeoCoordinate &destination, QList<QGeoCoordinate> &path);

114 115 116 117 118 119
    // static Members
    static const char* wimaFileExtension;
    static const char* areaItemsName;
    static const char* missionItemsName;

signals:
120 121 122 123 124 125 126
    void masterControllerChanged            (void);
    void missionControllerChanged           (void);
    void visualItemsChanged                 (void);
    void currentPolygonIndexChanged         (int index);
    void currentFileChanged                 ();
    void dataContainerChanged               ();
    void syncronizedWithControllerChanged   (void);
127
    void readyForSyncChanged                (void);
128 129

private slots:
130 131
    void recalcPolygonInteractivity         (int index);
    bool calcArrivalAndReturnPath           (void);
132
    bool recalcJoinedArea                   ();
133
    // called by _updateTimer::timeout signal, updates different mission parts, if parameters (e.g. survey or areas) have changed
134 135
    void updateTimerSlot                    ();
    void setSyncronizedWithControllerFalse  (void);
136
    void autoLoadMission                    (void);
137 138 139
private:
signals:
    void joinedAreaValidChanged();
140
private:
141 142
    // Member Functions
    WimaPlanData toPlanData();
143 144 145
    void         setSyncronizedWithController   (bool sync);
    void         setReadyForSync                (bool ready);
    void         setJoinedAreaValid             (bool valid);
146 147

    // Member Variables
148 149 150 151 152 153
    PlanMasterController   *_masterController;
    MissionController      *_missionController;
    int                     _currentAreaIndex;
    QString                 _currentFile; // file for saveing
    WimaDataContainer      *_container; // container for data exchange with WimaController
    QmlObjectListModel      _visualItems; // contains all visible areas
154
    WimaJoinedArea          _joinedArea; // joined area fromed by _measurementArea, _serviceArea, _corridor
155
    bool                    _joinedAreaValid;
156 157 158
    WimaMeasurementArea     _measurementArea; // measurement area
    WimaServiceArea         _serviceArea; // area for supplying
    WimaCorridor            _corridor; // corridor connecting _measurementArea and _serviceArea
159 160
    int                     _arrivalPathLength; // the number waypoints the arrival path consists of (path from takeoff to first measurement point)
    int                     _returnPathLength; // the number waypoints the return path consists of (path from last measurement point to land)
161 162 163

    CircularSurveyComplexItem* _circularSurvey; // pointer to the CircularSurvey item in _missionController.visualItems()

164
    // auto update
165
    QTimer                  _updateTimer; // on this timers timeout different mission parts will be updated, if parameters (e.g. survey or areas) have changed
166 167 168 169 170 171 172 173 174 175
    QGeoCoordinate          _lastSurveyRefPoint; // stores the SurveyRefPoint of the previous timer call
    bool                    _surveyRefChanging; // true if SurveyRefPoint is changing
    QVariantList            _lastMeasurementAreaPath; // stores the path of _measurementArea, at the time instance of the previous timer call
    bool                    _measurementAreaChanging; // true if the path of the _measurementArea is changing
    QVariantList            _lastCorridorPath; // stores the path of _corridor, at the time instance of the previous timer call
    bool                    _corridorChanging; // true if the path of the _corridor is changing
    QVariantList            _lastServiceAreaPath; // stores the path of _serviceArea, at the time instance of the previous timer call
    bool                    _serviceAreaChanging; // true if the path of the _serviceArea is changing

    // sync stuff
176
    bool                    _syncronizedWithController; // true if planData is syncronized with wimaController
177
    bool                    _readyForSync; // gets set by updateMission and calcArrivalAndReturnPath
178 179

    QTimer                  _autoLoadTimer; // timer to auto load mission after some time, prevents seg. faults
180
};