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
ec5bffef
Unverified
Commit
ec5bffef
authored
May 10, 2018
by
Don Gagne
Committed by
GitHub
May 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6442 from DonLakeFlyer/GeoFenceSave
Implement GeoFence persistence
parents
95be320c
63abdfd5
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
132 additions
and
53 deletions
+132
-53
GeoFenceController.cc
src/MissionManager/GeoFenceController.cc
+64
-23
GeoFenceController.h
src/MissionManager/GeoFenceController.h
+6
-1
QGCFenceCircle.cc
src/MissionManager/QGCFenceCircle.cc
+13
-7
QGCFenceCircle.h
src/MissionManager/QGCFenceCircle.h
+2
-0
QGCFencePolygon.cc
src/MissionManager/QGCFencePolygon.cc
+13
-7
QGCFencePolygon.h
src/MissionManager/QGCFencePolygon.h
+2
-0
QGCMapCircle.cc
src/MissionManager/QGCMapCircle.cc
+2
-2
RallyPointController.cc
src/MissionManager/RallyPointController.cc
+21
-6
RallyPointController.h
src/MissionManager/RallyPointController.h
+2
-0
GeoFenceMapVisuals.qml
src/PlanView/GeoFenceMapVisuals.qml
+7
-7
No files found.
src/MissionManager/GeoFenceController.cc
View file @
ec5bffef
...
...
@@ -34,6 +34,9 @@ QGC_LOGGING_CATEGORY(GeoFenceControllerLog, "GeoFenceControllerLog")
const
char
*
GeoFenceController
::
_jsonFileTypeValue
=
"GeoFence"
;
const
char
*
GeoFenceController
::
_jsonBreachReturnKey
=
"breachReturn"
;
const
char
*
GeoFenceController
::
_jsonPolygonsKey
=
"polygons"
;
const
char
*
GeoFenceController
::
_jsonCirclesKey
=
"circles"
;
const
char
*
GeoFenceController
::
_px4ParamCircularFence
=
"GF_MAX_HOR_DIST"
;
GeoFenceController
::
GeoFenceController
(
PlanMasterController
*
masterController
,
QObject
*
parent
)
...
...
@@ -116,46 +119,84 @@ void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle)
bool
GeoFenceController
::
load
(
const
QJsonObject
&
json
,
QString
&
errorString
)
{
Q_UNUSED
(
json
);
Q_UNUSED
(
errorString
);
removeAll
();
errorString
.
clear
();
#if 0
QString errorStr;
QString errorMessage = tr("GeoFence: %1");
if
(
json
.
contains
(
JsonHelper
::
jsonVersionKey
)
&&
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
==
1
)
{
// We just ignore old version 1 data
return
true
;
}
if (json.contains(_jsonBreachReturnKey) &&
!JsonHelper::loadGeoCoordinate(json[_jsonBreachReturnKey], false /* altitudeRequired */, _breachReturnPoint, errorStr)) {
errorString = errorMessage.arg(errorStr);
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
JsonHelper
::
jsonVersionKey
,
QJsonValue
::
Double
,
true
},
{
_jsonCirclesKey
,
QJsonValue
::
Array
,
true
},
{
_jsonPolygonsKey
,
QJsonValue
::
Array
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
json
,
keyInfoList
,
errorString
))
{
return
false
;
}
if (
!_mapPolygon.loadFromJson(json, true, errorStr)
) {
errorString =
errorMessage.arg(errorStr
);
if
(
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
!=
_jsonCurrentVersion
)
{
errorString
=
tr
(
"GeoFence supports version %1"
).
arg
(
_jsonCurrentVersion
);
return
false
;
}
_mapPolygon.setDirty(false);
setDirty(false);
QJsonArray
jsonPolygonArray
=
json
[
_jsonPolygonsKey
].
toArray
();
foreach
(
const
QJsonValue
&
jsonPolygonValue
,
jsonPolygonArray
)
{
if
(
jsonPolygonValue
.
type
()
!=
QJsonValue
::
Object
)
{
errorString
=
tr
(
"GeoFence polygon not stored as object"
);
return
false
;
}
QGCFencePolygon
*
fencePolygon
=
new
QGCFencePolygon
(
false
/* inclusion */
,
this
/* parent */
);
if
(
!
fencePolygon
->
loadFromJson
(
jsonPolygonValue
.
toObject
(),
true
/* required */
,
errorString
))
{
return
false
;
}
_polygons
.
append
(
fencePolygon
);
}
QJsonArray
jsonCircleArray
=
json
[
_jsonCirclesKey
].
toArray
();
foreach
(
const
QJsonValue
&
jsonCircleValue
,
jsonCircleArray
)
{
if
(
jsonCircleValue
.
type
()
!=
QJsonValue
::
Object
)
{
errorString
=
tr
(
"GeoFence circle not stored as object"
);
return
false
;
}
QGCFenceCircle
*
fenceCircle
=
new
QGCFenceCircle
(
this
/* parent */
);
if
(
!
fenceCircle
->
loadFromJson
(
jsonCircleValue
.
toObject
(),
errorString
))
{
return
false
;
}
_circles
.
append
(
fenceCircle
);
}
setDirty
(
false
);
_signalAll
();
#endif
return
true
;
}
void
GeoFenceController
::
save
(
QJsonObject
&
json
)
void
GeoFenceController
::
save
(
QJsonObject
&
json
)
{
Q_UNUSED
(
json
);
#if 0
json[JsonHelper::jsonVersionKey] = 1;
json
[
JsonHelper
::
jsonVersionKey
]
=
_jsonCurrentVersion
;
if (_breachReturnPoint.isValid()) {
QJsonValue jsonBreachReturn;
JsonHelper::saveGeoCoordinate(_breachReturnPoint, false /* writeAltitude */, jsonBreachReturn);
json[_jsonBreachReturnKey] = jsonBreachReturn;
QJsonArray
jsonPolygonArray
;
for
(
int
i
=
0
;
i
<
_polygons
.
count
();
i
++
)
{
QJsonObject
jsonPolygon
;
QGCFencePolygon
*
fencePolygon
=
_polygons
.
value
<
QGCFencePolygon
*>
(
i
);
fencePolygon
->
saveToJson
(
jsonPolygon
);
jsonPolygonArray
.
append
(
jsonPolygon
);
}
json
[
_jsonPolygonsKey
]
=
jsonPolygonArray
;
_mapPolygon.saveToJson(json);
#endif
QJsonArray
jsonCircleArray
;
for
(
int
i
=
0
;
i
<
_circles
.
count
();
i
++
)
{
QJsonObject
jsonCircle
;
QGCFenceCircle
*
fenceCircle
=
_circles
.
value
<
QGCFenceCircle
*>
(
i
);
fenceCircle
->
saveToJson
(
jsonCircle
);
jsonCircleArray
.
append
(
jsonCircle
);
}
json
[
_jsonCirclesKey
]
=
jsonCircleArray
;
}
void
GeoFenceController
::
removeAll
(
void
)
...
...
src/MissionManager/GeoFenceController.h
View file @
ec5bffef
...
...
@@ -111,9 +111,14 @@ private:
bool
_itemsRequested
;
Fact
*
_px4ParamCircularFenceFact
;
static
const
char
*
_px4ParamCircularFence
;
static
const
int
_jsonCurrentVersion
=
2
;
static
const
char
*
_jsonFileTypeValue
;
static
const
char
*
_jsonBreachReturnKey
;
static
const
char
*
_px4ParamCircularFence
;
static
const
char
*
_jsonPolygonsKey
;
static
const
char
*
_jsonCirclesKey
;
};
#endif
src/MissionManager/QGCFenceCircle.cc
View file @
ec5bffef
...
...
@@ -54,26 +54,32 @@ void QGCFenceCircle::_setDirty(void)
void
QGCFenceCircle
::
saveToJson
(
QJsonObject
&
json
)
{
QGCMapCircle
::
saveToJson
(
json
);
json
[
JsonHelper
::
jsonVersionKey
]
=
_jsonCurrentVersion
;
json
[
_jsonInclusionKey
]
=
_inclusion
;
QGCMapCircle
::
saveToJson
(
json
);
}
bool
QGCFenceCircle
::
loadFromJson
(
const
QJsonObject
&
json
,
QString
&
errorString
)
{
if
(
!
QGCMapCircle
::
loadFromJson
(
json
,
errorString
))
{
return
false
;
}
errorString
.
clear
();
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
_jsonInclusionKey
,
QJsonValue
::
Bool
,
true
},
{
JsonHelper
::
jsonVersionKey
,
QJsonValue
::
Double
,
true
},
{
_jsonInclusionKey
,
QJsonValue
::
Bool
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
json
,
keyInfoList
,
errorString
))
{
return
false
;
}
if
(
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
!=
_jsonCurrentVersion
)
{
errorString
=
tr
(
"GeoFence Circle only supports version %1"
).
arg
(
_jsonCurrentVersion
);
return
false
;
}
if
(
!
QGCMapCircle
::
loadFromJson
(
json
,
errorString
))
{
return
false
;
}
setInclusion
(
json
[
_jsonInclusionKey
].
toBool
());
return
true
;
...
...
src/MissionManager/QGCFenceCircle.h
View file @
ec5bffef
...
...
@@ -51,5 +51,7 @@ private:
bool
_inclusion
;
static
const
int
_jsonCurrentVersion
=
1
;
static
const
char
*
_jsonInclusionKey
;
};
src/MissionManager/QGCFencePolygon.cc
View file @
ec5bffef
...
...
@@ -47,26 +47,32 @@ void QGCFencePolygon::_setDirty(void)
void
QGCFencePolygon
::
saveToJson
(
QJsonObject
&
json
)
{
QGCMapPolygon
::
saveToJson
(
json
);
json
[
JsonHelper
::
jsonVersionKey
]
=
_jsonCurrentVersion
;
json
[
_jsonInclusionKey
]
=
_inclusion
;
QGCMapPolygon
::
saveToJson
(
json
);
}
bool
QGCFencePolygon
::
loadFromJson
(
const
QJsonObject
&
json
,
bool
required
,
QString
&
errorString
)
{
if
(
!
QGCMapPolygon
::
loadFromJson
(
json
,
required
,
errorString
))
{
return
false
;
}
errorString
.
clear
();
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
_jsonInclusionKey
,
QJsonValue
::
Bool
,
true
},
{
JsonHelper
::
jsonVersionKey
,
QJsonValue
::
Double
,
true
},
{
_jsonInclusionKey
,
QJsonValue
::
Bool
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
json
,
keyInfoList
,
errorString
))
{
return
false
;
}
if
(
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
!=
_jsonCurrentVersion
)
{
errorString
=
tr
(
"GeoFence Polygon only supports version %1"
).
arg
(
_jsonCurrentVersion
);
return
false
;
}
if
(
!
QGCMapPolygon
::
loadFromJson
(
json
,
required
,
errorString
))
{
return
false
;
}
setInclusion
(
json
[
_jsonInclusionKey
].
toBool
());
return
true
;
...
...
src/MissionManager/QGCFencePolygon.h
View file @
ec5bffef
...
...
@@ -51,5 +51,7 @@ private:
bool
_inclusion
;
static
const
int
_jsonCurrentVersion
=
1
;
static
const
char
*
_jsonInclusionKey
;
};
src/MissionManager/QGCMapCircle.cc
View file @
ec5bffef
...
...
@@ -111,11 +111,11 @@ bool QGCMapCircle::loadFromJson(const QJsonObject& json, QString& errorString)
}
QGeoCoordinate
center
;
if
(
!
JsonHelper
::
loadGeoCoordinate
(
json
[
_jsonCenterKey
],
false
/* altitudeRequired */
,
center
,
errorString
))
{
if
(
!
JsonHelper
::
loadGeoCoordinate
(
circleObject
[
_jsonCenterKey
],
false
/* altitudeRequired */
,
center
,
errorString
))
{
return
false
;
}
setCenter
(
center
);
_radius
.
setRawValue
(
json
[
_jsonRadiusKey
].
toDouble
());
_radius
.
setRawValue
(
circleObject
[
_jsonRadiusKey
].
toDouble
());
return
true
;
}
...
...
src/MissionManager/RallyPointController.cc
View file @
ec5bffef
...
...
@@ -82,13 +82,28 @@ void RallyPointController::managerVehicleChanged(Vehicle* managerVehicle)
bool
RallyPointController
::
load
(
const
QJsonObject
&
json
,
QString
&
errorString
)
{
removeAll
();
errorString
.
clear
();
if
(
json
.
contains
(
JsonHelper
::
jsonVersionKey
)
&&
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
==
1
)
{
// We just ignore old version 1 data
return
true
;
}
QList
<
JsonHelper
::
KeyValidateInfo
>
keyInfoList
=
{
{
JsonHelper
::
jsonVersionKey
,
QJsonValue
::
Double
,
true
},
{
_jsonPointsKey
,
QJsonValue
::
Array
,
true
},
};
if
(
!
JsonHelper
::
validateKeys
(
json
,
keyInfoList
,
errorString
))
{
return
false
;
}
QString
errorStr
;
QString
errorMessage
=
tr
(
"Rally: %1"
);
// Check for required keys
QStringList
requiredKeys
=
{
_jsonPointsKey
};
if
(
!
JsonHelper
::
validateRequiredKeys
(
json
,
requiredKeys
,
errorStr
))
{
errorString
=
errorMessage
.
arg
(
errorStr
);
if
(
json
[
JsonHelper
::
jsonVersionKey
].
toInt
()
!=
_jsonCurrentVersion
)
{
errorString
=
tr
(
"Rally Points supports version %1"
).
arg
(
_jsonCurrentVersion
);
return
false
;
}
...
...
@@ -97,7 +112,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
errorString
=
errorMessage
.
arg
(
errorStr
);
return
false
;
}
_points
.
clearAndDeleteContents
();
QObjectList
pointList
;
for
(
int
i
=
0
;
i
<
rgPoints
.
count
();
i
++
)
{
pointList
.
append
(
new
RallyPoint
(
rgPoints
[
i
],
this
));
...
...
@@ -112,7 +127,7 @@ bool RallyPointController::load(const QJsonObject& json, QString& errorString)
void
RallyPointController
::
save
(
QJsonObject
&
json
)
{
json
[
JsonHelper
::
jsonVersionKey
]
=
1
;
json
[
JsonHelper
::
jsonVersionKey
]
=
_jsonCurrentVersion
;
QJsonArray
rgPoints
;
QJsonValue
jsonPoint
;
...
...
src/MissionManager/RallyPointController.h
View file @
ec5bffef
...
...
@@ -74,6 +74,8 @@ private:
QObject
*
_currentRallyPoint
;
bool
_itemsRequested
;
static
const
int
_jsonCurrentVersion
=
2
;
static
const
char
*
_jsonFileTypeValue
;
static
const
char
*
_jsonPointsKey
;
};
...
...
src/PlanView/GeoFenceMapVisuals.qml
View file @
ec5bffef
...
...
@@ -28,8 +28,8 @@ Item {
property
bool
planView
:
false
///< true: visuals showing in plan view
property
var
homePosition
property
var
_breachReturnPointComponent
property
var
_mouseAreaComponent
//
property var _breachReturnPointComponent
//
property var _mouseAreaComponent
property
var
_paramCircleFenceComponent
property
var
_polygons
:
myGeoFenceController
.
polygons
property
var
_circles
:
myGeoFenceController
.
circles
...
...
@@ -75,17 +75,17 @@ Item {
}
Component.onCompleted
:
{
_breachReturnPointComponent
=
breachReturnPointComponent
.
createObject
(
map
)
map
.
addMapItem
(
_breachReturnPointComponent
)
//_breachReturnPointComponent = breachReturnPointComponent.createObject(map)
//map.addMapItem(_breachReturnPointComponent)
//_mouseAreaComponent = mouseAreaComponent.createObject(map)
_paramCircleFenceComponent
=
paramCircleFenceComponent
.
createObject
(
map
)
map
.
addMapItem
(
_paramCircleFenceComponent
)
_mouseAreaComponent
=
mouseAreaComponent
.
createObject
(
map
)
}
Component.onDestruction
:
{
_breachReturnPointComponent
.
destroy
()
//_breachReturnPointComponent.destroy()
//_mouseAreaComponent.destroy()
_paramCircleFenceComponent
.
destroy
()
_mouseAreaComponent
.
destroy
()
}
// Mouse area to capture breach return point coordinate
...
...
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