Commit 82aa7678 authored by DonLakeFlyer's avatar DonLakeFlyer

Use a master controller for all Plan elements

Update the user model to a single controller instead of multiple
parent da022f97
......@@ -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 \
......
......@@ -38,6 +38,10 @@ QGCView {
property bool activeVehicleJoystickEnabled: _activeVehicle ? _activeVehicle.joystickEnabled : false
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
......@@ -92,20 +96,14 @@ QGCView {
}
}
MissionController {
id: flyMissionController
Component.onCompleted: start(false /* editMode */)
onResumeMissionReady: guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionReady)
}
GeoFenceController {
id: flyGeoFenceController
PlanElemementMasterController {
id: masterController
Component.onCompleted: start(false /* editMode */)
}
RallyPointController {
id: flyRallyPointController
Component.onCompleted: start(false /* editMode */)
Connections {
target: _missionController
onResumeMissionReady: guidedActionsController.confirmAction(guidedActionsController.actionResumeMissionReady)
}
MessageDialog {
......@@ -149,7 +147,7 @@ QGCView {
vehicleWasArmed = true
}
} else {
if (promptForMissionRemove && (flyMissionController.containsItems || flyGeoFenceController.containsItems || flyRallyPointController.containsItems)) {
if (promptForMissionRemove && (_missionController.containsItems || _geoFenceController.containsItems || _rallyPointController.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() {
flyMissionController.removeAllFromVehicle()
flyGeoFenceController.removeAllFromVehicle()
flyRallyPointController.removeAllFromVehicle()
_missionController.removeAllFromVehicle()
_geoFenceController.removeAllFromVehicle()
_rallyPointController.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: flyMissionController
missionController: _missionController
confirmDialog: guidedActionConfirm
z: _flightVideoPipControl.z + 1
......
......@@ -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
......
......@@ -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 = mapMissionController.visualItems.get(0).coordinate
homePosition = _missionController.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<mapMissionController.visualItems.count; i++) {
var missionItem = mapMissionController.visualItems.get(i)
for (var i=1; i<_missionController.visualItems.count; i++) {
var missionItem = _missionController.visualItems.get(i)
if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) {
coordList.push(missionItem.coordinate)
}
......@@ -101,7 +103,7 @@ Item {
}
function fitMapViewportToMissionItems() {
if (!mapMissionController.visualItems) {
if (!_missionController.visualItems) {
// Being called prior to controller.start
return
}
......@@ -112,16 +114,16 @@ Item {
function addFenceItemCoordsForFit(coordList) {
var homePosition = fitHomePosition()
if (homePosition.isValid && mapGeoFenceController.circleEnabled) {
if (homePosition.isValid && _geoFenceController.circleEnabled) {
var azimuthList = [ 0, 180, 90, 270 ]
for (var i=0; i<azimuthList.length; i++) {
var edgeCoordinate = homePosition.atDistanceAndAzimuth(mapGeoFenceController.circleRadius, azimuthList[i])
var edgeCoordinate = homePosition.atDistanceAndAzimuth(_geoFenceController.circleRadius, azimuthList[i])
coordList.push(edgeCoordinate)
}
}
if (mapGeoFenceController.polygonEnabled && mapGeoFenceController.mapPolygon.path.count > 2) {
for (var i=0; i<mapGeoFenceController.mapPolygon.path.count; i++) {
coordList.push(mapGeoFenceController.mapPolygon.path[i])
if (_geoFenceController.polygonEnabled && _geoFenceController.mapPolygon.path.count > 2) {
for (var i=0; i<_geoFenceController.mapPolygon.path.count; i++) {
coordList.push(_geoFenceController.mapPolygon.path[i])
}
}
}
......@@ -133,8 +135,8 @@ Item {
}
function addRallyItemCoordsForFit(coordList) {
for (var i=0; i<mapRallyPointController.points.count; i++) {
coordList.push(mapRallyPointController.points.get(i).coordinate)
for (var i=0; i<_rallyPointController.points.count; i++) {
coordList.push(_rallyPointController.points.get(i).coordinate)
}
}
......@@ -145,7 +147,7 @@ Item {
}
function fitMapViewportToAllItems() {
if (!mapMissionController.visualItems) {
if (!_missionController.visualItems) {
// Being called prior to controller.start
return
}
......
......@@ -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,
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -339,39 +339,6 @@ void MissionController::removeAll(void)
}
}
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);
}
}
bool MissionController::_loadJsonMissionFileV1(Vehicle* vehicle, const QJsonObject& json, QmlObjectListModel* visualItems, QString& errorString)
{
// Validate root object keys
......@@ -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,67 +686,13 @@ 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::saveToFile(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);
}
QFile file(missionFilename);
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;
json[JsonHelper::jsonVersionKey] = _missionFileVersion;
// Mission settings
......@@ -761,11 +703,11 @@ void MissionController::saveToFile(const QString& filename)
}
QJsonValue coordinateValue;
JsonHelper::saveGeoCoordinate(settingsItem->coordinate(), true /* writeAltitude */, coordinateValue);
missionFileObject[_jsonPlannedHomePositionKey] = coordinateValue;
missionFileObject[_jsonFirmwareTypeKey] = _activeVehicle->firmwareType();
missionFileObject[_jsonVehicleTypeKey] = _activeVehicle->vehicleType();
missionFileObject[_jsonCruiseSpeedKey] = _activeVehicle->defaultCruiseSpeed();
missionFileObject[_jsonHoverSpeedKey] = _activeVehicle->defaultHoverSpeed();
json[_jsonPlannedHomePositionKey] = coordinateValue;
json[_jsonFirmwareTypeKey] = _activeVehicle->firmwareType();
json[_jsonVehicleTypeKey] = _activeVehicle->vehicleType();
json[_jsonCruiseSpeedKey] = _activeVehicle->defaultCruiseSpeed();
json[_jsonHoverSpeedKey] = _activeVehicle->defaultHoverSpeed();
// Save the visual items
......@@ -791,16 +733,7 @@ void MissionController::saveToFile(const QString& filename)
}
}
missionFileObject[_jsonItemsKey] = rgJsonMissionItems;
QJsonDocument saveDoc(missionFileObject);
file.write(saveDoc.toJson());
}
// If we are connected to a real vehicle, don't clear dirty bit on saving to file since vehicle is still out of date
if (_activeVehicle->isOfflineEditingVehicle()) {
_visualItems->setDirty(false);
}
json[_jsonItemsKey] = rgJsonMissionItems;
}
void MissionController::_calcPrevWaypointValues(double homeAlt, VisualMissionItem* currentItem, VisualMissionItem* prevItem, double* azimuth, double* distance, double* altDifference)
......@@ -1320,7 +1253,7 @@ void MissionController::_itemCommandChanged(void)
_recalcWaypointLines();
}
void MissionController::_activeVehicleBeingRemoved(void)
void MissionController::activeVehicleBeingRemoved(void)
{
qCDebug(MissionControllerLog) << "MissionController::_activeVehicleBeingRemoved";
......@@ -1337,10 +1270,14 @@ void MissionController::_activeVehicleBeingRemoved(void)
// We always remove all items on vehicle change. This leaves a user model hole:
// If the user has unsaved changes in the Plan view they will lose them
removeAll();
_activeVehicle = NULL;
}
void MissionController::_activeVehicleSet(void)
void MissionController::activeVehicleSet(Vehicle* activeVehicle)
{
_activeVehicle = activeVehicle;
// We always remove all items on vehicle change. This leaves a user model hole:
// If the user has unsaved changes in the Plan view they will lose them
removeAll();
......@@ -1529,11 +1466,6 @@ void MissionController::setDirty(bool dirty)
}
}
QString MissionController::fileExtension(void) const
{
return AppSettings::missionFileExtension;
}
void MissionController::_scanForAdditionalSettings(QmlObjectListModel* visualItems, Vehicle* vehicle)
{
// First we look for a Fixed Wing Landing Pattern which is at the end
......
......@@ -98,13 +98,6 @@ public:
/// Updates the altitudes of the items in the current mission to the new default altitude
Q_INVOKABLE void applyDefaultMissionAltitude(void);
/// Loads the mission items from the specified file
/// @param[in] vehicle Vehicle we are loading items for
/// @param[in] filename File to load from
/// @param[out] visualItems Visual items loaded, returns NULL if error
/// @return success/fail
static bool loadItemsFromFile(Vehicle* vehicle, const QString& filename, QmlObjectListModel** visualItems);
/// Sends the mission items to the specified vehicle
static void sendItemsToVehicle(Vehicle* vehicle, QmlObjectListModel* visualMissionItems);
......@@ -113,18 +106,21 @@ public:
// Overrides from PlanElementController
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;
#if 0
void loadFromFile (const QString& filename) final;
void saveToFile (const QString& filename) final;
#endif
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;
// Property accessors
......@@ -205,10 +201,7 @@ private:
void _addHoverTime(double hoverTime, double hoverDistance, int waypointIndex);
void _addCruiseTime(double cruiseTime, double cruiseDistance, int wayPointIndex);
void _updateBatteryInfo(int waypointIndex);
// Overrides from PlanElementController
void _activeVehicleBeingRemoved(void) final;
void _activeVehicleSet(void) final;
bool _loadItemsFromJson(const QJsonObject& json, QmlObjectListModel* visualItems, QString& errorString);
private:
QmlObjectListModel* _visualItems;
......
......@@ -28,32 +28,9 @@ PlanElementController::~PlanElementController()
void PlanElementController::start(bool editMode)
{
_editMode = editMode;
connect(_multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged, this, &PlanElementController::_activeVehicleChanged);
_activeVehicleChanged(_multiVehicleMgr->activeVehicle());
}
void PlanElementController::startStaticActiveVehicle(Vehicle* vehicle)
{
_editMode = false;
_activeVehicleChanged(vehicle);
}
void PlanElementController::_activeVehicleChanged(Vehicle* activeVehicle)
{
if (_activeVehicle) {
_activeVehicleBeingRemoved();
_activeVehicle = NULL;
}
if (activeVehicle) {
_activeVehicle = activeVehicle;
} else {
_activeVehicle = _multiVehicleMgr->offlineEditingVehicle();
}
_activeVehicleSet();
// Whenever vehicle changes we need to update syncInProgress
emit syncInProgressChanged(syncInProgress());
emit vehicleChanged(_activeVehicle);
}
......@@ -28,32 +28,33 @@ public:
Q_PROPERTY(bool containsItems READ containsItems NOTIFY containsItemsChanged) ///< true: Elemement is non-empty
Q_PROPERTY(bool syncInProgress READ syncInProgress NOTIFY syncInProgressChanged) ///< true: information is currently being saved/sent, false: no active save/send in progress
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) ///< true: unsaved/sent changes are present, false: no changes since last save/send
Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) ///< Returns the file extention for plan element file type.
Q_PROPERTY(Vehicle* vehicle READ vehicle NOTIFY vehicleChanged)
virtual QString fileExtension(void) const = 0;
/// Should be called immediately upon Component.onCompleted.
/// @param editMode true: controller being used in Plan view, false: controller being used in Fly view
Q_INVOKABLE virtual void start(bool editMode);
virtual void start(bool editMode);
/// Starts the controller using a single static active vehicle. Will not track global active vehicle changes.
/// @param editMode true: controller being used in Plan view, false: controller being used in Fly view
Q_INVOKABLE virtual void startStaticActiveVehicle(Vehicle* vehicle);
virtual void startStaticActiveVehicle(Vehicle* vehicle);
Q_INVOKABLE virtual void loadFromVehicle(void) = 0;
Q_INVOKABLE virtual void sendToVehicle(void) = 0;
Q_INVOKABLE virtual void loadFromFile(const QString& filename) = 0;
Q_INVOKABLE virtual void saveToFile(const QString& filename) = 0;
Q_INVOKABLE virtual void removeAll(void) = 0; ///< Removes all from controller only, synce required to remove from vehicle
Q_INVOKABLE virtual void removeAllFromVehicle(void) = 0; ///< Removes all from vehicle and controller
virtual void save(QJsonObject& json) = 0;
virtual bool load(const QJsonObject& json, QString& errorString) = 0;
virtual void loadFromVehicle(void) = 0;
virtual void sendToVehicle(void) = 0;
virtual void removeAll(void) = 0; ///< Removes all from controller only, synce required to remove from vehicle
virtual void removeAllFromVehicle(void) = 0; ///< Removes all from vehicle and controller
virtual bool containsItems (void) const = 0;
virtual bool syncInProgress (void) const = 0;
virtual bool dirty (void) const = 0;
virtual void setDirty (bool dirty) = 0;
/// Called when the current active vehicle is about to be removed. Derived classes should override to implement custom behavior.
virtual void activeVehicleBeingRemoved(void) = 0;
/// Called when a new active vehicle has been set. Derived classes should override to implement custom behavior.
virtual void activeVehicleSet(Vehicle* activeVehicle) = 0;
Vehicle* vehicle(void) { return _activeVehicle; }
signals:
......@@ -66,17 +67,6 @@ protected:
MultiVehicleManager* _multiVehicleMgr;
Vehicle* _activeVehicle; ///< Currently active vehicle, can be disconnected offline editing vehicle
bool _editMode;
/// Called when the current active vehicle is about to be removed. Derived classes should override
/// to implement custom behavior.
virtual void _activeVehicleBeingRemoved(void) = 0;
/// Called when a new active vehicle has been set. Derived classes should override
/// to implement custom behavior.
virtual void _activeVehicleSet(void) = 0;
private slots:
void _activeVehicleChanged(Vehicle* activeVehicle);
};
#endif
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#include "PlanMasterController.h"
#include "QGCApplication.h"
#include "MultiVehicleManager.h"
#include "AppSettings.h"
#include "JsonHelper.h"
#include <QJsonDocument>
const int PlanMasterController::_planFileVersion = 1;
const char* PlanMasterController::_planFileType = "Plan";
const char* PlanMasterController::_jsonMissionObjectKey = "mission";
const char* PlanMasterController::_jsonGeoFenceObjectKey = "geoFence";
const char* PlanMasterController::_jsonRallyPointsObjectKey = "rallyPoints";
PlanMasterController::PlanMasterController(QObject* parent)
: QObject(parent)
, _multiVehicleMgr(qgcApp()->toolbox()->multiVehicleManager())
, _activeVehicle(_multiVehicleMgr->offlineEditingVehicle())
, _editMode(false)
{
connect(&_missionController, &MissionController::dirtyChanged, this, &PlanMasterController::dirtyChanged);
connect(&_geoFenceController, &GeoFenceController::dirtyChanged, this, &PlanMasterController::dirtyChanged);
connect(&_rallyPointController, &RallyPointController::dirtyChanged, this, &PlanMasterController::dirtyChanged);
connect(&_missionController, &MissionController::containsItemsChanged, this, &PlanMasterController::containsItemsChanged);
connect(&_geoFenceController, &GeoFenceController::containsItemsChanged, this, &PlanMasterController::containsItemsChanged);
connect(&_rallyPointController, &RallyPointController::containsItemsChanged, this, &PlanMasterController::containsItemsChanged);
connect(&_missionController, &MissionController::syncInProgressChanged, this, &PlanMasterController::syncInProgressChanged);
connect(&_geoFenceController, &GeoFenceController::syncInProgressChanged, this, &PlanMasterController::syncInProgressChanged);
connect(&_rallyPointController, &RallyPointController::syncInProgressChanged, this, &PlanMasterController::syncInProgressChanged);
}
PlanMasterController::~PlanMasterController()
{
}
void PlanMasterController::start(bool editMode)
{
_editMode = editMode;
_missionController.start(editMode);
_geoFenceController.start(editMode);
_rallyPointController.start(editMode);
connect(_multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged, this, &PlanMasterController::_activeVehicleChanged);
_activeVehicleChanged(_multiVehicleMgr->activeVehicle());
}
void PlanMasterController::startStaticActiveVehicle(Vehicle* vehicle)
{
_editMode = false;
_missionController.startStaticActiveVehicle(vehicle);
_geoFenceController.startStaticActiveVehicle(vehicle);
_rallyPointController.startStaticActiveVehicle(vehicle);
_activeVehicleChanged(vehicle);
}
void PlanMasterController::_activeVehicleChanged(Vehicle* activeVehicle)
{
if (_activeVehicle) {
_missionController.activeVehicleBeingRemoved();
_geoFenceController.activeVehicleBeingRemoved();
_rallyPointController.activeVehicleBeingRemoved();
_activeVehicle = NULL;
}
if (activeVehicle) {
_activeVehicle = activeVehicle;
} else {
_activeVehicle = _multiVehicleMgr->offlineEditingVehicle();
}
_missionController.activeVehicleSet(_activeVehicle);
_geoFenceController.activeVehicleSet(_activeVehicle);
_rallyPointController.activeVehicleSet(_activeVehicle);
// Whenever vehicle changes we need to update syncInProgress
emit syncInProgressChanged(syncInProgress());
emit vehicleChanged(_activeVehicle);
}
void PlanMasterController::loadFromVehicle(void)
{
// FIXME: Hack implementation
_missionController.loadFromVehicle();
_geoFenceController.loadFromVehicle();
_rallyPointController.loadFromVehicle();
}
void PlanMasterController::sendToVehicle(void)
{
// FIXME: Hack implementation
_missionController.sendToVehicle();
_geoFenceController.sendToVehicle();
_rallyPointController.sendToVehicle();
}
void PlanMasterController::loadFromFile(const QString& filename)
{
QString errorString;
QString errorMessage = tr("Error reading Plan file (%1). %2").arg(filename).arg("%1");
if (filename.isEmpty()) {
return;
}
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
errorString = file.errorString() + QStringLiteral(" ") + filename;
return;
}
QJsonDocument jsonDoc;
QByteArray bytes = file.readAll();
if (!JsonHelper::isJsonFile(bytes, jsonDoc, errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString));
return;
}
int version;
QJsonObject json = jsonDoc.object();
if (!JsonHelper::validateQGCJsonFile(json, _planFileType, _planFileVersion, _planFileVersion, version, errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString));
return;
}
QList<JsonHelper::KeyValidateInfo> rgKeyInfo = {
{ _jsonMissionObjectKey, QJsonValue::Object, true },
{ _jsonGeoFenceObjectKey, QJsonValue::Object, true },
{ _jsonRallyPointsObjectKey, QJsonValue::Object, true },
};
if (!JsonHelper::validateKeys(json, rgKeyInfo, errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString));
return;
}
if (!_missionController.load(json[_jsonMissionObjectKey].toObject(), errorString) ||
!_geoFenceController.load(json[_jsonGeoFenceObjectKey].toObject(), errorString) ||
!_rallyPointController.load(json[_jsonRallyPointsObjectKey].toObject(), errorString)) {
qgcApp()->showMessage(errorMessage.arg(errorString));
return;
}
setDirty(true);
}
void PlanMasterController::saveToFile(const QString& filename)
{
if (filename.isEmpty()) {
return;
}
QString planFilename = filename;
if (!QFileInfo(filename).fileName().contains(".")) {
planFilename += QString(".%1").arg(fileExtension());
}
QFile file(planFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(tr("Plan save error %1 : %2").arg(filename).arg(file.errorString()));
} else {
QJsonObject planJson;
QJsonObject missionJson;
QJsonObject fenceJson;
QJsonObject rallyJson;
JsonHelper::saveQGCJsonFileHeader(planJson, _planFileType, _planFileVersion);
_missionController.save(missionJson);
_geoFenceController.save(fenceJson);
_rallyPointController.save(rallyJson);
planJson[_jsonMissionObjectKey] = missionJson;
planJson[_jsonGeoFenceObjectKey] = fenceJson;
planJson[_jsonRallyPointsObjectKey] = rallyJson;
QJsonDocument saveDoc(planJson);
file.write(saveDoc.toJson());
}
// If we are connected to a real vehicle, don't clear dirty bit on saving to file since vehicle is still out of date
if (_activeVehicle->isOfflineEditingVehicle()) {
setDirty(false);
}
}
void PlanMasterController::removeAll(void)
{
}
void PlanMasterController::removeAllFromVehicle(void)
{
_missionController.removeAllFromVehicle();
_geoFenceController.removeAllFromVehicle();
_rallyPointController.removeAllFromVehicle();
}
bool PlanMasterController::containsItems(void) const
{
return _missionController.containsItems() || _geoFenceController.containsItems() || _rallyPointController.containsItems();
}
bool PlanMasterController::syncInProgress(void) const
{
return _missionController.syncInProgress() || _geoFenceController.syncInProgress() || _rallyPointController.syncInProgress();
}
bool PlanMasterController::dirty(void) const
{
return _missionController.dirty() || _geoFenceController.dirty() || _rallyPointController.dirty();
}
void PlanMasterController::setDirty(bool dirty)
{
_missionController.setDirty(dirty);
_geoFenceController.setDirty(dirty);
_rallyPointController.setDirty(dirty);
}
QString PlanMasterController::fileExtension(void) const
{
return AppSettings::planFileExtension;
}
QStringList PlanMasterController::loadNameFilters(void) const
{
QStringList filters;
filters << tr("Plan Files (*.%1)").arg(AppSettings::planFileExtension) <<
tr("Mission Files (*.%1)").arg(AppSettings::missionFileExtension) <<
tr("Waypoint Files (*.waypoints)") <<
tr("All Files (*.*)");
return filters;
}
QStringList PlanMasterController::saveNameFilters(void) const
{
QStringList filters;
filters << tr("Plan Files (*.%1)").arg(fileExtension()) << tr("All Files (*.*)");
return filters;
}
void PlanMasterController::sendPlanToVehicle(Vehicle* vehicle, const QString& filename)
{
// Use a transient PlanMasterController to accomplish this
PlanMasterController* controller = new PlanMasterController();
controller->startStaticActiveVehicle(vehicle);
controller->loadFromFile(filename);
delete controller;
}
/****************************************************************************
*
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
#pragma once
#include <QObject>
#include "MissionController.h"
#include "GeoFenceController.h"
#include "RallyPointController.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"
/// Master controller for mission, fence, rally
class PlanMasterController : public QObject
{
Q_OBJECT
public:
PlanMasterController(QObject* parent = NULL);
~PlanMasterController();
Q_PROPERTY(MissionController* missionController READ missionController CONSTANT)
Q_PROPERTY(GeoFenceController* geoFenceController READ geoFenceController CONSTANT)
Q_PROPERTY(RallyPointController* rallyPointController READ rallyPointController CONSTANT)
Q_PROPERTY(bool containsItems READ containsItems NOTIFY containsItemsChanged) ///< true: Elemement is non-empty
Q_PROPERTY(bool syncInProgress READ syncInProgress NOTIFY syncInProgressChanged) ///< true: Information is currently being saved/sent, false: no active save/send in progress
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) ///< true: Unsaved/sent changes are present, false: no changes since last save/send
Q_PROPERTY(Vehicle* vehicle READ vehicle NOTIFY vehicleChanged)
Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) ///< File extention for missions
Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT) ///< File filter list loading plan files
Q_PROPERTY(QStringList saveNameFilters READ saveNameFilters CONSTANT) ///< File filter list saving plan files
/// Should be called immediately upon Component.onCompleted.
/// @param editMode true: controller being used in Plan view, false: controller being used in Fly view
Q_INVOKABLE virtual void start(bool editMode);
/// Starts the controller using a single static active vehicle. Will not track global active vehicle changes.
Q_INVOKABLE virtual void startStaticActiveVehicle(Vehicle* vehicle);
/// Sends a plan to the specified file
/// @param[in] vehicle Vehicle we are sending a plan to
/// @param[in] filename Plan file to load
static void sendPlanToVehicle(Vehicle* vehicle, const QString& filename);
Q_INVOKABLE void loadFromVehicle(void);
Q_INVOKABLE void sendToVehicle(void);
Q_INVOKABLE void loadFromFile(const QString& filename);
Q_INVOKABLE void saveToFile(const QString& filename);
Q_INVOKABLE void removeAll(void); ///< Removes all from controller only, synce required to remove from vehicle
Q_INVOKABLE void removeAllFromVehicle(void); ///< Removes all from vehicle and controller
MissionController* missionController(void) { return &_missionController; }
GeoFenceController* geoFenceController(void) { return &_geoFenceController; }
RallyPointController* rallyPointController(void) { return &_rallyPointController; }
bool containsItems (void) const;
bool syncInProgress (void) const;
bool dirty (void) const;
void setDirty (bool dirty);
QString fileExtension (void) const;
QStringList loadNameFilters (void) const;
QStringList saveNameFilters (void) const;
Vehicle* vehicle(void) { return _activeVehicle; }
signals:
void containsItemsChanged (bool containsItems);
void syncInProgressChanged (bool syncInProgress);
void dirtyChanged (bool dirty);
void vehicleChanged (Vehicle* vehicle);
private slots:
void _activeVehicleChanged(Vehicle* activeVehicle);
private:
MultiVehicleManager* _multiVehicleMgr;
Vehicle* _activeVehicle; ///< Currently active vehicle, can be disconnected offline editing vehicle
bool _editMode;
MissionController _missionController;
GeoFenceController _geoFenceController;
RallyPointController _rallyPointController;
static const int _planFileVersion;
static const char* _planFileType;
static const char* _jsonMissionObjectKey;
static const char* _jsonGeoFenceObjectKey;
static const char* _jsonRallyPointsObjectKey;
};
......@@ -49,14 +49,16 @@ RallyPointController::~RallyPointController()
}
void RallyPointController::_activeVehicleBeingRemoved(void)
void RallyPointController::activeVehicleBeingRemoved(void)
{
_activeVehicle->rallyPointManager()->disconnect(this);
_points.clearAndDeleteContents();
_activeVehicle = NULL;
}
void RallyPointController::_activeVehicleSet(void)
void RallyPointController::activeVehicleSet(Vehicle* activeVehicle)
{
_activeVehicle = activeVehicle;
RallyPointManager* rallyPointManager = _activeVehicle->rallyPointManager();
connect(rallyPointManager, &RallyPointManager::loadComplete, this, &RallyPointController::_loadComplete);
connect(rallyPointManager, &RallyPointManager::inProgressChanged, this, &RallyPointController::syncInProgressChanged);
......@@ -67,30 +69,21 @@ void RallyPointController::_activeVehicleSet(void)
emit rallyPointsSupportedChanged(rallyPointsSupported());
}
bool RallyPointController::_loadJsonFile(QJsonDocument& jsonDoc, QString& errorString)
bool RallyPointController::load(const QJsonObject& json, QString& errorString)
{
QJsonObject json = jsonDoc.object();
int fileVersion;
if (!JsonHelper::validateQGCJsonFile(json,
_jsonFileTypeValue, // expected file type
1, // minimum supported version
1, // maximum supported version
fileVersion,
errorString)) {
return false;
}
QString errorStr;
QString errorMessage = tr("Rally: %1");
// Check for required keys
QStringList requiredKeys = { _jsonPointsKey };
if (!JsonHelper::validateRequiredKeys(json, requiredKeys, errorString)) {
if (!JsonHelper::validateRequiredKeys(json, requiredKeys, errorStr)) {
errorString = errorMessage.arg(errorStr);
return false;
}
// Load points
QList<QGeoCoordinate> rgPoints;
if (!JsonHelper::loadGeoCoordinateArray(json[_jsonPointsKey], true /* altitudeRequired */, rgPoints, errorString)) {
if (!JsonHelper::loadGeoCoordinateArray(json[_jsonPointsKey], true /* altitudeRequired */, rgPoints, errorStr)) {
errorString = errorMessage.arg(errorStr);
return false;
}
_points.clearAndDeleteContents();
......@@ -100,63 +93,15 @@ bool RallyPointController::_loadJsonFile(QJsonDocument& jsonDoc, QString& errorS
}
_points.swapObjectList(pointList);
return true;
}
void RallyPointController::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();
if (JsonHelper::isJsonFile(bytes, jsonDoc)) {
_loadJsonFile(jsonDoc, errorString);
} else {
// FIXME: No MP file format support
qgcApp()->showMessage("Rall Point file is in incorrect format.");
return;
}
}
if (!errorString.isEmpty()) {
qgcApp()->showMessage(errorString);
}
setDirty(true);
setDirty(false);
_setFirstPointCurrent();
return true;
}
void RallyPointController::saveToFile(const QString& filename)
void RallyPointController::save(QJsonObject& json)
{
if (filename.isEmpty()) {
return;
}
QString rallyFilename = filename;
if (!QFileInfo(filename).fileName().contains(".")) {
rallyFilename += QString(".%1").arg(AppSettings::rallyPointFileExtension);
}
QFile file(rallyFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(file.errorString());
} else {
QJsonObject jsonObject;
jsonObject[JsonHelper::jsonFileTypeKey] = _jsonFileTypeValue;
jsonObject[JsonHelper::jsonVersionKey] = 1;
jsonObject[JsonHelper::jsonGroundStationKey] = JsonHelper::jsonGroundStationValue;
json[JsonHelper::jsonVersionKey] = 1;
QJsonArray rgPoints;
QJsonValue jsonPoint;
......@@ -164,13 +109,7 @@ void RallyPointController::saveToFile(const QString& filename)
JsonHelper::saveGeoCoordinate(qobject_cast<RallyPoint*>(_points[i])->coordinate(), true /* writeAltitude */, jsonPoint);
rgPoints.append(jsonPoint);
}
jsonObject[_jsonPointsKey] = QJsonValue(rgPoints);
QJsonDocument saveDoc(jsonObject);
file.write(saveDoc.toJson());
}
setDirty(false);
json[_jsonPointsKey] = QJsonValue(rgPoints);
}
void RallyPointController::removeAll(void)
......@@ -234,11 +173,6 @@ void RallyPointController::_loadComplete(const QList<QGeoCoordinate> rgPoints)
emit loadComplete();
}
QString RallyPointController::fileExtension(void) const
{
return AppSettings::rallyPointFileExtension;
}
void RallyPointController::addPoint(QGeoCoordinate point)
{
double defaultAlt;
......
......@@ -37,18 +37,18 @@ public:
Q_INVOKABLE void addPoint(QGeoCoordinate point);
Q_INVOKABLE void removePoint(QObject* rallyPoint);
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 { return _dirty; }
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 rallyPointsSupported (void) const;
QmlObjectListModel* points (void) { return &_points; }
......@@ -68,11 +68,6 @@ private slots:
void _updateContainsItems(void);
private:
bool _loadJsonFile(QJsonDocument& jsonDoc, QString& errorString);
void _activeVehicleBeingRemoved(void) final;
void _activeVehicleSet(void) final;
bool _dirty;
QmlObjectListModel _points;
QObject* _currentRallyPoint;
......
......@@ -20,6 +20,7 @@ Rectangle {
radius: _radius
property var map ///< Map control
property var missionController
property var missionItem ///< MissionItem associated with this editor
property bool readOnly ///< true: read only view, false: full editing view
property var rootQgcView
......
......@@ -23,21 +23,22 @@ Rectangle {
signal showFlyView
property var missionController
property var planMasterController
property var currentMissionItem ///< Mission item to display status for
property var missionItems: _controllerValid ? missionController.visualItems : undefined
property real missionDistance: _controllerValid ? missionController.missionDistance : NaN
property real missionTime: _controllerValid ? missionController.missionTime : NaN
property real missionMaxTelemetry: _controllerValid ? missionController.missionMaxTelemetry : NaN
property bool missionDirty: _controllerValid ? missionController.dirty : false
property var missionItems: _controllerValid ? planMasterController.missionController.visualItems : undefined
property real missionDistance: _controllerValid ? planMasterController.missionController.missionDistance : NaN
property real missionTime: _controllerValid ? planMasterController.missionController.missionTime : NaN
property real missionMaxTelemetry: _controllerValid ? planMasterController.missionController.missionMaxTelemetry : NaN
property bool missionDirty: _controllerValid ? planMasterController.missionController.dirty : false
property bool _controllerValid: planMasterController != undefined
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property var _controllerDirty: planMasterController ? planMasterController.dirty : false
property var _controllerSyncInProgress: planMasterController ? planMasterController.syncInProgress : false
property bool _statusValid: currentMissionItem != undefined
property bool _missionValid: missionItems != undefined
property bool _controllerValid: missionController != undefined
property bool _manualUpload: QGroundControl.settingsManager.appSettings.automaticMissionUpload.rawValue == 0
property real _dataFontSize: ScreenTools.defaultFontPointSize
property real _largeValueWidth: ScreenTools.defaultFontPixelWidth * 8
......@@ -54,8 +55,8 @@ Rectangle {
property real _missionDistance: _missionValid ? missionDistance : NaN
property real _missionMaxTelemetry: _missionValid ? missionMaxTelemetry : NaN
property real _missionTime: _missionValid ? missionTime : NaN
property int _batteryChangePoint: _controllerValid ? missionController.batteryChangePoint : -1
property int _batteriesRequired: _controllerValid ? missionController.batteriesRequired : -1
property int _batteryChangePoint: _controllerValid ? planMasterController.missionController.batteryChangePoint : -1
property int _batteriesRequired: _controllerValid ? planMasterController.missionController.batteriesRequired : -1
property string _distanceText: isNaN(_distance) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
property string _altDifferenceText: isNaN(_altDifference) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
......@@ -104,12 +105,10 @@ Rectangle {
checked: false
onClicked: {
checked = false
if (missionController.uploadOnSwitch()) {
showFlyView()
}
}
}
}
RowLayout {
anchors.top: parent.top
......@@ -245,17 +244,17 @@ Rectangle {
anchors.rightMargin: _margins
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: missionController ? (missionController.dirty ? qsTr("Upload Required") : qsTr("Upload")) : ""
enabled: _activeVehicle && !missionController.syncInProgress
visible: _activeVehicle && _manualUpload
onClicked: missionController.upload()
text: _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
enabled: _activeVehicle && !_controllerSyncInProgress
visible: _activeVehicle
onClicked: planMasterController.upload()
PropertyAnimation on opacity {
easing.type: Easing.OutQuart
from: 0.5
to: 1
loops: Animation.Infinite
running: missionController ? missionController.dirty : false
running: _controllerDirty
alwaysRunToEnd: true
duration: 2000
}
......
This diff is collapsed.
......@@ -64,9 +64,7 @@
#include "QGroundControlQmlGlobal.h"
#include "FlightMapSettings.h"
#include "CoordinateVector.h"
#include "MissionController.h"
#include "GeoFenceController.h"
#include "RallyPointController.h"
#include "PlanMasterController.h"
#include "VideoManager.h"
#include "VideoSurface.h"
#include "VideoReceiver.h"
......@@ -384,6 +382,7 @@ void QGCApplication::_initCommon(void)
qmlRegisterType<ParameterEditorController> ("QGroundControl.Controllers", 1, 0, "ParameterEditorController");
qmlRegisterType<ESP8266ComponentController> ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController");
qmlRegisterType<ScreenToolsController> ("QGroundControl.Controllers", 1, 0, "ScreenToolsController");
qmlRegisterType<PlanMasterController> ("QGroundControl.Controllers", 1, 0, "PlanElemementMasterController");
qmlRegisterType<MissionController> ("QGroundControl.Controllers", 1, 0, "MissionController");
qmlRegisterType<GeoFenceController> ("QGroundControl.Controllers", 1, 0, "GeoFenceController");
qmlRegisterType<RallyPointController> ("QGroundControl.Controllers", 1, 0, "RallyPointController");
......
......@@ -34,6 +34,7 @@ const char* AppSettings::autoLoadMissionsName = "AutoLoa
const char* AppSettings::automaticMissionUploadName = "AutomaticMissionUpload";
const char* AppSettings::parameterFileExtension = "params";
const char* AppSettings::planFileExtension = "plan";
const char* AppSettings::missionFileExtension = "mission";
const char* AppSettings::fenceFileExtension = "fence";
const char* AppSettings::rallyPointFileExtension = "rally";
......
......@@ -40,6 +40,7 @@ public:
Q_PROPERTY(QString parameterSavePath READ parameterSavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString telemetrySavePath READ telemetrySavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString planFileExtension MEMBER planFileExtension CONSTANT)
Q_PROPERTY(QString missionFileExtension MEMBER missionFileExtension CONSTANT)
Q_PROPERTY(QString parameterFileExtension MEMBER parameterFileExtension CONSTANT)
Q_PROPERTY(QString telemetryFileExtension MEMBER telemetryFileExtension CONSTANT)
......@@ -86,6 +87,7 @@ public:
// Application wide file extensions
static const char* parameterFileExtension;
static const char* planFileExtension;
static const char* missionFileExtension;
static const char* fenceFileExtension;
static const char* rallyPointFileExtension;
......
......@@ -17,6 +17,7 @@
#include "JoystickManager.h"
#include "MissionManager.h"
#include "MissionController.h"
#include "PlanMasterController.h"
#include "GeoFenceManager.h"
#include "RallyPointManager.h"
#include "CoordinateVector.h"
......@@ -1627,11 +1628,10 @@ void Vehicle::_startMissionRequest(void)
if (_settingsManager->appSettings()->autoLoadMissions()->rawValue().toBool()) {
QString missionAutoLoadDirPath = _settingsManager->appSettings()->missionSavePath();
if (!missionAutoLoadDirPath.isEmpty()) {
QmlObjectListModel* visualItems = NULL;
QDir missionAutoLoadDir(missionAutoLoadDirPath);
QString autoloadFilename = missionAutoLoadDir.absoluteFilePath(tr("AutoLoad%1.%2").arg(_id).arg(AppSettings::missionFileExtension));
if (MissionController::loadItemsFromFile(this, autoloadFilename, &visualItems)) {
MissionController::sendItemsToVehicle(this, visualItems);
QString autoloadFilename = missionAutoLoadDir.absoluteFilePath(tr("AutoLoad%1.%2").arg(_id).arg(AppSettings::planFileExtension));
if (QFile(autoloadFilename).exists()) {
PlanMasterController::sendPlanToVehicle(this, autoloadFilename);
return;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment