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

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

6 7 8 9
#include "Geometry/WimaCorridor.h"
#include "Geometry/WimaCorridorData.h"
#include "Geometry/WimaJoinedArea.h"
#include "Geometry/WimaJoinedAreaData.h"
10 11 12 13
#include "Geometry/WimaMeasurementArea.h"
#include "Geometry/WimaMeasurementAreaData.h"
#include "Geometry/WimaServiceArea.h"
#include "Geometry/WimaServiceAreaData.h"
14
#include "WimaPlanData.h"
15 16

#include "JsonHelper.h"
17

18 19 20
class MissionController;
class PlanMasterController;
class WimaBridge;
21

22 23
class WimaPlaner : public QObject {
  Q_OBJECT
24

25
  enum FileType { WimaFile, PlanFile };
26

27
public:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
  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)
  Q_PROPERTY(WimaBridge *wimaBridge READ wimaBridge WRITE setWimaBridge NOTIFY
                 wimaBridgeChanged)
  Q_PROPERTY(bool syncronized READ syncronizedWithController NOTIFY
                 syncronizedWithControllerChanged)
  Q_PROPERTY(bool readyForSync READ readyForSync NOTIFY readyForSyncChanged)

  // Property accessors
  PlanMasterController *masterController(void) { return _masterController; }
  MissionController *missionController(void) { return _missionController; }
  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;
  WimaBridge *wimaBridge(void) { return _wimaBridge; }

  // 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 setWimaBridge(WimaBridge *bridge);

  // Property acessors
  bool syncronizedWithController();
  bool readyForSync();

  // Member Methodes
  Q_INVOKABLE WimaPlaner *thisPointer();
  Q_INVOKABLE bool addMeasurementArea();
  /// Removes an area from _visualItems
  /// @param index Index of the area to be removed
  Q_INVOKABLE void removeArea(int index);
  Q_INVOKABLE bool addServiceArea();
  Q_INVOKABLE bool addCorridor();
  /// 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();
  /// Pushes the generated mission data to the wimaController.
  Q_INVOKABLE void pushToWimaController();

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

  QJsonDocument saveToJson(FileType fileType);

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

  // static Members
  static const char *wimaFileExtension;
  static const char *areaItemsName;
  static const char *missionItemsName;
109 110

signals:
111 112 113 114 115 116 117 118
  void masterControllerChanged(void);
  void missionControllerChanged(void);
  void visualItemsChanged(void);
  void currentPolygonIndexChanged(int index);
  void currentFileChanged();
  void wimaBridgeChanged();
  void syncronizedWithControllerChanged(void);
  void readyForSyncChanged(void);
119 120

private slots:
121 122 123 124 125 126 127
  void recalcPolygonInteractivity(int index);
  bool calcArrivalAndReturnPath(void);
  bool recalcJoinedArea();
  // called by _updateTimer::timeout signal, updates different mission parts, if
  // parameters (e.g. survey or areas) have changed
  void updateTimerSlot();
  void setSyncronizedWithControllerFalse(void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
128
#ifndef NDEBUG
129
  void autoLoadMission(void);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
130
#endif
131 132
  void startCalcArrivalAndReturnTimer(void);

133 134
private:
signals:
135 136
  void joinedAreaValidChanged();

137
private:
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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
  // Member Functions
  WimaPlanData toPlanData();
  void setSyncronizedWithController(bool sync);
  void setReadyForSync(bool ready);
  void setJoinedAreaValid(bool valid);

  // Member Variables
  PlanMasterController *_masterController;
  MissionController *_missionController;
  int _currentAreaIndex;
  QString _currentFile;    // file for saveing
  WimaBridge *_wimaBridge; // container for data exchange with WimaController
  QmlObjectListModel _visualItems; // contains all visible areas
  WimaJoinedArea _joinedArea;      // joined area fromed by _measurementArea,
                                   // _serviceArea, _corridor
  bool _joinedAreaValid;
  WimaMeasurementArea _measurementArea; // measurement area
  WimaServiceArea _serviceArea;         // area for supplying
  WimaCorridor
      _corridor; // corridor connecting _measurementArea and _serviceArea
  unsigned long
      _arrivalPathLength; // the number waypoints the arrival path consists of
                          // (path from takeoff to first measurement point)
  unsigned long
      _returnPathLength; // the number waypoints the return path consists of
                         // (path from last measurement point to land)

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

  // auto update
  QTimer _updateTimer; // on this timers timeout different mission parts will be
                       // updated, if parameters (e.g. survey or areas) have
                       // changed
  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
  bool _syncronizedWithController; // true if planData is syncronized with
                                   // wimaController
  bool _readyForSync; // gets set by updateMission and calcArrivalAndReturnPath
191

Valentin Platzgummer's avatar
Valentin Platzgummer committed
192
#ifndef NDEBUG
193 194
  QTimer _autoLoadTimer; // timer to auto load mission after some time, prevents
                         // seg. faults
Valentin Platzgummer's avatar
Valentin Platzgummer committed
195
#endif
196
  QTimer _calcArrivalAndReturnPathTimer;
197
};