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
82aa7678
Commit
82aa7678
authored
Apr 20, 2017
by
DonLakeFlyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a master controller for all Plan elements
Update the user model to a single controller instead of multiple
parent
da022f97
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
691 additions
and
723 deletions
+691
-723
qgroundcontrol.pro
qgroundcontrol.pro
+2
-0
FlightDisplayView.qml
src/FlightDisplay/FlightDisplayView.qml
+25
-29
FlightDisplayViewMap.qml
src/FlightDisplay/FlightDisplayViewMap.qml
+13
-13
MapFitFunctions.qml
src/FlightMap/Widgets/MapFitFunctions.qml
+17
-15
JsonHelper.cc
src/JsonHelper.cc
+10
-1
JsonHelper.h
src/JsonHelper.h
+8
-2
GeoFenceController.cc
src/MissionManager/GeoFenceController.cc
+20
-80
GeoFenceController.h
src/MissionManager/GeoFenceController.h
+4
-8
MissionController.cc
src/MissionManager/MissionController.cc
+72
-140
MissionController.h
src/MissionManager/MissionController.h
+7
-14
PlanElementController.cc
src/MissionManager/PlanElementController.cc
+0
-23
PlanElementController.h
src/MissionManager/PlanElementController.h
+22
-32
PlanMasterController.cc
src/MissionManager/PlanMasterController.cc
+265
-0
PlanMasterController.h
src/MissionManager/PlanMasterController.h
+96
-0
RallyPointController.cc
src/MissionManager/RallyPointController.cc
+23
-89
RallyPointController.h
src/MissionManager/RallyPointController.h
+4
-9
MissionItemEditor.qml
src/PlanView/MissionItemEditor.qml
+4
-3
PlanToolBar.qml
src/PlanView/PlanToolBar.qml
+17
-18
PlanView.qml
src/PlanView/PlanView.qml
+73
-240
QGCApplication.cc
src/QGCApplication.cc
+2
-3
AppSettings.cc
src/Settings/AppSettings.cc
+1
-0
AppSettings.h
src/Settings/AppSettings.h
+2
-0
Vehicle.cc
src/Vehicle/Vehicle.cc
+4
-4
No files found.
qgroundcontrol.pro
View file @
82aa7678
...
...
@@ -472,6 +472,7 @@ HEADERS += \
src/MissionManager/MissionManager.h \
src/MissionManager/MissionSettingsItem.h \
src/MissionManager/PlanElementController.h \
src/MissionManager/PlanMasterController.h \
src/MissionManager/QGCMapPolygon.h \
src/MissionManager/RallyPoint.h \
src/MissionManager/RallyPointController.h \
...
...
@@ -654,6 +655,7 @@ SOURCES += \
src/MissionManager/MissionManager.cc \
src/MissionManager/MissionSettingsItem.cc \
src/MissionManager/PlanElementController.cc \
src/MissionManager/PlanMasterController.cc \
src/MissionManager/QGCMapPolygon.cc \
src/MissionManager/RallyPoint.cc \
src/MissionManager/RallyPointController.cc \
...
...
src/FlightDisplay/FlightDisplayView.qml
View file @
82aa7678
...
...
@@ -38,14 +38,18 @@ QGCView {
property
bool
activeVehicleJoystickEnabled
:
_activeVehicle
?
_activeVehicle
.
joystickEnabled
:
false
property
var
_activeVehicle
:
QGroundControl
.
multiVehicleManager
.
activeVehicle
property
bool
_mainIsMap
:
QGroundControl
.
videoManager
.
hasVideo
?
QGroundControl
.
loadBoolGlobalSetting
(
_mainIsMapKey
,
true
)
:
true
property
bool
_isPipVisible
:
QGroundControl
.
videoManager
.
hasVideo
?
QGroundControl
.
loadBoolGlobalSetting
(
_PIPVisibleKey
,
true
)
:
false
property
real
_savedZoomLevel
:
0
property
real
_margins
:
ScreenTools
.
defaultFontPixelWidth
/
2
property
real
_pipSize
:
mainWindow
.
width
*
0.2
property
alias
_guidedController
:
guidedActionsController
property
alias
_altitudeSlider
:
altitudeSlider
property
var
_planMasterController
:
masterController
property
var
_missionController
:
_planMasterController
.
missionController
property
var
_geoFenceController
:
_planMasterController
.
geoFenceController
property
var
_rallyPointController
:
_planMasterController
.
rallyPointController
property
var
_activeVehicle
:
QGroundControl
.
multiVehicleManager
.
activeVehicle
property
bool
_mainIsMap
:
QGroundControl
.
videoManager
.
hasVideo
?
QGroundControl
.
loadBoolGlobalSetting
(
_mainIsMapKey
,
true
)
:
true
property
bool
_isPipVisible
:
QGroundControl
.
videoManager
.
hasVideo
?
QGroundControl
.
loadBoolGlobalSetting
(
_PIPVisibleKey
,
true
)
:
false
property
real
_savedZoomLevel
:
0
property
real
_margins
:
ScreenTools
.
defaultFontPixelWidth
/
2
property
real
_pipSize
:
mainWindow
.
width
*
0.2
property
alias
_guidedController
:
guidedActionsController
property
alias
_altitudeSlider
:
altitudeSlider
readonly
property
bool
isBackgroundDark
:
_mainIsMap
?
(
_flightMap
?
_flightMap
.
isSatelliteMap
:
true
)
:
true
...
...
@@ -92,20 +96,14 @@ QGCView {
}
}
Mission
Controller
{
id
:
flyMission
Controller
PlanElemementMaster
Controller
{
id
:
master
Controller
Component.onCompleted
:
start
(
false
/* editMode */
)
onResumeMissionReady
:
guidedActionsController
.
confirmAction
(
guidedActionsController
.
actionResumeMissionReady
)
}
GeoFenceController
{
id
:
flyGeoFenceController
Component.onCompleted
:
start
(
false
/* editMode */
)
}
RallyPointController
{
id
:
flyRallyPoint
Controller
Component.onCompleted
:
start
(
false
/* editMode */
)
Connections
{
target
:
_mission
Controller
onResumeMissionReady
:
guidedActionsController
.
confirmAction
(
guidedActionsController
.
actionResumeMissionReady
)
}
MessageDialog
{
...
...
@@ -116,7 +114,7 @@ QGCView {
}
Connections
{
target
:
QGroundControl
.
multiVehicleManager
target
:
QGroundControl
.
multiVehicleManager
onActiveVehicleChanged
:
px4JoystickCheck
()
}
...
...
@@ -149,7 +147,7 @@ QGCView {
vehicleWasArmed
=
true
}
}
else
{
if
(
promptForMissionRemove
&&
(
flyMissionController
.
containsItems
||
flyGeoFenceController
.
containsItems
||
flyR
allyPointController
.
containsItems
))
{
if
(
promptForMissionRemove
&&
(
_missionController
.
containsItems
||
_geoFenceController
.
containsItems
||
_r
allyPointController
.
containsItems
))
{
root
.
showDialog
(
removeMissionDialogComponent
,
qsTr
(
"
Flight complete
"
),
showDialogDefaultWidth
,
StandardButton
.
No
|
StandardButton
.
Yes
)
}
promptForMissionRemove
=
false
...
...
@@ -169,9 +167,9 @@ QGCView {
message
:
qsTr
(
"
Do you want to remove the mission from the vehicle?
"
)
function
accept
()
{
flyM
issionController
.
removeAllFromVehicle
()
flyG
eoFenceController
.
removeAllFromVehicle
()
flyR
allyPointController
.
removeAllFromVehicle
()
_m
issionController
.
removeAllFromVehicle
()
_g
eoFenceController
.
removeAllFromVehicle
()
_r
allyPointController
.
removeAllFromVehicle
()
hideDialog
()
}
...
...
@@ -214,9 +212,7 @@ QGCView {
FlightDisplayViewMap
{
id
:
_flightMap
anchors.fill
:
parent
missionController
:
flyMissionController
geoFenceController
:
flyGeoFenceController
rallyPointController
:
flyRallyPointController
planMasterController
:
masterController
guidedActionsController
:
_guidedController
flightWidgets
:
flightDisplayViewWidgets
rightPanelWidth
:
ScreenTools
.
defaultFontPixelHeight
*
9
...
...
@@ -320,7 +316,7 @@ QGCView {
anchors.bottom
:
parent
.
bottom
qgcView
:
root
useLightColors
:
isBackgroundDark
missionController
:
_
flightMap
.
missionController
missionController
:
_missionController
visible
:
singleVehicleView
.
checked
}
...
...
@@ -511,7 +507,7 @@ QGCView {
GuidedActionsController
{
id
:
guidedActionsController
missionController
:
flyM
issionController
missionController
:
_m
issionController
confirmDialog
:
guidedActionConfirm
z
:
_flightVideoPipControl
.
z
+
1
...
...
src/FlightDisplay/FlightDisplayViewMap.qml
View file @
82aa7678
...
...
@@ -34,9 +34,7 @@ FlightMap {
property
alias
scaleState
:
mapScale
.
state
// The following properties must be set by the consumer
property
var
missionController
property
var
geoFenceController
property
var
rallyPointController
property
var
planMasterController
property
var
guidedActionsController
property
var
flightWidgets
property
var
rightPanelWidth
...
...
@@ -44,6 +42,10 @@ FlightMap {
property
rect
centerViewport
:
Qt
.
rect
(
0
,
0
,
width
,
height
)
property
var
_planMasterController
:
planMasterController
property
var
_missionController
:
_planMasterController
.
missionController
property
var
_geoFenceController
:
_planMasterController
.
geoFenceController
property
var
_rallyPointController
:
_planMasterController
.
rallyPointController
property
var
_activeVehicle
:
QGroundControl
.
multiVehicleManager
.
activeVehicle
property
var
_activeVehicleCoordinate
:
_activeVehicle
?
_activeVehicle
.
coordinate
:
QtPositioning
.
coordinate
()
property
var
_gotoHereCoordinate
:
QtPositioning
.
coordinate
()
...
...
@@ -132,10 +134,10 @@ FlightMap {
QGCMapPalette
{
id
:
mapPal
;
lightColors
:
isSatelliteMap
}
Connections
{
target
:
missionController
target
:
_
missionController
onNewItemsFromVehicle
:
{
var
visualItems
=
missionController
.
visualItems
var
visualItems
=
_
missionController
.
visualItems
if
(
visualItems
&&
visualItems
.
count
!=
1
)
{
mapFitFunctions
.
fitMapViewportToMissionItems
()
firstVehiclePositionReceived
=
true
...
...
@@ -151,9 +153,7 @@ FlightMap {
id
:
mapFitFunctions
map
:
_flightMap
usePlannedHomePosition
:
false
mapMissionController
:
missionController
mapGeoFenceController
:
geoFenceController
mapRallyPointController
:
rallyPointController
planMasterController
:
_planMasterController
property
real
leftToolWidth
:
toolStrip
.
x
+
toolStrip
.
width
}
...
...
@@ -188,7 +188,7 @@ FlightMap {
// Add the mission item visuals to the map
Repeater
{
model
:
_mainIsMap
?
missionController
.
visualItems
:
0
model
:
_mainIsMap
?
_
missionController
.
visualItems
:
0
delegate
:
MissionItemMapVisual
{
map
:
flightMap
...
...
@@ -198,12 +198,12 @@ FlightMap {
// Add lines between waypoints
MissionLineView
{
model
:
_mainIsMap
?
missionController
.
waypointLines
:
0
model
:
_mainIsMap
?
_
missionController
.
waypointLines
:
0
}
GeoFenceMapVisuals
{
map
:
flightMap
myGeoFenceController
:
geoFenceController
myGeoFenceController
:
_
geoFenceController
interactive
:
false
planView
:
false
homePosition
:
_activeVehicle
&&
_activeVehicle
.
homePosition
.
isValid
?
_activeVehicle
.
homePosition
:
undefined
...
...
@@ -211,7 +211,7 @@ FlightMap {
// Rally points on map
MapItemView
{
model
:
rallyPointController
.
points
model
:
_
rallyPointController
.
points
delegate
:
MapQuickItem
{
id
:
itemIndicator
...
...
@@ -243,7 +243,7 @@ FlightMap {
// Camera points
MapItemView
{
model
:
missionController
.
cameraPoints
model
:
_
missionController
.
cameraPoints
delegate
:
CameraTriggerIndicator
{
coordinate
:
object
.
coordinate
...
...
src/FlightMap/Widgets/MapFitFunctions.qml
View file @
82aa7678
...
...
@@ -16,9 +16,11 @@ import QGroundControl 1.0
Item
{
property
var
map
property
bool
usePlannedHomePosition
///< true: planned home position used for calculations, false: vehicle home position use for calculations
property
var
mapGeoFenceController
property
var
mapMissionController
property
var
mapRallyPointController
property
var
planMasterController
property
var
_missionController
:
planMasterController
.
missionController
property
var
_geoFenceController
:
planMasterController
.
geoFenceController
property
var
_rallyPointController
:
planMasterController
.
rallyPointController
property
var
_activeVehicle
:
QGroundControl
.
multiVehicleManager
.
activeVehicle
...
...
@@ -26,7 +28,7 @@ Item {
var
homePosition
=
QtPositioning
.
coordinate
()
var
activeVehicle
=
QGroundControl
.
multiVehicleManager
.
activeVehicle
if
(
usePlannedHomePosition
)
{
homePosition
=
mapM
issionController
.
visualItems
.
get
(
0
).
coordinate
homePosition
=
_m
issionController
.
visualItems
.
get
(
0
).
coordinate
}
else
if
(
activeVehicle
)
{
homePosition
=
activeVehicle
.
homePosition
}
...
...
@@ -92,8 +94,8 @@ Item {
if
(
homePosition
.
isValid
)
{
coordList
.
push
(
homePosition
)
}
for
(
var
i
=
1
;
i
<
mapM
issionController
.
visualItems
.
count
;
i
++
)
{
var
missionItem
=
mapM
issionController
.
visualItems
.
get
(
i
)
for
(
var
i
=
1
;
i
<
_m
issionController
.
visualItems
.
count
;
i
++
)
{
var
missionItem
=
_m
issionController
.
visualItems
.
get
(
i
)
if
(
missionItem
.
specifiesCoordinate
&&
!
missionItem
.
isStandaloneCoordinate
)
{
coordList
.
push
(
missionItem
.
coordinate
)
}
...
...
@@ -101,7 +103,7 @@ Item {
}
function
fitMapViewportToMissionItems
()
{
if
(
!
mapM
issionController
.
visualItems
)
{
if
(
!
_m
issionController
.
visualItems
)
{
// Being called prior to controller.start
return
}
...
...
@@ -112,16 +114,16 @@ Item {
function
addFenceItemCoordsForFit
(
coordList
)
{
var
homePosition
=
fitHomePosition
()
if
(
homePosition
.
isValid
&&
mapG
eoFenceController
.
circleEnabled
)
{
if
(
homePosition
.
isValid
&&
_g
eoFenceController
.
circleEnabled
)
{
var
azimuthList
=
[
0
,
180
,
90
,
270
]
for
(
var
i
=
0
;
i
<
azimuthList
.
length
;
i
++
)
{
var
edgeCoordinate
=
homePosition
.
atDistanceAndAzimuth
(
mapG
eoFenceController
.
circleRadius
,
azimuthList
[
i
])
var
edgeCoordinate
=
homePosition
.
atDistanceAndAzimuth
(
_g
eoFenceController
.
circleRadius
,
azimuthList
[
i
])
coordList
.
push
(
edgeCoordinate
)
}
}
if
(
mapGeoFenceController
.
polygonEnabled
&&
mapG
eoFenceController
.
mapPolygon
.
path
.
count
>
2
)
{
for
(
var
i
=
0
;
i
<
mapG
eoFenceController
.
mapPolygon
.
path
.
count
;
i
++
)
{
coordList
.
push
(
mapG
eoFenceController
.
mapPolygon
.
path
[
i
])
if
(
_geoFenceController
.
polygonEnabled
&&
_g
eoFenceController
.
mapPolygon
.
path
.
count
>
2
)
{
for
(
var
i
=
0
;
i
<
_g
eoFenceController
.
mapPolygon
.
path
.
count
;
i
++
)
{
coordList
.
push
(
_g
eoFenceController
.
mapPolygon
.
path
[
i
])
}
}
}
...
...
@@ -133,8 +135,8 @@ Item {
}
function
addRallyItemCoordsForFit
(
coordList
)
{
for
(
var
i
=
0
;
i
<
mapR
allyPointController
.
points
.
count
;
i
++
)
{
coordList
.
push
(
mapR
allyPointController
.
points
.
get
(
i
).
coordinate
)
for
(
var
i
=
0
;
i
<
_r
allyPointController
.
points
.
count
;
i
++
)
{
coordList
.
push
(
_r
allyPointController
.
points
.
get
(
i
).
coordinate
)
}
}
...
...
@@ -145,7 +147,7 @@ Item {
}
function
fitMapViewportToAllItems
()
{
if
(
!
mapM
issionController
.
visualItems
)
{
if
(
!
_m
issionController
.
visualItems
)
{
// Being called prior to controller.start
return
}
...
...
src/JsonHelper.cc
View file @
82aa7678
...
...
@@ -125,7 +125,7 @@ bool JsonHelper::parseEnum(const QJsonObject& jsonObject, QStringList& enumStrin
return
true
;
}
bool
JsonHelper
::
isJsonFile
(
const
QByteArray
&
bytes
,
QJsonDocument
&
jsonDoc
)
bool
JsonHelper
::
isJsonFile
(
const
QByteArray
&
bytes
,
QJsonDocument
&
jsonDoc
,
QString
&
errorString
)
{
QJsonParseError
error
;
...
...
@@ -192,6 +192,15 @@ bool JsonHelper::validateQGCJsonFile(const QJsonObject& jsonObject,
return
true
;
}
void
JsonHelper
::
saveQGCJsonFileHeader
(
QJsonObject
&
jsonObject
,
const
QString
&
fileType
,
int
version
)
{
jsonObject
[
jsonGroundStationKey
]
=
jsonGroundStationValue
;
jsonObject
[
jsonFileTypeKey
]
=
fileType
;
jsonObject
[
jsonVersionKey
]
=
version
;
}
bool
JsonHelper
::
loadGeoCoordinateArray
(
const
QJsonValue
&
jsonValue
,
bool
altitudeRequired
,
QVariantList
&
rgVarPoints
,
...
...
src/JsonHelper.h
View file @
82aa7678
...
...
@@ -20,9 +20,15 @@ class JsonHelper
{
public:
/// Determines is the specified data is a json file
/// @param jsonDoc Returned json document if json file
/// @return true: file is json, false: file is not json
static
bool
isJsonFile
(
const
QByteArray
&
bytes
,
QJsonDocument
&
jsonDoc
);
static
bool
isJsonFile
(
const
QByteArray
&
bytes
,
///< json bytes
QJsonDocument
&
jsonDoc
,
///< returned json document
QString
&
errorString
);
///< error on parse failure
/// Saves the standard file header the json object
static
void
saveQGCJsonFileHeader
(
QJsonObject
&
jsonObject
,
///< root json object
const
QString
&
fileType
,
///< file type for file
int
version
);
///< version number for file
/// Validates the standard parts of a QGC json file:
/// jsonFileTypeKey - Required and checked to be equal to expectedFileType
...
...
src/MissionManager/GeoFenceController.cc
View file @
82aa7678
...
...
@@ -89,13 +89,15 @@ void GeoFenceController::_signalAll(void)
emit
dirtyChanged
(
dirty
());
}
void
GeoFenceController
::
_
activeVehicleBeingRemoved
(
void
)
void
GeoFenceController
::
activeVehicleBeingRemoved
(
void
)
{
_activeVehicle
->
geoFenceManager
()
->
disconnect
(
this
);
_activeVehicle
=
NULL
;
}
void
GeoFenceController
::
_activeVehicleSet
(
void
)
void
GeoFenceController
::
activeVehicleSet
(
Vehicle
*
vehicle
)
{
_activeVehicle
=
vehicle
;
GeoFenceManager
*
geoFenceManager
=
_activeVehicle
->
geoFenceManager
();
connect
(
geoFenceManager
,
&
GeoFenceManager
::
breachReturnSupportedChanged
,
this
,
&
GeoFenceController
::
breachReturnSupportedChanged
);
connect
(
geoFenceManager
,
&
GeoFenceManager
::
circleEnabledChanged
,
this
,
&
GeoFenceController
::
circleEnabledChanged
);
...
...
@@ -112,97 +114,40 @@ void GeoFenceController::_activeVehicleSet(void)
_signalAll
();
}
bool
GeoFenceController
::
_loadJsonFile
(
QJsonDocument
&
jsonDoc
,
QString
&
errorString
)
bool
GeoFenceController
::
load
(
const
QJsonObject
&
json
,
QString
&
errorString
)
{
QJsonObject
json
=
jsonDoc
.
object
();
QString
errorStr
;
QString
errorMessage
=
tr
(
"GeoFence: %1"
);
int
fileVersion
;
if
(
!
JsonHelper
::
validateQGCJsonFile
(
json
,
_jsonFileTypeValue
,
// expected file type
1
,
// minimum supported version
1
,
// maximum supported version
fileVersion
,
errorString
))
{
if
(
json
.
contains
(
_jsonBreachReturnKey
)
&&
!
JsonHelper
::
loadGeoCoordinate
(
json
[
_jsonBreachReturnKey
],
false
/* altitudeRequired */
,
_breachReturnPoint
,
errorStr
))
{
errorString
=
errorMessage
.
arg
(
errorStr
);
return
false
;
}
if
(
!
_activeVehicle
->
parameterManager
()
->
loadFromJson
(
json
,
false
/* required */
,
errorString
))
{
return
false
;
}
if
(
json
.
contains
(
_jsonBreachReturnKey
)
&&
!
JsonHelper
::
loadGeoCoordinate
(
json
[
_jsonBreachReturnKey
],
false
/* altitudeRequired */
,
_breachReturnPoint
,
errorString
))
{
return
false
;
}
if
(
!
_mapPolygon
.
loadFromJson
(
json
,
true
,
errorString
))
{
if
(
!
_mapPolygon
.
loadFromJson
(
json
,
true
,
errorStr
))
{
errorString
=
errorMessage
.
arg
(
errorStr
);
return
false
;
}
_mapPolygon
.
setDirty
(
false
);
return
true
;
}
void
GeoFenceController
::
loadFromFile
(
const
QString
&
filename
)
{
QString
errorString
;
if
(
filename
.
isEmpty
())
{
return
;
}
QFile
file
(
filename
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
errorString
=
file
.
errorString
()
+
QStringLiteral
(
" "
)
+
filename
;
}
else
{
QJsonDocument
jsonDoc
;
QByteArray
bytes
=
file
.
readAll
();
_loadJsonFile
(
jsonDoc
,
errorString
);
}
if
(
!
errorString
.
isEmpty
())
{
qgcApp
()
->
showMessage
(
errorString
);
}
setDirty
(
false
);
_signalAll
();
setDirty
(
true
);
return
true
;
}
void
GeoFenceController
::
saveToFile
(
const
QString
&
filename
)
void
GeoFenceController
::
save
(
QJsonObject
&
json
)
{
if
(
filename
.
isEmpty
())
{
return
;
}
QString
fenceFilename
=
filename
;
if
(
!
QFileInfo
(
filename
).
fileName
().
contains
(
"."
))
{
fenceFilename
+=
QString
(
".%1"
).
arg
(
AppSettings
::
fenceFileExtension
);
}
QFile
file
(
fenceFilename
);
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Text
))
{
qgcApp
()
->
showMessage
(
file
.
errorString
());
}
else
{
QJsonObject
fenceFileObject
;
// top level json object
fenceFileObject
[
JsonHelper
::
jsonFileTypeKey
]
=
_jsonFileTypeValue
;
fenceFileObject
[
JsonHelper
::
jsonVersionKey
]
=
1
;
fenceFileObject
[
JsonHelper
::
jsonGroundStationKey
]
=
JsonHelper
::
jsonGroundStationValue
;
json
[
JsonHelper
::
jsonVersionKey
]
=
1
;
if
(
_breachReturnPoint
.
isValid
())
{
QJsonValue
jsonBreachReturn
;
JsonHelper
::
saveGeoCoordinate
(
_breachReturnPoint
,
false
/* writeAltitude */
,
jsonBreachReturn
);
fenceFileObject
[
_jsonBreachReturnKey
]
=
jsonBreachReturn
;
_mapPolygon
.
saveToJson
(
fenceFileObject
);
QJsonDocument
saveDoc
(
fenceFileObject
);
file
.
write
(
saveDoc
.
toJson
());
json
[
_jsonBreachReturnKey
]
=
jsonBreachReturn
;
}
setDirty
(
false
);
_mapPolygon
.
saveToJson
(
json
);
}
void
GeoFenceController
::
removeAll
(
void
)
...
...
@@ -323,11 +268,6 @@ void GeoFenceController::_loadComplete(const QGeoCoordinate& breachReturn, const
emit
loadComplete
();
}
QString
GeoFenceController
::
fileExtension
(
void
)
const
{
return
AppSettings
::
fenceFileExtension
;
}
bool
GeoFenceController
::
containsItems
(
void
)
const
{
return
_mapPolygon
.
count
()
>
2
;
...
...
src/MissionManager/GeoFenceController.h
View file @
82aa7678
...
...
@@ -46,18 +46,18 @@ public:
void
start
(
bool
editMode
)
final
;
void
startStaticActiveVehicle
(
Vehicle
*
vehicle
)
final
;
void
save
(
QJsonObject
&
json
)
final
;
bool
load
(
const
QJsonObject
&
json
,
QString
&
errorString
)
final
;
void
loadFromVehicle
(
void
)
final
;
void
sendToVehicle
(
void
)
final
;
void
loadFromFile
(
const
QString
&
filename
)
final
;
void
saveToFile
(
const
QString
&
filename
)
final
;
void
removeAll
(
void
)
final
;
void
removeAllFromVehicle
(
void
)
final
;
bool
syncInProgress
(
void
)
const
final
;
bool
dirty
(
void
)
const
final
;
void
setDirty
(
bool
dirty
)
final
;
bool
containsItems
(
void
)
const
final
;
QString
fileExtension
(
void
)
const
final
;
void
activeVehicleBeingRemoved
(
void
)
final
;
void
activeVehicleSet
(
Vehicle
*
vehicle
)
final
;
bool
circleEnabled
(
void
)
const
;
Fact
*
circleRadiusFact
(
void
)
const
;
...
...
@@ -95,10 +95,6 @@ private slots:
private:
void
_init
(
void
);
void
_signalAll
(
void
);
bool
_loadJsonFile
(
QJsonDocument
&
jsonDoc
,
QString
&
errorString
);
void
_activeVehicleBeingRemoved
(
void
)
final
;
void
_activeVehicleSet
(
void
)
final
;
bool
_dirty
;
QGCMapPolygon
_mapPolygon
;
...
...
src/MissionManager/MissionController.cc
View file @
82aa7678
...
...
@@ -335,40 +335,7 @@ void MissionController::removeAll(void)
_addMissionSettings
(
_activeVehicle
,
_visualItems
,
false
/* addToCenter */
);
_initAllVisualItems
();
_visualItems
->
setDirty
(
true
);
_resetMissionFlightStatus
();
}
}
bool
MissionController
::
_loadJsonMissionFile
(
Vehicle
*
vehicle
,
const
QByteArray
&
bytes
,
QmlObjectListModel
*
visualItems
,
QString
&
errorString
)
{
QJsonParseError
jsonParseError
;
QJsonDocument
jsonDoc
(
QJsonDocument
::
fromJson
(
bytes
,
&
jsonParseError
));
if
(
jsonParseError
.
error
!=
QJsonParseError
::
NoError
)
{
errorString
=
jsonParseError
.
errorString
();
return
false
;
}
QJsonObject
json
=
jsonDoc
.
object
();
// V1 file format has no file type key and version key is string. Convert to new format.
if
(
!
json
.
contains
(
JsonHelper
::
jsonFileTypeKey
))
{
json
[
JsonHelper
::
jsonFileTypeKey
]
=
_jsonFileTypeValue
;
}
int
fileVersion
;
if
(
!
JsonHelper
::
validateQGCJsonFile
(
json
,
_jsonFileTypeValue
,
// expected file type
1
,
// minimum supported version
2
,
// maximum supported version
fileVersion
,
errorString
))
{
return
false
;
}
if
(
fileVersion
==
1
)
{
return
_loadJsonMissionFileV1
(
vehicle
,
json
,
visualItems
,
errorString
);
}
else
{
return
_loadJsonMissionFileV2
(
vehicle
,
json
,
visualItems
,
errorString
);
_resetMissionFlightStatus
();
}
}
...
...
@@ -612,6 +579,32 @@ bool MissionController::_loadJsonMissionFileV2(Vehicle* vehicle, const QJsonObje
return
true
;
}
#if 0
bool MissionController::_loadItemsFromJson(const QJsonObject& json, QmlObjectListModel* visualItems, QString& errorString)
{
// V1 file format has no file type key and version key is string. Convert to new format.
if (!json.contains(JsonHelper::jsonFileTypeKey)) {
json[JsonHelper::jsonFileTypeKey] = _jsonFileTypeValue;
}
int fileVersion;
if (!JsonHelper::validateQGCJsonFile(json,
_jsonFileTypeValue, // expected file type
1, // minimum supported version
2, // maximum supported version
fileVersion,
errorString)) {
return false;
}
if (fileVersion == 1) {
return _loadJsonMissionFileV1(_activeVehicle, json, visualItems, errorString);
} else {
return _loadJsonMissionFileV2(_activeVehicle, json, visualItems, errorString);
}
}
#endif
bool
MissionController
::
_loadTextMissionFile
(
Vehicle
*
vehicle
,
QTextStream
&
stream
,
QmlObjectListModel
*
visualItems
,
QString
&
errorString
)
{
bool
addPlannedHomePosition
=
false
;
...
...
@@ -662,12 +655,15 @@ bool MissionController::_loadTextMissionFile(Vehicle* vehicle, QTextStream& stre
return
true
;
}
void
MissionController
::
loadFromFile
(
const
QString
&
filename
)
bool
MissionController
::
load
(
const
QJsonObject
&
json
,
QString
&
errorString
)
{
QmlObjectListModel
*
newVisualItems
=
NULL
;
QString
errorStr
;
QString
errorMessage
=
tr
(
"Mission: %1"
);
QmlObjectListModel
*
newVisualItems
=
new
QmlObjectListModel
(
this
);
if
(
!
loadItemsFromFile
(
_activeVehicle
,
filename
,
&
newVisualItems
))
{
return
;
if
(
!
_loadJsonMissionFileV2
(
_activeVehicle
,
json
,
newVisualItems
,
errorStr
))
{
errorString
=
errorMessage
.
arg
(
errorStr
);
return
false
;
}
if
(
_visualItems
)
{
...
...
@@ -690,117 +686,54 @@ void MissionController::loadFromFile(const QString& filename)
// Needs a sync to vehicle
setDirty
(
true
);
}
}
bool
MissionController
::
loadItemsFromFile
(
Vehicle
*
vehicle
,
const
QString
&
filename
,
QmlObjectListModel
**
visualItems
)
{
*
visualItems
=
NULL
;
QString
errorString
;
if
(
filename
.
isEmpty
())
{
return
false
;
}
*
visualItems
=
new
QmlObjectListModel
();
QFile
file
(
filename
);
if
(
!
file
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
))
{
errorString
=
file
.
errorString
()
+
QStringLiteral
(
" "
)
+
filename
;
}
else
{
QByteArray
bytes
=
file
.
readAll
();
QTextStream
stream
(
&
bytes
);
QString
firstLine
=
stream
.
readLine
();
if
(
firstLine
.
contains
(
QRegExp
(
"QGC.*WPL"
)))
{
stream
.
seek
(
0
);
_loadTextMissionFile
(
vehicle
,
stream
,
*
visualItems
,
errorString
);
}
else
{
_loadJsonMissionFile
(
vehicle
,
bytes
,
*
visualItems
,
errorString
);
}
}
if
(
!
errorString
.
isEmpty
())
{
(
*
visualItems
)
->
deleteLater
();
qgcApp
()
->
showMessage
(
errorString
);
return
false
;
}
return
true
;
}
void
MissionController
::
save
ToFile
(
const
QString
&
filename
)
void
MissionController
::
save
(
QJsonObject
&
json
)
{
if
(
filename
.
isEmpty
())
{
return
;
}
QString
missionFilename
=
filename
;
if
(
!
QFileInfo
(
filename
).
fileName
().
contains
(
"."
))
{
missionFilename
+=
QString
(
".%1"
).
arg
(
AppSettings
::
missionFileExtension
);
}
json
[
JsonHelper
::
jsonVersionKey
]
=
_missionFileVersion
;
QFile
file
(
missionFilename
);
// Mission settings
if
(
!
file
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Text
))
{
qgcApp
()
->
showMessage
(
tr
(
"Mission save %1 : %2"
).
arg
(
filename
).
arg
(
file
.
errorString
()));
}
else
{
QJsonObject
missionFileObject
;
// top level json object
missionFileObject
[
JsonHelper
::
jsonVersionKey
]
=
_missionFileVersion
;
missionFileObject
[
JsonHelper
::
jsonGroundStationKey
]
=
JsonHelper
::
jsonGroundStationValue
;
MissionSettingsItem
*
settingsItem
=
_visualItems
->
value
<
MissionSettingsItem
*>
(
0
);
if
(
!
settingsItem
)
{
qWarning
()
<<
"First item is not MissionSettingsItem"
;
return
;
}
QJsonValue
coordinateValue
;
JsonHelper
::
saveGeoCoordinate
(
settingsItem
->
coordinate
(),
true
/* writeAltitude */
,
coordinateValue
);
json
[
_jsonPlannedHomePositionKey
]
=
coordinateValue
;
json
[
_jsonFirmwareTypeKey
]
=
_activeVehicle
->
firmwareType
();
json
[
_jsonVehicleTypeKey
]
=
_activeVehicle
->
vehicleType
();
json
[
_jsonCruiseSpeedKey
]
=
_activeVehicle
->
defaultCruiseSpeed
();
json
[
_jsonHoverSpeedKey
]
=
_activeVehicle
->
defaultHoverSpeed
();
// Mission setting
s
// Save the visual item
s
MissionSettingsItem
*
settingsItem
=
_visualItems
->
value
<
MissionSettingsItem
*>
(
0
);
if
(
!
settingsItem
)
{
qWarning
()
<<
"First item is not MissionSettingsItem"
;
return
;
}
QJsonValue
coordinateValue
;
JsonHelper
::
saveGeoCoordinate
(
settingsItem
->
coordinate
(),
true
/* writeAltitude */
,
coordinateValue
);
missionFileObject
[
_jsonPlannedHomePositionKey
]
=
coordinateValue
;
missionFileObject
[
_jsonFirmwareTypeKey
]
=
_activeVehicle
->
firmwareType
();
missionFileObject
[
_jsonVehicleTypeKey
]
=
_activeVehicle
->
vehicleType
();
missionFileObject
[
_jsonCruiseSpeedKey
]
=<