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()) {
60 _terrainQuery = terrainQuery;
62 _terrainQuery->setParent(
this);
67void TerrainAtCoordinateBatchManager::_sendNextBatch()
69 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"_state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
73 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"waiting for current batch, restarting timer";
78 if (_requestQueue.isEmpty()) {
82 _sentRequests.clear();
85 QList<QGeoCoordinate> coords;
86 while (!_requestQueue.isEmpty()) {
87 const QueuedRequestInfo_t requestInfo = _requestQueue.dequeue();
88 const SentRequestInfo_t sentRequestInfo = {
89 requestInfo.terrainAtCoordinateQuery,
90 requestInfo.coordinates.count()
92 (void) _sentRequests.append(sentRequestInfo);
93 coords += requestInfo.coordinates;
94 if (coords.count() > 50) {
99 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"requesting next batch _state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
105void TerrainAtCoordinateBatchManager::_batchFailed()
107 const QList<double> noHeights;
109 for (
const SentRequestInfo_t &sentRequestInfo: _sentRequests) {
110 if (!sentRequestInfo.terrainAtCoordinateQuery.isNull()) {
111 sentRequestInfo.terrainAtCoordinateQuery->signalTerrainData(
false, noHeights);
115 _sentRequests.clear();
122 return QStringLiteral(
"Idle");
124 return QStringLiteral(
"Downloading");
129 return QStringLiteral(
"State unknown");
132void TerrainAtCoordinateBatchManager::_coordinateHeights(
bool success,
const QList<double> &heights)
136 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"signalled success:count" << success << heights.count();
143 int currentIndex = 0;
144 for (
const SentRequestInfo_t &sentRequestInfo: _sentRequests) {
145 if (!sentRequestInfo.terrainAtCoordinateQuery.isNull()) {
146 qCDebug(TerrainQueryVerboseLog) << Q_FUNC_INFO <<
"returned TerrainCoordinateQuery:count" << sentRequestInfo.terrainAtCoordinateQuery << sentRequestInfo.cCoord;
147 const QList<double> requestAltitudes = heights.mid(currentIndex, sentRequestInfo.cCoord);
148 sentRequestInfo.terrainAtCoordinateQuery->signalTerrainData(
true, requestAltitudes);
150 currentIndex += sentRequestInfo.cCoord;
152 _sentRequests.clear();
154 if (!_requestQueue.isEmpty()) {
155 _batchTimer->start();
163 , _autoDelete(autoDelete)
165 qCDebug(TerrainQueryLog) <<
this;
170 qCDebug(TerrainQueryLog) <<
this;
175 if (coordinates.isEmpty()) {
199 , _autoDelete(autoDelete)
202 qCDebug(TerrainQueryLog) <<
this;
204 qRegisterMetaType<TerrainPathQuery::PathHeightInfo_t>();
210 qCDebug(TerrainQueryLog) <<
this;
218void TerrainPathQuery::_pathHeights(
bool success,
double distanceBetween,
double finalDistanceBetween,
const QList<double> &heights)
220 PathHeightInfo_t pathHeightInfo;
221 pathHeightInfo.distanceBetween = distanceBetween;
222 pathHeightInfo.finalDistanceBetween = finalDistanceBetween;
223 pathHeightInfo.heights = heights;
234 , _autoDelete(autoDelete)
237 qCDebug(TerrainQueryLog) <<
this;
239 qRegisterMetaType<TerrainAreaQuery::CarpetHeightInfo_t>();
245 qCDebug(TerrainQueryLog) <<
this;
253void TerrainAreaQuery::_carpetHeights(
bool success,
double minHeight,
double maxHeight,
const QList<QList<double>> &carpet)
255 CarpetHeightInfo_t carpetHeightInfo;
256 carpetHeightInfo.minHeight = minHeight;
257 carpetHeightInfo.maxHeight = maxHeight;
258 carpetHeightInfo.carpet = carpet;
269 , _autoDelete(autoDelete)
272 qCDebug(TerrainQueryLog) <<
this;
274 qRegisterMetaType<QList<TerrainPathQuery::PathHeightInfo_t>>();
280 qCDebug(TerrainQueryLog) <<
this;
285 QList<QGeoCoordinate> path;
287 for (
const QVariant &geoVar: polyPath) {
288 (void) path.append(geoVar.value<QGeoCoordinate>());
296 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"count" << polyPath.count();
298 if (polyPath.count() < 2) {
299 qCWarning(TerrainQueryLog) << Q_FUNC_INFO <<
"polyPath requires at least 2 coordinates";
307 _rgCoords = polyPath;
309 _pathQuery->
requestData(_rgCoords[0], _rgCoords[1]);
314 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"success:_curIndex" << success << _curIndex;
317 _rgPathHeightInfo.clear();
322 (void) _rgPathHeightInfo.append(pathHeightInfo);
324 if (++_curIndex >= (_rgCoords.count() - 1)) {
325 qCDebug(TerrainQueryLog) << Q_FUNC_INFO <<
"complete";
331 _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()
void setTerrainQueryInterface(TerrainQueryInterface *terrainQuery)
Set custom terrain query interface (for testing). Takes ownership.
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)
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.
Base class for offline/online terrain queries.
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()