WimaPlaner.h 9.21 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 33
#include "QSignalBlocker"

34
#define TEST_FUN 0
35 36 37 38 39

#if TEST_FUN
    #include "TestPolygonCalculus.h"
    #include "testplanimetrycalculus.h"
#endif
40 41

class WimaPlaner : public QObject
42
{
43 44 45 46
    Q_OBJECT

    enum FileType {WimaFile, PlanFile};

47
public:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    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)
63
    Q_PROPERTY(WimaDataContainer*       dataContainer       READ dataContainer          WRITE setDataContainer          NOTIFY dataContainerChanged)
64
    Q_PROPERTY(bool                     syncronized         READ syncronizedWithController                              NOTIFY syncronizedWithControllerChanged)
65
    Q_PROPERTY(bool                     readyForSync        READ readyForSync                                           NOTIFY readyForSyncChanged)
66 67

    // Property accessors
68 69
    PlanMasterController*       masterController       (void)          { return _masterController; }
    MissionController*          missionController      (void)          { return _missionController; }
70 71 72 73 74 75 76
    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;
77
    WimaDataContainer*          dataContainer          (void)          { return _container;}
78

79 80 81 82 83 84 85
    // 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);

86 87
    // Property acessors
    bool syncronizedWithController  ();
88
    bool readyForSync               ();
89

90
    // Member Methodes
91
    Q_INVOKABLE bool addMeasurementArea();
92 93 94 95
    /// Removes an area from _visualItems
    /// @param index Index of the area to be removed
    Q_INVOKABLE void removeArea(int index);
    Q_INVOKABLE bool addServiceArea();
96
    Q_INVOKABLE bool addCorridor();
97 98 99 100
    /// 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();
101 102
    /// Pushes the generated mission data to the container, for exchange with wimaController
    Q_INVOKABLE void pushToContainer();
103 104 105 106 107 108 109 110 111

    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);

112
    QJsonDocument saveToJson(FileType fileType);
113

114
    bool calcShortestPath(const QGeoCoordinate &start, const QGeoCoordinate &destination, QVector<QGeoCoordinate> &path);
115

116 117 118 119 120 121
    // static Members
    static const char* wimaFileExtension;
    static const char* areaItemsName;
    static const char* missionItemsName;

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

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

    // Member Variables
151 152 153 154 155 156
    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
157
    WimaJoinedArea          _joinedArea; // joined area fromed by _measurementArea, _serviceArea, _corridor
158
    bool                    _joinedAreaValid;
159 160 161
    WimaMeasurementArea     _measurementArea; // measurement area
    WimaServiceArea         _serviceArea; // area for supplying
    WimaCorridor            _corridor; // corridor connecting _measurementArea and _serviceArea
162 163
    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)
164 165 166

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

167
    // auto update
168
    QTimer                  _updateTimer; // on this timers timeout different mission parts will be updated, if parameters (e.g. survey or areas) have changed
169 170 171 172 173 174 175 176 177 178
    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
179
    bool                    _syncronizedWithController; // true if planData is syncronized with wimaController
180
    bool                    _readyForSync; // gets set by updateMission and calcArrivalAndReturnPath
181 182

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