6#include <QtCore/QTimer>
15 , _batchTimer(new QTimer(this))
18 qCDebug(TerrainQueryLog) <<
this;
20 _batchTimer->setSingleShot(
true);
21 _batchTimer->setInterval(_batchTimeout);
23 (void) connect(_batchTimer, &QTimer::timeout,
this, &TerrainAtCoordinateBatchManager::_sendNextBatch);
29 qCDebug(TerrainQueryLog) <<
this;
34 return _terrainAtCoordinateBatchManager();
39 if (coordinates.isEmpty()) {
43 const QueuedRequestInfo_t queuedRequestInfo = {
44 terrainAtCoordinateQuery,
47 _requestQueue.enqueue(queuedRequestInfo);
49 if (!_batchTimer->isActive()) {
54void TerrainAtCoordinateBatchManager::_sendNextBatch()
56 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"_state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
60 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"waiting for current batch, restarting timer";
65 if (_requestQueue.isEmpty()) {
69 _sentRequests.clear();
72 QList<QGeoCoordinate> coords;
73 while (!_requestQueue.isEmpty()) {
74 const QueuedRequestInfo_t requestInfo = _requestQueue.dequeue();
75 const SentRequestInfo_t sentRequestInfo = {
76 requestInfo.terrainAtCoordinateQuery,
77 requestInfo.coordinates.count()
79 (void) _sentRequests.append(sentRequestInfo);
80 coords += requestInfo.coordinates;
81 if (coords.count() > 50) {
86 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"requesting next batch _state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
92void TerrainAtCoordinateBatchManager::_batchFailed()
94 const QList<double> noHeights;
96 for (
const SentRequestInfo_t &sentRequestInfo: _sentRequests) {
97 if (!sentRequestInfo.terrainAtCoordinateQuery.isNull()) {
98 sentRequestInfo.terrainAtCoordinateQuery->signalTerrainData(
false, noHeights);
102 _sentRequests.clear();
109 return QStringLiteral(
"Idle");
111 return QStringLiteral(
"Downloading");
116 return QStringLiteral(
"State unknown");
119void TerrainAtCoordinateBatchManager::_coordinateHeights(
bool success,
const QList<double> &heights)
123 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"signalled success:count" << success << heights.count();
130 int currentIndex = 0;
131 for (
const SentRequestInfo_t &sentRequestInfo: _sentRequests) {
132 if (!sentRequestInfo.terrainAtCoordinateQuery.isNull()) {
133 qCDebug(TerrainQueryVerboseLog) << Q_FUNC_INFO <<
"returned TerrainCoordinateQuery:count" << sentRequestInfo.terrainAtCoordinateQuery << sentRequestInfo.cCoord;
134 const QList<double> requestAltitudes = heights.mid(currentIndex, sentRequestInfo.cCoord);
135 sentRequestInfo.terrainAtCoordinateQuery->signalTerrainData(
true, requestAltitudes);
137 currentIndex += sentRequestInfo.cCoord;
139 _sentRequests.clear();
141 if (!_requestQueue.isEmpty()) {
142 _batchTimer->start();
150 , _autoDelete(autoDelete)
152 qCDebug(TerrainQueryLog) <<
this;
157 qCDebug(TerrainQueryLog) <<
this;
162 if (coordinates.isEmpty()) {
186 , _autoDelete(autoDelete)
189 qCDebug(TerrainQueryLog) <<
this;
191 qRegisterMetaType<TerrainPathQuery::PathHeightInfo_t>();
197 qCDebug(TerrainQueryLog) <<
this;
205void TerrainPathQuery::_pathHeights(
bool success,
double distanceBetween,
double finalDistanceBetween,
const QList<double> &heights)
209 pathHeightInfo.finalDistanceBetween = finalDistanceBetween;
210 pathHeightInfo.heights = heights;
221 , _autoDelete(autoDelete)
224 qCDebug(TerrainQueryLog) <<
this;
226 qRegisterMetaType<TerrainAreaQuery::CarpetHeightInfo_t>();
232 qCDebug(TerrainQueryLog) <<
this;
240void TerrainAreaQuery::_carpetHeights(
bool success,
double minHeight,
double maxHeight,
const QList<QList<double>> &carpet)
242 CarpetHeightInfo_t carpetHeightInfo;
243 carpetHeightInfo.minHeight = minHeight;
244 carpetHeightInfo.maxHeight = maxHeight;
245 carpetHeightInfo.carpet = carpet;
256 , _autoDelete(autoDelete)
259 qCDebug(TerrainQueryLog) <<
this;
261 qRegisterMetaType<QList<TerrainPathQuery::PathHeightInfo_t>>();
267 qCDebug(TerrainQueryLog) <<
this;
272 QList<QGeoCoordinate> path;
274 for (
const QVariant &geoVar: polyPath) {
275 (void) path.append(geoVar.value<QGeoCoordinate>());
283 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"count" << polyPath.count();
285 if (polyPath.count() < 2) {
286 qCWarning(TerrainQueryLog) << Q_FUNC_INFO <<
"polyPath requires at least 2 coordinates";
294 _rgCoords = polyPath;
296 _pathQuery->
requestData(_rgCoords[0], _rgCoords[1]);
301 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"success:_curIndex" << success << _curIndex;
304 _rgPathHeightInfo.clear();
309 (void) _rgPathHeightInfo.append(pathHeightInfo);
311 if (++_curIndex >= (_rgCoords.count() - 1)) {
312 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"complete";
318 _pathQuery->
requestData(_rgCoords[_curIndex], _rgCoords[_curIndex + 1]);
Q_GLOBAL_STATIC(FirmwarePluginFactoryRegister, _firmwarePluginFactoryRegisterInstance)
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void requestData(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord)
void terrainDataReceived(bool success, const TerrainAreaQuery::CarpetHeightInfo_t &carpetHeightInfo)
TerrainAreaQuery(bool autoDelete, QObject *parent=nullptr)
void addQuery(TerrainAtCoordinateQuery *terrainAtCoordinateQuery, const QList< QGeoCoordinate > &coordinates)
~TerrainAtCoordinateBatchManager()
static TerrainAtCoordinateBatchManager * instance()
NOTE: TerrainAtCoordinateQuery is not thread safe. All instances/calls to ElevationProvider must be o...
void terrainDataReceived(bool success, const QList< double > &heights)
void requestData(const QList< QGeoCoordinate > &coordinates)
void signalTerrainData(bool success, const QList< double > &heights)
TerrainAtCoordinateQuery(bool autoDelete, QObject *parent=nullptr)
static bool getAltitudesForCoordinates(const QList< QGeoCoordinate > &coordinates, QList< double > &altitudes, bool &error)
~TerrainAtCoordinateQuery()
void terrainDataReceived(bool success, const TerrainPathQuery::PathHeightInfo_t &pathHeightInfo)
Signalled when terrain data comes back from server.
TerrainPathQuery(bool autoDelete, QObject *parent=nullptr)
TerrainPathHeightInfo PathHeightInfo_t
void requestData(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord)
TerrainPolyPathQuery(bool autoDelete, QObject *parent=nullptr)
void requestData(const QVariantList &polyPath)
void terrainDataReceived(bool success, const QList< TerrainPathQuery::PathHeightInfo_t > &rgPathHeightInfo)
Signalled when terrain data comes back from server.
void pathHeightsReceived(bool success, double distanceBetween, double finalDistanceBetween, const QList< double > &heights)
void carpetHeightsReceived(bool success, double minHeight, double maxHeight, const QList< QList< double > > &carpet)
virtual void requestPathHeights(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord)
virtual void requestCoordinateHeights(const QList< QGeoCoordinate > &coordinates)
void coordinateHeightsReceived(bool success, const QList< double > &heights)
virtual void requestCarpetHeights(const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord, bool statsOnly)
bool getAltitudesForCoordinates(const QList< QGeoCoordinate > &coordinates, QList< double > &altitudes, bool &error)
static TerrainTileManager * instance()
double distanceBetween
Distance between each height value.