Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
24f8cd47
Commit
24f8cd47
authored
Mar 17, 2018
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure for TerrainQueryInterface base class
parent
bf202aac
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
231 additions
and
151 deletions
+231
-151
TransectStyleComplexItem.cc
src/MissionManager/TransectStyleComplexItem.cc
+2
-2
VisualMissionItem.cc
src/MissionManager/VisualMissionItem.cc
+2
-2
VisualMissionItem.h
src/MissionManager/VisualMissionItem.h
+1
-1
TerrainQuery.cc
src/Terrain/TerrainQuery.cc
+161
-116
TerrainQuery.h
src/Terrain/TerrainQuery.h
+65
-30
No files found.
src/MissionManager/TransectStyleComplexItem.cc
View file @
24f8cd47
...
@@ -374,7 +374,7 @@ void TransectStyleComplexItem::_adjustTransectPointsForTerrain(void)
...
@@ -374,7 +374,7 @@ void TransectStyleComplexItem::_adjustTransectPointsForTerrain(void)
bool
surveyEdgeIndicator
=
transectPoint
.
altitude
()
==
_surveyEdgeIndicator
;
bool
surveyEdgeIndicator
=
transectPoint
.
altitude
()
==
_surveyEdgeIndicator
;
if
(
_followTerrain
)
{
if
(
_followTerrain
)
{
transectPoint
.
setAltitude
(
_transectsPathHeightInfo
[
i
].
rgHeight
[
0
]
+
altitude
);
transectPoint
.
setAltitude
(
_transectsPathHeightInfo
[
i
].
heights
[
0
]
+
altitude
);
}
else
{
}
else
{
transectPoint
.
setAltitude
(
altitude
);
transectPoint
.
setAltitude
(
altitude
);
}
}
...
@@ -390,7 +390,7 @@ void TransectStyleComplexItem::_adjustTransectPointsForTerrain(void)
...
@@ -390,7 +390,7 @@ void TransectStyleComplexItem::_adjustTransectPointsForTerrain(void)
QGeoCoordinate
transectPoint
=
_transectPoints
.
last
().
value
<
QGeoCoordinate
>
();
QGeoCoordinate
transectPoint
=
_transectPoints
.
last
().
value
<
QGeoCoordinate
>
();
bool
surveyEdgeIndicator
=
transectPoint
.
altitude
()
==
_surveyEdgeIndicator
;
bool
surveyEdgeIndicator
=
transectPoint
.
altitude
()
==
_surveyEdgeIndicator
;
if
(
_followTerrain
){
if
(
_followTerrain
){
transectPoint
.
setAltitude
(
_transectsPathHeightInfo
.
last
().
rgHeight
.
last
()
+
altitude
);
transectPoint
.
setAltitude
(
_transectsPathHeightInfo
.
last
().
heights
.
last
()
+
altitude
);
}
else
{
}
else
{
transectPoint
.
setAltitude
(
altitude
);
transectPoint
.
setAltitude
(
altitude
);
}
}
...
...
src/MissionManager/VisualMissionItem.cc
View file @
24f8cd47
...
@@ -180,10 +180,10 @@ void VisualMissionItem::_reallyUpdateTerrainAltitude(void)
...
@@ -180,10 +180,10 @@ void VisualMissionItem::_reallyUpdateTerrainAltitude(void)
}
}
}
}
void
VisualMissionItem
::
_terrainDataReceived
(
bool
success
,
QList
<
float
>
altitude
s
)
void
VisualMissionItem
::
_terrainDataReceived
(
bool
success
,
QList
<
double
>
height
s
)
{
{
if
(
success
)
{
if
(
success
)
{
_terrainAltitude
=
altitude
s
[
0
];
_terrainAltitude
=
height
s
[
0
];
emit
terrainAltitudeChanged
(
_terrainAltitude
);
emit
terrainAltitudeChanged
(
_terrainAltitude
);
sender
()
->
deleteLater
();
sender
()
->
deleteLater
();
}
}
...
...
src/MissionManager/VisualMissionItem.h
View file @
24f8cd47
...
@@ -211,7 +211,7 @@ protected:
...
@@ -211,7 +211,7 @@ protected:
private
slots
:
private
slots
:
void
_updateTerrainAltitude
(
void
);
void
_updateTerrainAltitude
(
void
);
void
_reallyUpdateTerrainAltitude
(
void
);
void
_reallyUpdateTerrainAltitude
(
void
);
void
_terrainDataReceived
(
bool
success
,
QList
<
float
>
altitude
s
);
void
_terrainDataReceived
(
bool
success
,
QList
<
double
>
height
s
);
private:
private:
QTimer
_updateTerrainTimer
;
QTimer
_updateTerrainTimer
;
...
...
src/Terrain/TerrainQuery.cc
View file @
24f8cd47
...
@@ -23,16 +23,65 @@ QGC_LOGGING_CATEGORY(TerrainQueryLog, "TerrainQueryLog")
...
@@ -23,16 +23,65 @@ QGC_LOGGING_CATEGORY(TerrainQueryLog, "TerrainQueryLog")
Q_GLOBAL_STATIC
(
TerrainAtCoordinateBatchManager
,
_TerrainAtCoordinateBatchManager
)
Q_GLOBAL_STATIC
(
TerrainAtCoordinateBatchManager
,
_TerrainAtCoordinateBatchManager
)
Terrain
Query
::
Terrain
Query
(
QObject
*
parent
)
Terrain
AirMapQuery
::
TerrainAirMap
Query
(
QObject
*
parent
)
:
QObject
(
parent
)
:
TerrainQueryInterface
(
parent
)
{
{
}
}
void
TerrainQuery
::
_sendQuery
(
const
QString
&
path
,
const
QUrlQuery
&
urlQuery
)
void
TerrainAirMapQuery
::
requestCoordinateHeights
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
{
QString
points
;
foreach
(
const
QGeoCoordinate
&
coord
,
coordinates
)
{
points
+=
QString
::
number
(
coord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
coord
.
longitude
(),
'f'
,
10
)
+
","
;
}
points
=
points
.
mid
(
0
,
points
.
length
()
-
1
);
// remove the last ',' from string
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_queryMode
=
QueryModeCoordinates
;
_sendQuery
(
QString
()
/* path */
,
query
);
}
void
TerrainAirMapQuery
::
requestPathHeights
(
const
QGeoCoordinate
&
fromCoord
,
const
QGeoCoordinate
&
toCoord
)
{
QString
points
;
points
+=
QString
::
number
(
fromCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
fromCoord
.
longitude
(),
'f'
,
10
)
+
","
;
points
+=
QString
::
number
(
toCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
toCoord
.
longitude
(),
'f'
,
10
);
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_queryMode
=
QueryModePath
;
_sendQuery
(
QStringLiteral
(
"/path"
),
query
);
}
void
TerrainAirMapQuery
::
requestCarpetHeights
(
const
QGeoCoordinate
&
swCoord
,
const
QGeoCoordinate
&
neCoord
,
bool
statsOnly
)
{
QString
points
;
points
+=
QString
::
number
(
swCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
swCoord
.
longitude
(),
'f'
,
10
)
+
","
;
points
+=
QString
::
number
(
neCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
neCoord
.
longitude
(),
'f'
,
10
);
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_queryMode
=
QueryModeCarpet
;
_carpetStatsOnly
=
statsOnly
;
_sendQuery
(
QStringLiteral
(
"/carpet"
),
query
);
}
void
TerrainAirMapQuery
::
_sendQuery
(
const
QString
&
path
,
const
QUrlQuery
&
urlQuery
)
{
{
QUrl
url
(
QStringLiteral
(
"https://api.airmap.com/elevation/v1/ele"
)
+
path
);
QUrl
url
(
QStringLiteral
(
"https://api.airmap.com/elevation/v1/ele"
)
+
path
);
url
.
setQuery
(
urlQuery
);
url
.
setQuery
(
urlQuery
);
qCDebug
(
TerrainQueryLog
)
<<
"_sendQuery"
<<
url
;
QNetworkRequest
request
(
url
);
QNetworkRequest
request
(
url
);
...
@@ -43,21 +92,21 @@ void TerrainQuery::_sendQuery(const QString& path, const QUrlQuery& urlQuery)
...
@@ -43,21 +92,21 @@ void TerrainQuery::_sendQuery(const QString& path, const QUrlQuery& urlQuery)
QNetworkReply
*
networkReply
=
_networkManager
.
get
(
request
);
QNetworkReply
*
networkReply
=
_networkManager
.
get
(
request
);
if
(
!
networkReply
)
{
if
(
!
networkReply
)
{
qCDebug
(
TerrainQueryLog
)
<<
"QNetworkManager::Get did not return QNetworkReply"
;
qCDebug
(
TerrainQueryLog
)
<<
"QNetworkManager::Get did not return QNetworkReply"
;
_
terrainData
(
false
/* success */
,
QJsonValue
()
);
_
requestFailed
(
);
return
;
return
;
}
}
connect
(
networkReply
,
&
QNetworkReply
::
finished
,
this
,
&
TerrainQuery
::
_requestFinished
);
connect
(
networkReply
,
&
QNetworkReply
::
finished
,
this
,
&
Terrain
AirMap
Query
::
_requestFinished
);
}
}
void
TerrainQuery
::
_requestFinished
(
void
)
void
Terrain
AirMap
Query
::
_requestFinished
(
void
)
{
{
QNetworkReply
*
reply
=
qobject_cast
<
QNetworkReply
*>
(
QObject
::
sender
());
QNetworkReply
*
reply
=
qobject_cast
<
QNetworkReply
*>
(
QObject
::
sender
());
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
if
(
reply
->
error
()
!=
QNetworkReply
::
NoError
)
{
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished error:"
<<
reply
->
error
();
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished error:"
<<
reply
->
error
();
reply
->
deleteLater
();
reply
->
deleteLater
();
_
terrainData
(
false
/* success */
,
QJsonValue
()
);
_
requestFailed
(
);
return
;
return
;
}
}
...
@@ -69,7 +118,7 @@ void TerrainQuery::_requestFinished(void)
...
@@ -69,7 +118,7 @@ void TerrainQuery::_requestFinished(void)
QJsonDocument
responseJson
=
QJsonDocument
::
fromJson
(
responseBytes
,
&
parseError
);
QJsonDocument
responseJson
=
QJsonDocument
::
fromJson
(
responseBytes
,
&
parseError
);
if
(
parseError
.
error
!=
QJsonParseError
::
NoError
)
{
if
(
parseError
.
error
!=
QJsonParseError
::
NoError
)
{
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished unable to parse json:"
<<
parseError
.
errorString
();
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished unable to parse json:"
<<
parseError
.
errorString
();
_
terrainData
(
false
/* success */
,
QJsonValue
()
);
_
requestFailed
(
);
return
;
return
;
}
}
...
@@ -78,12 +127,93 @@ void TerrainQuery::_requestFinished(void)
...
@@ -78,12 +127,93 @@ void TerrainQuery::_requestFinished(void)
QString
status
=
rootObject
[
"status"
].
toString
();
QString
status
=
rootObject
[
"status"
].
toString
();
if
(
status
!=
"success"
)
{
if
(
status
!=
"success"
)
{
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished status != success:"
<<
status
;
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished status != success:"
<<
status
;
_
terrainData
(
false
/* success */
,
QJsonValue
()
);
_
requestFailed
(
);
return
;
return
;
}
}
// Send back data
// Send back data
_terrainData
(
true
/* success */
,
rootObject
[
"data"
]);
const
QJsonValue
&
jsonData
=
rootObject
[
"data"
];
qCDebug
(
TerrainQueryLog
)
<<
"_requestFinished"
<<
jsonData
;
switch
(
_queryMode
)
{
case
QueryModeCoordinates
:
emit
_parseCoordinateData
(
jsonData
);
break
;
case
QueryModePath
:
emit
_parsePathData
(
jsonData
);
break
;
case
QueryModeCarpet
:
emit
_parseCarpetData
(
jsonData
);
break
;
}
}
void
TerrainAirMapQuery
::
_requestFailed
(
void
)
{
switch
(
_queryMode
)
{
case
QueryModeCoordinates
:
emit
coordinateHeights
(
false
/* success */
,
QList
<
double
>
()
/* heights */
);
break
;
case
QueryModePath
:
emit
pathHeights
(
false
/* success */
,
qQNaN
()
/* latStep */
,
qQNaN
()
/* lonStep */
,
QList
<
double
>
()
/* heights */
);
break
;
case
QueryModeCarpet
:
emit
carpetHeights
(
false
/* success */
,
qQNaN
()
/* minHeight */
,
qQNaN
()
/* maxHeight */
,
QList
<
QList
<
double
>>
()
/* carpet */
);
break
;
}
}
void
TerrainAirMapQuery
::
_parseCoordinateData
(
const
QJsonValue
&
coordinateJson
)
{
QList
<
double
>
heights
;
const
QJsonArray
&
dataArray
=
coordinateJson
.
toArray
();
for
(
int
i
=
0
;
i
<
dataArray
.
count
();
i
++
)
{
heights
.
append
(
dataArray
[
i
].
toDouble
());
}
emit
coordinateHeights
(
true
/* success */
,
heights
);
}
void
TerrainAirMapQuery
::
_parsePathData
(
const
QJsonValue
&
pathJson
)
{
QJsonObject
jsonObject
=
pathJson
.
toArray
()[
0
].
toObject
();
QJsonArray
stepArray
=
jsonObject
[
"step"
].
toArray
();
QJsonArray
profileArray
=
jsonObject
[
"profile"
].
toArray
();
double
latStep
=
stepArray
[
0
].
toDouble
();
double
lonStep
=
stepArray
[
1
].
toDouble
();
QList
<
double
>
heights
;
foreach
(
const
QJsonValue
&
profileValue
,
profileArray
)
{
heights
.
append
(
profileValue
.
toDouble
());
}
emit
pathHeights
(
true
/* success */
,
latStep
,
lonStep
,
heights
);
}
void
TerrainAirMapQuery
::
_parseCarpetData
(
const
QJsonValue
&
carpetJson
)
{
QJsonObject
jsonObject
=
carpetJson
.
toArray
()[
0
].
toObject
();
QJsonObject
statsObject
=
jsonObject
[
"stats"
].
toObject
();
double
minHeight
=
statsObject
[
"min"
].
toDouble
();
double
maxHeight
=
statsObject
[
"min"
].
toDouble
();
QList
<
QList
<
double
>>
carpet
;
if
(
!
_carpetStatsOnly
)
{
QJsonArray
carpetArray
=
jsonObject
[
"carpet"
].
toArray
();
for
(
int
i
=
0
;
i
<
carpetArray
.
count
();
i
++
)
{
QJsonArray
rowArray
=
carpetArray
[
i
].
toArray
();
carpet
.
append
(
QList
<
double
>
());
for
(
int
j
=
0
;
j
<
rowArray
.
count
();
j
++
)
{
double
height
=
rowArray
[
j
].
toDouble
();
carpet
.
last
().
append
(
height
);
}
}
}
emit
carpetHeights
(
true
/*success*/
,
minHeight
,
maxHeight
,
carpet
);
}
}
TerrainAtCoordinateBatchManager
::
TerrainAtCoordinateBatchManager
(
void
)
TerrainAtCoordinateBatchManager
::
TerrainAtCoordinateBatchManager
(
void
)
...
@@ -91,6 +221,7 @@ TerrainAtCoordinateBatchManager::TerrainAtCoordinateBatchManager(void)
...
@@ -91,6 +221,7 @@ TerrainAtCoordinateBatchManager::TerrainAtCoordinateBatchManager(void)
_batchTimer
.
setSingleShot
(
true
);
_batchTimer
.
setSingleShot
(
true
);
_batchTimer
.
setInterval
(
_batchTimeout
);
_batchTimer
.
setInterval
(
_batchTimeout
);
connect
(
&
_batchTimer
,
&
QTimer
::
timeout
,
this
,
&
TerrainAtCoordinateBatchManager
::
_sendNextBatch
);
connect
(
&
_batchTimer
,
&
QTimer
::
timeout
,
this
,
&
TerrainAtCoordinateBatchManager
::
_sendNextBatch
);
connect
(
&
_terrainQuery
,
&
TerrainQueryInterface
::
coordinateHeights
,
this
,
&
TerrainAtCoordinateBatchManager
::
_coordinateHeights
);
}
}
void
TerrainAtCoordinateBatchManager
::
addQuery
(
TerrainAtCoordinateQuery
*
terrainAtCoordinateQuery
,
const
QList
<
QGeoCoordinate
>&
coordinates
)
void
TerrainAtCoordinateBatchManager
::
addQuery
(
TerrainAtCoordinateQuery
*
terrainAtCoordinateQuery
,
const
QList
<
QGeoCoordinate
>&
coordinates
)
...
@@ -123,35 +254,28 @@ void TerrainAtCoordinateBatchManager::_sendNextBatch(void)
...
@@ -123,35 +254,28 @@ void TerrainAtCoordinateBatchManager::_sendNextBatch(void)
_sentRequests
.
clear
();
_sentRequests
.
clear
();
// Convert coordinates to point strings for json query
// Convert coordinates to point strings for json query
Q
String
point
s
;
Q
List
<
QGeoCoordinate
>
coord
s
;
foreach
(
const
QueuedRequestInfo_t
&
requestInfo
,
_requestQueue
)
{
foreach
(
const
QueuedRequestInfo_t
&
requestInfo
,
_requestQueue
)
{
SentRequestInfo_t
sentRequestInfo
=
{
requestInfo
.
terrainAtCoordinateQuery
,
false
,
requestInfo
.
coordinates
.
count
()
};
SentRequestInfo_t
sentRequestInfo
=
{
requestInfo
.
terrainAtCoordinateQuery
,
false
,
requestInfo
.
coordinates
.
count
()
};
qCDebug
(
TerrainQueryLog
)
<<
"Building request: coordinate count"
<<
requestInfo
.
coordinates
.
count
();
qCDebug
(
TerrainQueryLog
)
<<
"Building request: coordinate count"
<<
requestInfo
.
coordinates
.
count
();
_sentRequests
.
append
(
sentRequestInfo
);
_sentRequests
.
append
(
sentRequestInfo
);
foreach
(
const
QGeoCoordinate
&
coord
,
requestInfo
.
coordinates
)
{
coords
+=
requestInfo
.
coordinates
;
points
+=
QString
::
number
(
coord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
coord
.
longitude
(),
'f'
,
10
)
+
","
;
}
}
}
points
=
points
.
mid
(
0
,
points
.
length
()
-
1
);
// remove the last ',' from string
_requestQueue
.
clear
();
_requestQueue
.
clear
();
QUrlQuery
query
;
_terrainQuery
.
requestCoordinateHeights
(
coords
);
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_sendQuery
(
QString
()
/* path */
,
query
);
_state
=
State
::
Downloading
;
_state
=
State
::
Downloading
;
}
}
void
TerrainAtCoordinateBatchManager
::
_batchFailed
(
void
)
void
TerrainAtCoordinateBatchManager
::
_batchFailed
(
void
)
{
{
QList
<
float
>
noAltitude
s
;
QList
<
double
>
noHeight
s
;
foreach
(
const
SentRequestInfo_t
&
sentRequestInfo
,
_sentRequests
)
{
foreach
(
const
SentRequestInfo_t
&
sentRequestInfo
,
_sentRequests
)
{
if
(
!
sentRequestInfo
.
queryObjectDestroyed
)
{
if
(
!
sentRequestInfo
.
queryObjectDestroyed
)
{
disconnect
(
sentRequestInfo
.
terrainAtCoordinateQuery
,
&
TerrainAtCoordinateQuery
::
destroyed
,
this
,
&
TerrainAtCoordinateBatchManager
::
_queryObjectDestroyed
);
disconnect
(
sentRequestInfo
.
terrainAtCoordinateQuery
,
&
TerrainAtCoordinateQuery
::
destroyed
,
this
,
&
TerrainAtCoordinateBatchManager
::
_queryObjectDestroyed
);
sentRequestInfo
.
terrainAtCoordinateQuery
->
_signalTerrainData
(
false
,
no
Altitude
s
);
sentRequestInfo
.
terrainAtCoordinateQuery
->
_signalTerrainData
(
false
,
no
Height
s
);
}
}
}
}
_sentRequests
.
clear
();
_sentRequests
.
clear
();
...
@@ -195,7 +319,7 @@ QString TerrainAtCoordinateBatchManager::_stateToString(State state)
...
@@ -195,7 +319,7 @@ QString TerrainAtCoordinateBatchManager::_stateToString(State state)
return
QStringLiteral
(
"State unknown"
);
return
QStringLiteral
(
"State unknown"
);
}
}
void
TerrainAtCoordinateBatchManager
::
_
terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
void
TerrainAtCoordinateBatchManager
::
_
coordinateHeights
(
bool
success
,
QList
<
double
>
heights
)
{
{
_state
=
State
::
Idle
;
_state
=
State
::
Idle
;
...
@@ -204,17 +328,11 @@ void TerrainAtCoordinateBatchManager::_terrainData(bool success, const QJsonValu
...
@@ -204,17 +328,11 @@ void TerrainAtCoordinateBatchManager::_terrainData(bool success, const QJsonValu
return
;
return
;
}
}
QList
<
float
>
altitudes
;
const
QJsonArray
&
dataArray
=
dataJsonValue
.
toArray
();
for
(
int
i
=
0
;
i
<
dataArray
.
count
();
i
++
)
{
altitudes
.
push_back
(
dataArray
[
i
].
toDouble
());
}
int
currentIndex
=
0
;
int
currentIndex
=
0
;
foreach
(
const
SentRequestInfo_t
&
sentRequestInfo
,
_sentRequests
)
{
foreach
(
const
SentRequestInfo_t
&
sentRequestInfo
,
_sentRequests
)
{
if
(
!
sentRequestInfo
.
queryObjectDestroyed
)
{
if
(
!
sentRequestInfo
.
queryObjectDestroyed
)
{
disconnect
(
sentRequestInfo
.
terrainAtCoordinateQuery
,
&
TerrainAtCoordinateQuery
::
destroyed
,
this
,
&
TerrainAtCoordinateBatchManager
::
_queryObjectDestroyed
);
disconnect
(
sentRequestInfo
.
terrainAtCoordinateQuery
,
&
TerrainAtCoordinateQuery
::
destroyed
,
this
,
&
TerrainAtCoordinateBatchManager
::
_queryObjectDestroyed
);
QList
<
float
>
requestAltitudes
=
altitude
s
.
mid
(
currentIndex
,
sentRequestInfo
.
cCoord
);
QList
<
double
>
requestAltitudes
=
height
s
.
mid
(
currentIndex
,
sentRequestInfo
.
cCoord
);
sentRequestInfo
.
terrainAtCoordinateQuery
->
_signalTerrainData
(
true
,
requestAltitudes
);
sentRequestInfo
.
terrainAtCoordinateQuery
->
_signalTerrainData
(
true
,
requestAltitudes
);
currentIndex
+=
sentRequestInfo
.
cCoord
;
currentIndex
+=
sentRequestInfo
.
cCoord
;
}
}
...
@@ -236,54 +354,30 @@ void TerrainAtCoordinateQuery::requestData(const QList<QGeoCoordinate>& coordina
...
@@ -236,54 +354,30 @@ void TerrainAtCoordinateQuery::requestData(const QList<QGeoCoordinate>& coordina
_TerrainAtCoordinateBatchManager
->
addQuery
(
this
,
coordinates
);
_TerrainAtCoordinateBatchManager
->
addQuery
(
this
,
coordinates
);
}
}
void
TerrainAtCoordinateQuery
::
_signalTerrainData
(
bool
success
,
QList
<
float
>&
altitude
s
)
void
TerrainAtCoordinateQuery
::
_signalTerrainData
(
bool
success
,
QList
<
double
>&
height
s
)
{
{
emit
terrainData
(
success
,
altitude
s
);
emit
terrainData
(
success
,
height
s
);
}
}
TerrainPathQuery
::
TerrainPathQuery
(
QObject
*
parent
)
TerrainPathQuery
::
TerrainPathQuery
(
QObject
*
parent
)
:
TerrainQuery
(
parent
)
:
QObject
(
parent
)
{
{
qRegisterMetaType
<
PathHeightInfo_t
>
();
qRegisterMetaType
<
PathHeightInfo_t
>
();
connect
(
&
_terrainQuery
,
&
TerrainQueryInterface
::
pathHeights
,
this
,
&
TerrainPathQuery
::
_pathHeights
);
}
}
void
TerrainPathQuery
::
requestData
(
const
QGeoCoordinate
&
fromCoord
,
const
QGeoCoordinate
&
toCoord
)
void
TerrainPathQuery
::
requestData
(
const
QGeoCoordinate
&
fromCoord
,
const
QGeoCoordinate
&
toCoord
)
{
{
if
(
!
fromCoord
.
isValid
()
||
!
toCoord
.
isValid
())
{
_terrainQuery
.
requestPathHeights
(
fromCoord
,
toCoord
);
return
;
}
QString
points
;
points
+=
QString
::
number
(
fromCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
fromCoord
.
longitude
(),
'f'
,
10
)
+
","
;
points
+=
QString
::
number
(
toCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
toCoord
.
longitude
(),
'f'
,
10
);
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_sendQuery
(
QStringLiteral
(
"/path"
),
query
);
}
}
void
TerrainPathQuery
::
_
terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
void
TerrainPathQuery
::
_
pathHeights
(
bool
success
,
double
latStep
,
double
lonStep
,
const
QList
<
double
>&
heights
)
{
{
if
(
!
success
)
{
emit
terrainData
(
false
/* success */
,
PathHeightInfo_t
());
return
;
}
QJsonObject
jsonObject
=
dataJsonValue
.
toArray
()[
0
].
toObject
();
QJsonArray
stepArray
=
jsonObject
[
"step"
].
toArray
();
QJsonArray
profileArray
=
jsonObject
[
"profile"
].
toArray
();
PathHeightInfo_t
pathHeightInfo
;
PathHeightInfo_t
pathHeightInfo
;
pathHeightInfo
.
latStep
=
stepArray
[
0
].
toDouble
();
pathHeightInfo
.
latStep
=
latStep
;
pathHeightInfo
.
lonStep
=
stepArray
[
1
].
toDouble
();
pathHeightInfo
.
lonStep
=
lonStep
;
foreach
(
const
QJsonValue
&
profileValue
,
profileArray
)
{
pathHeightInfo
.
heights
=
heights
;
pathHeightInfo
.
rgHeight
.
append
(
profileValue
.
toDouble
());
emit
terrainData
(
success
,
pathHeightInfo
);
}
emit
terrainData
(
true
/* success */
,
pathHeightInfo
);
}
}
TerrainPolyPathQuery
::
TerrainPolyPathQuery
(
QObject
*
parent
)
TerrainPolyPathQuery
::
TerrainPolyPathQuery
(
QObject
*
parent
)
...
@@ -331,61 +425,12 @@ void TerrainPolyPathQuery::_terrainDataReceived(bool success, const TerrainPathQ
...
@@ -331,61 +425,12 @@ void TerrainPolyPathQuery::_terrainDataReceived(bool success, const TerrainPathQ
}
}
TerrainCarpetQuery
::
TerrainCarpetQuery
(
QObject
*
parent
)
TerrainCarpetQuery
::
TerrainCarpetQuery
(
QObject
*
parent
)
:
TerrainQuery
(
parent
)
:
QObject
(
parent
)
{
{
connect
(
&
_terrainQuery
,
&
TerrainQueryInterface
::
carpetHeights
,
this
,
&
TerrainCarpetQuery
::
terrainData
);
}
}
void
TerrainCarpetQuery
::
requestData
(
const
QGeoCoordinate
&
swCoord
,
const
QGeoCoordinate
&
neCoord
,
bool
statsOnly
)
void
TerrainCarpetQuery
::
requestData
(
const
QGeoCoordinate
&
swCoord
,
const
QGeoCoordinate
&
neCoord
,
bool
statsOnly
)
{
{
if
(
!
swCoord
.
isValid
()
||
!
neCoord
.
isValid
())
{
_terrainQuery
.
requestCarpetHeights
(
swCoord
,
neCoord
,
statsOnly
);
return
;
}
_statsOnly
=
statsOnly
;
QString
points
;
points
+=
QString
::
number
(
swCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
swCoord
.
longitude
(),
'f'
,
10
)
+
","
;
points
+=
QString
::
number
(
neCoord
.
latitude
(),
'f'
,
10
)
+
","
+
QString
::
number
(
neCoord
.
longitude
(),
'f'
,
10
);
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"points"
),
points
);
_sendQuery
(
QStringLiteral
(
"/carpet"
),
query
);
}
void
TerrainCarpetQuery
::
_terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
{
if
(
!
success
)
{
emit
terrainData
(
false
/* success */
,
qQNaN
()
/* minHeight */
,
qQNaN
()
/* maxHeight */
,
QList
<
QList
<
double
>>
()
/* carpet */
);
return
;
}
qDebug
()
<<
dataJsonValue
;
QJsonObject
jsonObject
=
dataJsonValue
.
toArray
()[
0
].
toObject
();
QJsonObject
statsObject
=
jsonObject
[
"stats"
].
toObject
();
double
minHeight
=
statsObject
[
"min"
].
toDouble
();
double
maxHeight
=
statsObject
[
"min"
].
toDouble
();
QList
<
QList
<
double
>>
carpet
;
if
(
!
_statsOnly
)
{
QJsonArray
carpetArray
=
jsonObject
[
"carpet"
].
toArray
();
for
(
int
i
=
0
;
i
<
carpetArray
.
count
();
i
++
)
{
QJsonArray
rowArray
=
carpetArray
[
i
].
toArray
();
carpet
.
append
(
QList
<
double
>
());
for
(
int
j
=
0
;
j
<
rowArray
.
count
();
j
++
)
{
double
height
=
rowArray
[
j
].
toDouble
();
carpet
.
last
().
append
(
height
);
}
}
}
emit
terrainData
(
true
/*success*/
,
minHeight
,
maxHeight
,
carpet
);
}
}
src/Terrain/TerrainQuery.h
View file @
24f8cd47
...
@@ -21,31 +21,71 @@ Q_DECLARE_LOGGING_CATEGORY(TerrainQueryLog)
...
@@ -21,31 +21,71 @@ Q_DECLARE_LOGGING_CATEGORY(TerrainQueryLog)
class
TerrainAtCoordinateQuery
;
class
TerrainAtCoordinateQuery
;
// Base class for all terrain query objects
/// Base class for offline/online terrain queries
class
TerrainQuery
:
public
QObject
{
class
TerrainQueryInterface
:
public
QObject
{
Q_OBJECT
Q_OBJECT
public:
public:
TerrainQuery
(
QObject
*
parent
=
NULL
);
TerrainQueryInterface
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
/// Request terrain heights for specified coodinates.
/// Signals: coordinateHeights when data is available
virtual
void
requestCoordinateHeights
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
=
0
;
/// Requests terrain heights along the path specified by the two coordinates.
/// Signals: pathHeights
/// @param coordinates to query
virtual
void
requestPathHeights
(
const
QGeoCoordinate
&
fromCoord
,
const
QGeoCoordinate
&
toCoord
)
=
0
;
/// Request terrain heights for the rectangular area specified.
/// Signals: carpetHeights when data is available
/// @param swCoord South-West bound of rectangular area to query
/// @param neCoord North-East bound of rectangular area to query
/// @param statsOnly true: Return only stats, no carpet data
virtual
void
requestCarpetHeights
(
const
QGeoCoordinate
&
swCoord
,
const
QGeoCoordinate
&
neCoord
,
bool
statsOnly
)
=
0
;
signals:
void
coordinateHeights
(
bool
success
,
QList
<
double
>
heights
);
void
pathHeights
(
bool
success
,
double
latStep
,
double
lonStep
,
const
QList
<
double
>&
heights
);
void
carpetHeights
(
bool
success
,
double
minHeight
,
double
maxHeight
,
const
QList
<
QList
<
double
>>&
carpet
);
};
protected:
/// AirMap online implementation of terrain queries
// Send a query to AirMap terrain servers. Data and errors are returned back from super class virtual implementations.
class
TerrainAirMapQuery
:
public
TerrainQueryInterface
{
// @param path Additional path to add to url
Q_OBJECT
// @param urlQuery Query to send
void
_sendQuery
(
const
QString
&
path
,
const
QUrlQuery
&
urlQuery
);
public:
TerrainAirMapQuery
(
QObject
*
parent
=
NULL
);
// Called when the request to the server fails or succeeds
// Overrides from TerrainQueryInterface
virtual
void
_terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
=
0
;
void
requestCoordinateHeights
(
const
QList
<
QGeoCoordinate
>&
coordinates
)
final
;
void
requestPathHeights
(
const
QGeoCoordinate
&
fromCoord
,
const
QGeoCoordinate
&
toCoord
)
final
;
void
requestCarpetHeights
(
const
QGeoCoordinate
&
swCoord
,
const
QGeoCoordinate
&
neCoord
,
bool
statsOnly
)
final
;
private
slots
:
private
slots
:
void
_requestFinished
(
void
);
void
_requestFinished
(
void
);
private:
private:
QNetworkAccessManager
_networkManager
;
void
_sendQuery
(
const
QString
&
path
,
const
QUrlQuery
&
urlQuery
);
void
_requestFailed
(
void
);
void
_parseCoordinateData
(
const
QJsonValue
&
coordinateJson
);
void
_parsePathData
(
const
QJsonValue
&
pathJson
);
void
_parseCarpetData
(
const
QJsonValue
&
carpetJson
);
enum
QueryMode
{
QueryModeCoordinates
,
QueryModePath
,
QueryModeCarpet
};
QNetworkAccessManager
_networkManager
;
QueryMode
_queryMode
;
bool
_carpetStatsOnly
;
};
};
/// Used internally by TerrainAtCoordinateQuery to batch coordinate requests together
/// Used internally by TerrainAtCoordinateQuery to batch coordinate requests together
class
TerrainAtCoordinateBatchManager
:
public
TerrainQuery
{
class
TerrainAtCoordinateBatchManager
:
public
QObject
{
Q_OBJECT
Q_OBJECT
public:
public:
...
@@ -53,13 +93,10 @@ public:
...
@@ -53,13 +93,10 @@ public:
void
addQuery
(
TerrainAtCoordinateQuery
*
terrainAtCoordinateQuery
,
const
QList
<
QGeoCoordinate
>&
coordinates
);
void
addQuery
(
TerrainAtCoordinateQuery
*
terrainAtCoordinateQuery
,
const
QList
<
QGeoCoordinate
>&
coordinates
);
protected:
// Overrides from TerrainQuery
void
_terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
final
;
private
slots
:
private
slots
:
void
_sendNextBatch
(
void
);
void
_sendNextBatch
(
void
);
void
_queryObjectDestroyed
(
QObject
*
elevationProvider
);
void
_queryObjectDestroyed
(
QObject
*
elevationProvider
);
void
_coordinateHeights
(
bool
success
,
QList
<
double
>
heights
);
private:
private:
typedef
struct
{
typedef
struct
{
...
@@ -87,6 +124,7 @@ private:
...
@@ -87,6 +124,7 @@ private:
State
_state
=
State
::
Idle
;
State
_state
=
State
::
Idle
;
const
int
_batchTimeout
=
500
;
const
int
_batchTimeout
=
500
;
QTimer
_batchTimer
;
QTimer
_batchTimer
;
TerrainAirMapQuery
_terrainQuery
;
};
};
/// NOTE: TerrainAtCoordinateQuery is not thread safe. All instances/calls to ElevationProvider must be on main thread.
/// NOTE: TerrainAtCoordinateQuery is not thread safe. All instances/calls to ElevationProvider must be on main thread.
...
@@ -102,13 +140,13 @@ public:
...
@@ -102,13 +140,13 @@ public:
void
requestData
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
void
requestData
(
const
QList
<
QGeoCoordinate
>&
coordinates
);
// Internal method
// Internal method
void
_signalTerrainData
(
bool
success
,
QList
<
float
>&
altitude
s
);
void
_signalTerrainData
(
bool
success
,
QList
<
double
>&
height
s
);
signals:
signals:
void
terrainData
(
bool
success
,
QList
<
float
>
altitude
s
);
void
terrainData
(
bool
success
,
QList
<
double
>
height
s
);
};
};
class
TerrainPathQuery
:
public
TerrainQuery
class
TerrainPathQuery
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
...
@@ -123,16 +161,18 @@ public:
...
@@ -123,16 +161,18 @@ public:
typedef
struct
{
typedef
struct
{
double
latStep
;
///< Amount of latitudinal distance between each returned height
double
latStep
;
///< Amount of latitudinal distance between each returned height
double
lonStep
;
///< Amount of longitudinal distance between each returned height
double
lonStep
;
///< Amount of longitudinal distance between each returned height
QList
<
double
>
rgHeight
;
///< Terrain heights along path
QList
<
double
>
heights
;
///< Terrain heights along path
}
PathHeightInfo_t
;
}
PathHeightInfo_t
;
signals:
signals:
/// Signalled when terrain data comes back from server
/// Signalled when terrain data comes back from server
void
terrainData
(
bool
success
,
const
PathHeightInfo_t
&
pathHeightInfo
);
void
terrainData
(
bool
success
,
const
PathHeightInfo_t
&
pathHeightInfo
);
protected:
private
slots
:
// Overrides from TerrainQuery
void
_pathHeights
(
bool
success
,
double
latStep
,
double
lonStep
,
const
QList
<
double
>&
heights
);
void
_terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
final
;
private:
TerrainAirMapQuery
_terrainQuery
;
};
};
Q_DECLARE_METATYPE
(
TerrainPathQuery
::
PathHeightInfo_t
)
Q_DECLARE_METATYPE
(
TerrainPathQuery
::
PathHeightInfo_t
)
...
@@ -165,7 +205,7 @@ private:
...
@@ -165,7 +205,7 @@ private:
};
};
class
TerrainCarpetQuery
:
public
TerrainQuery
class
TerrainCarpetQuery
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
...
@@ -183,12 +223,7 @@ signals:
...
@@ -183,12 +223,7 @@ signals:
/// Signalled when terrain data comes back from server
/// Signalled when terrain data comes back from server
void
terrainData
(
bool
success
,
double
minHeight
,
double
maxHeight
,
const
QList
<
QList
<
double
>>&
carpet
);
void
terrainData
(
bool
success
,
double
minHeight
,
double
maxHeight
,
const
QList
<
QList
<
double
>>&
carpet
);
protected:
// Overrides from TerrainQuery
void
_terrainData
(
bool
success
,
const
QJsonValue
&
dataJsonValue
)
final
;
private:
private:
bool
_statsOnl
y
;
TerrainAirMapQuery
_terrainQuer
y
;
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment