Commit 12b1624e authored by DonLakeFlyer's avatar DonLakeFlyer

More work on Plan sync user model

parent 62fb732c
......@@ -65,11 +65,11 @@ ColumnLayout {
QGCButton {
text: qsTr("Current Location")
Layout.fillWidth: true
enabled: mainWindow.gcsPosition.isValid
enabled: _map.gcsPosition.isValid
onClicked: {
dropPanel.hide()
map.center = mainWindow.gcsPosition
map.center = _map.gcsPosition
}
}
......
......@@ -56,6 +56,7 @@ MissionController::MissionController(QObject *parent)
, _queuedSend(false)
, _surveyMissionItemName(tr("Survey"))
, _fwLandingMissionItemName(tr("Fixed Wing Landing"))
, _appSettings(qgcApp()->toolbox()->settingsManager()->appSettings())
{
_missionFlightStatus.maxTelemetryDistance = 0;
_missionFlightStatus.totalDistance = 0;
......@@ -449,18 +450,18 @@ bool MissionController::_loadJsonMissionFileV2(Vehicle* vehicle, const QJsonObje
// Mission Settings
QGeoCoordinate homeCoordinate;
SettingsManager* settingsManager = qgcApp()->toolbox()->settingsManager();
AppSettings* appSettings = qgcApp()->toolbox()->settingsManager()->appSettings();
if (!JsonHelper::loadGeoCoordinate(json[_jsonPlannedHomePositionKey], true /* altitudeRequired */, homeCoordinate, errorString)) {
return false;
}
if (json.contains(_jsonVehicleTypeKey) && vehicle->isOfflineEditingVehicle()) {
settingsManager->appSettings()->offlineEditingVehicleType()->setRawValue(json[_jsonVehicleTypeKey].toDouble());
appSettings->offlineEditingVehicleType()->setRawValue(json[_jsonVehicleTypeKey].toDouble());
}
if (json.contains(_jsonCruiseSpeedKey)) {
settingsManager->appSettings()->offlineEditingCruiseSpeed()->setRawValue(json[_jsonCruiseSpeedKey].toDouble());
appSettings->offlineEditingCruiseSpeed()->setRawValue(json[_jsonCruiseSpeedKey].toDouble());
}
if (json.contains(_jsonHoverSpeedKey)) {
settingsManager->appSettings()->offlineEditingHoverSpeed()->setRawValue(json[_jsonHoverSpeedKey].toDouble());
appSettings->offlineEditingHoverSpeed()->setRawValue(json[_jsonHoverSpeedKey].toDouble());
}
MissionSettingsItem* settingsItem = new MissionSettingsItem(vehicle, visualItems);
......@@ -647,17 +648,27 @@ void MissionController::loadFromFile(const QString& filename)
_initAllVisualItems();
// Split the filename into directory and filename
QString filenameOnly = filename;
int lastSepIndex = filename.lastIndexOf(QStringLiteral("/"));
if (lastSepIndex != -1) {
filenameOnly = filename.right(filename.length() - lastSepIndex - 1);
}
QString directoryOnly = filename.left(filename.length() - filenameOnly.length() - 1);
QString extension = AppSettings::missionFileExtension;
if (filenameOnly.endsWith("." + extension)) {
filenameOnly = filenameOnly.left(filenameOnly.length() - extension.length() - 1);
}
_settingsItem->missionName()->setRawValue(filenameOnly);
if (directoryOnly == qgcApp()->toolbox()->settingsManager()->appSettings()->missionSavePath()) {
QString emptyString;
_settingsItem->setLoadedMissionDirectory(emptyString);
} else {
_settingsItem->setLoadedMissionDirectory(directoryOnly);
}
_settingsItem->setExistingMission(true);
sendToVehicle();
......@@ -704,8 +715,6 @@ bool MissionController::loadItemsFromFile(Vehicle* vehicle, const QString& filen
void MissionController::saveToFile(const QString& filename)
{
qDebug() << filename;
if (filename.isEmpty()) {
return;
}
......@@ -718,7 +727,7 @@ void MissionController::saveToFile(const QString& filename)
QFile file(missionFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(file.errorString());
qgcApp()->showMessage(tr("Mission save %1 : %2").arg(filename).arg(file.errorString()));
} else {
QJsonObject missionFileObject; // top level json object
......@@ -1596,9 +1605,17 @@ bool MissionController::missionInProgress(void) const
void MissionController::save(void)
{
// Save to file if the mission is named
QString missionFullPath = _settingsItem->missionFullPath()->rawValue().toString();
if (!missionFullPath.isEmpty()) {
saveToFile(missionFullPath);
QString missionDir = _settingsItem->loadedMissionDirectory();
if (missionDir.isEmpty()) {
missionDir = _appSettings->missionSavePath();
}
bool savedToFile = false;
QString missionName = _settingsItem->missionName()->rawValue().toString();
if (!missionDir.isEmpty() && !missionName.isEmpty()) {
savedToFile = true;
saveToFile(missionDir + "/" + missionName);
}
// Send to vehicle if we are connected
......@@ -1606,11 +1623,22 @@ void MissionController::save(void)
sendToVehicle();
}
_settingsItem->setExistingMission(_visualItems->count() > 1 && !missionFullPath.isEmpty());
_settingsItem->setExistingMission(savedToFile);
}
void MissionController::clearMission(void)
{
// We need to save the mission information around removeAll all since it delete/recreates settings item
QString missionName = _settingsItem->missionName()->rawValue().toString();
QString loadedMissionDirectory = _settingsItem->loadedMissionDirectory();
bool existingMission = _settingsItem->existingMission();
removeAll();
_settingsItem->missionName()->setRawValue(missionName);
_settingsItem->setLoadedMissionDirectory(loadedMissionDirectory);
_settingsItem->setExistingMission(existingMission);
}
void MissionController::closeMission(void)
{
removeAll();
save();
}
......@@ -23,6 +23,7 @@ class CoordinateVector;
class VisualMissionItem;
class MissionItem;
class MissionSettingsItem;
class AppSettings;
Q_DECLARE_LOGGING_CATEGORY(MissionControllerLog)
......@@ -88,9 +89,15 @@ public:
/// Sends the mission items to the specified vehicle
static void sendItemsToVehicle(Vehicle* vehicle, QmlObjectListModel* visualMissionItems);
/// Saves the mission to file if any and sends to vehicle
Q_INVOKABLE void save(void);
/// Removes all items from the mission saving and sending as needed
Q_INVOKABLE void clearMission(void);
/// Closes the mission, saving and sending as needed before closing
Q_INVOKABLE void closeMission(void);
// Overrides from PlanElementController
void start (bool editMode) final;
void startStaticActiveVehicle (Vehicle* vehicle) final;
......@@ -193,6 +200,7 @@ private:
MissionFlightStatus_t _missionFlightStatus;
QString _surveyMissionItemName;
QString _fwLandingMissionItemName;
AppSettings* _appSettings;
static const char* _settingsGroup;
......
......@@ -24,7 +24,6 @@ QGC_LOGGING_CATEGORY(MissionSettingsComplexItemLog, "MissionSettingsComplexItemL
const char* MissionSettingsItem::jsonComplexItemTypeValue = "MissionSettings";
const char* MissionSettingsItem::_missionNameName = "MissionName";
const char* MissionSettingsItem::_missionFullPathName = "MissionFullPath";
const char* MissionSettingsItem::_plannedHomePositionAltitudeName = "PlannedHomePositionAltitude";
const char* MissionSettingsItem::_missionFlightSpeedName = "FlightSpeed";
const char* MissionSettingsItem::_missionEndActionName = "MissionEndAction";
......@@ -36,7 +35,6 @@ MissionSettingsItem::MissionSettingsItem(Vehicle* vehicle, QObject* parent)
, _existingMission(false)
, _specifyMissionFlightSpeed(false)
, _missionNameFact (0, _missionNameName, FactMetaData::valueTypeString)
, _missionFullPathFact (0, _missionFullPathName, FactMetaData::valueTypeString)
, _plannedHomePositionAltitudeFact (0, _plannedHomePositionAltitudeName, FactMetaData::valueTypeDouble)
, _missionFlightSpeedFact (0, _missionFlightSpeedName, FactMetaData::valueTypeDouble)
, _missionEndActionFact (0, _missionEndActionName, FactMetaData::valueTypeUint32)
......@@ -65,8 +63,6 @@ MissionSettingsItem::MissionSettingsItem(Vehicle* vehicle, QObject* parent)
setHomePositionSpecialCase(true);
connect(&_missionNameFact, &Fact::valueChanged, this, &MissionSettingsItem::_missionNameChanged);
connect(this, &MissionSettingsItem::specifyMissionFlightSpeedChanged, this, &MissionSettingsItem::_setDirtyAndUpdateLastSequenceNumber);
connect(&_cameraSection, &CameraSection::missionItemCountChanged, this, &MissionSettingsItem::_setDirtyAndUpdateLastSequenceNumber);
......@@ -416,18 +412,6 @@ void MissionSettingsItem::_updateAltitudeInCoordinate(QVariant value)
}
}
void MissionSettingsItem::_missionNameChanged(QVariant value)
{
QString missionDir = qgcApp()->toolbox()->settingsManager()->appSettings()->missionSavePath();
QString missionName = value.toString();
if (missionName.isEmpty()) {
_missionFullPathFact.setRawValue(QString());
} else {
_missionFullPathFact.setRawValue(missionDir + "/" + missionName);
}
}
void MissionSettingsItem::setExistingMission(bool existingMission)
{
if (existingMission != _existingMission) {
......@@ -435,3 +419,11 @@ void MissionSettingsItem::setExistingMission(bool existingMission)
emit existingMissionChanged(existingMission );
}
}
void MissionSettingsItem::setLoadedMissionDirectory(QString& loadedMissionDirectory)
{
if (_loadedMissionDirectory != loadedMissionDirectory) {
_loadedMissionDirectory = loadedMissionDirectory;
emit loadedMissionDirectoryChanged(loadedMissionDirectory);
}
}
......@@ -33,7 +33,7 @@ public:
Q_ENUMS(MissionEndAction)
Q_PROPERTY(Fact* missionName READ missionName CONSTANT)
Q_PROPERTY(Fact* missionFullPath READ missionFullPath CONSTANT)
Q_PROPERTY(QString loadedMissionDirectory READ loadedMissionDirectory WRITE setLoadedMissionDirectory NOTIFY loadedMissionDirectoryChanged)
Q_PROPERTY(bool existingMission READ existingMission WRITE setExistingMission NOTIFY existingMissionChanged)
Q_PROPERTY(bool specifyMissionFlightSpeed READ specifyMissionFlightSpeed WRITE setSpecifyMissionFlightSpeed NOTIFY specifyMissionFlightSpeedChanged)
Q_PROPERTY(Fact* missionFlightSpeed READ missionFlightSpeed CONSTANT)
......@@ -42,7 +42,6 @@ public:
Q_PROPERTY(QObject* cameraSection READ cameraSection CONSTANT)
Fact* missionName (void) { return &_missionNameFact; }
Fact* missionFullPath (void) { return &_missionFullPathFact; }
Fact* plannedHomePositionAltitude (void) { return &_plannedHomePositionAltitudeFact; }
Fact* missionFlightSpeed (void) { return &_missionFlightSpeedFact; }
Fact* missionEndAction (void) { return &_missionEndActionFact; }
......@@ -63,6 +62,10 @@ public:
/// @return true: Mission end action was added
bool addMissionEndAction(QList<MissionItem*>& items, int seqNum, QObject* missionItemParent);
// Returns the directory the misiosn was loaded from. Empty string is laoded from normal savePath.
QString loadedMissionDirectory(void) const { return _loadedMissionDirectory; }
void setLoadedMissionDirectory(QString& loadedMissionDirectory);
// Overrides from ComplexMissionItem
double complexDistance (void) const final;
......@@ -102,23 +105,23 @@ public:
signals:
void specifyMissionFlightSpeedChanged(bool specifyMissionFlightSpeed);
void existingMissionChanged(bool existingMission);
void loadedMissionDirectoryChanged(QString& loadedMissionDirectory);
private slots:
void _setDirtyAndUpdateLastSequenceNumber (void);
void _setDirty (void);
void _cameraSectionDirtyChanged (bool dirty);
void _updateAltitudeInCoordinate (QVariant value);
void _missionNameChanged (QVariant value);
private:
bool _existingMission;
bool _specifyMissionFlightSpeed;
QGeoCoordinate _plannedHomePositionCoordinate; // Does not include altitde
Fact _missionNameFact;
Fact _missionFullPathFact;
Fact _plannedHomePositionAltitudeFact;
Fact _missionFlightSpeedFact;
Fact _missionEndActionFact;
QString _loadedMissionDirectory;
CameraSection _cameraSection;
int _sequenceNumber;
......@@ -127,7 +130,6 @@ private:
static QMap<QString, FactMetaData*> _metaDataMap;
static const char* _missionNameName;
static const char* _missionFullPathName;
static const char* _plannedHomePositionAltitudeName;
static const char* _missionFlightSpeedName;
static const char* _missionEndActionName;
......
......@@ -13,7 +13,6 @@ import QGroundControl.Palette 1.0
/// Mission item edit control
Rectangle {
id: _root
height: editorLoader.y + editorLoader.height + (_margin * 2)
color: _currentItem ? qgcPal.primaryButton : qgcPal.windowShade
radius: _radius
......@@ -21,6 +20,7 @@ Rectangle {
property var map ///< Map control
property var missionItem ///< MissionItem associated with this editor
property bool readOnly ///< true: read only view, false: full editing view
property var rootQgcView
signal clicked
signal remove
......
......@@ -35,6 +35,7 @@ Rectangle {
property bool _noMissionName: missionItem.missionName.valueString === ""
property bool _showMissionList: _noMissionItemsAdded && (_noMissionName || _newMissionAlreadyExists)
property bool _existingMissionLoaded: missionItem.existingMission
property var _appSettings: QGroundControl.settingsManager.appSettings
readonly property string _firmwareLabel: qsTr("Firmware")
readonly property string _vehicleLabel: qsTr("Vehicle")
......@@ -97,12 +98,38 @@ Rectangle {
visible: !_existingMissionLoaded && _newMissionAlreadyExists
}
FactCheckBox {
id: automaticUploadCheckbox
text: qsTr("Automatically upload on exit")
fact: _appSettings.automaticMissionUpload
}
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
QGCButton {
text: qsTr("Clear mission")
text: qsTr("Clear")
visible: !_noMissionItemsAdded
Layout.fillWidth: true
onClicked: missionController.clearMission()
}
QGCButton {
text: qsTr("Close")
visible: !_noMissionItemsAdded
Layout.fillWidth: true
onClicked: missionController.closeMission()
}
QGCButton {
text: qsTr("Upload")
visible: !_noMissionItemsAdded && !automaticUploadCheckbox.checked
Layout.fillWidth: true
onClicked: missionController.sendToVehicle()
}
}
Loader {
anchors.left: parent.left
anchors.right: parent.right
......@@ -132,14 +159,36 @@ Rectangle {
showSpacer: false
}
QGCButton {
RowLayout {
anchors.left: parent.left
anchors.right: parent.right
text: qsTr("Load from Vehicle")
QGCButton {
text: qsTr("From Vehicle")
visible: !_offlineEditing
Layout.fillWidth: true
onClicked: missionController.loadFromVehicle()
}
onClicked: {
missionController.loadFromVehicle()
QGCButton {
text: qsTr("Browse")
Layout.fillWidth: true
onClicked: fileDialog.openForLoad()
QGCFileDialog {
id: fileDialog
qgcView: rootQgcView
title: qsTr("Select mission file")
selectExisting: true
folder: _appSettings.missionSavePath
fileExtension: _appSettings.missionFileExtension
nameFilters: [ qsTr("Mission Files (*.%1)").arg(fileExtension) , qsTr("All Files (*.*)") ]
onAcceptedForLoad: {
missionController.loadFromFile(file)
fileDialog.close()
}
}
}
}
......@@ -337,5 +386,5 @@ Rectangle {
}
}
} // Column
}
} // Deferred loader
} // Rectangle
......@@ -80,7 +80,6 @@ Rectangle {
checked: false
onClicked: {
console.log("Leave plan clicked")
checked = false
missionController.saveOnSwitch()
showFlyView()
......
This diff is collapsed.
......@@ -115,6 +115,13 @@
"type": "bool",
"defaultValue": false
},
{
"name": "AutomaticMissionUpload",
"shortDescription": "Automatic mission upload",
"longDescription": "Automatically upload mission to vehicle after changes",
"type": "bool",
"defaultValue": true
},
{
"name": "SavePath",
"shortDescription": "Application save directory",
......
......@@ -31,6 +31,7 @@ const char* AppSettings::indoorPaletteName = "StyleIs
const char* AppSettings::showLargeCompassName = "ShowLargeCompass";
const char* AppSettings::savePathName = "SavePath";
const char* AppSettings::autoLoadMissionsName = "AutoLoadMissions";
const char* AppSettings::automaticMissionUploadName = "AutomaticMissionUpload";
const char* AppSettings::parameterFileExtension = "params";
const char* AppSettings::missionFileExtension = "mission";
......@@ -59,6 +60,7 @@ AppSettings::AppSettings(QObject* parent)
, _showLargeCompassFact(NULL)
, _savePathFact(NULL)
, _autoLoadMissionsFact(NULL)
, _automaticMissionUpload(NULL)
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
qmlRegisterUncreatableType<AppSettings>("QGroundControl.SettingsManager", 1, 0, "AppSettings", "Reference only");
......@@ -276,3 +278,12 @@ Fact* AppSettings::autoLoadMissions(void)
return _autoLoadMissionsFact;
}
Fact* AppSettings::automaticMissionUpload(void)
{
if (!_automaticMissionUpload) {
_automaticMissionUpload = _createSettingsFact(automaticMissionUploadName);
}
return _automaticMissionUpload;
}
......@@ -34,6 +34,7 @@ public:
Q_PROPERTY(Fact* showLargeCompass READ showLargeCompass CONSTANT)
Q_PROPERTY(Fact* savePath READ savePath CONSTANT)
Q_PROPERTY(Fact* autoLoadMissions READ autoLoadMissions CONSTANT)
Q_PROPERTY(Fact* automaticMissionUpload READ automaticMissionUpload CONSTANT)
Q_PROPERTY(QString missionSavePath READ missionSavePath NOTIFY savePathsChanged)
Q_PROPERTY(QString parameterSavePath READ parameterSavePath NOTIFY savePathsChanged)
......@@ -58,6 +59,7 @@ public:
Fact* showLargeCompass (void);
Fact* savePath (void);
Fact* autoLoadMissions (void);
Fact* automaticMissionUpload (void);
QString missionSavePath (void);
QString parameterSavePath (void);
......@@ -80,6 +82,7 @@ public:
static const char* showLargeCompassName;
static const char* savePathName;
static const char* autoLoadMissionsName;
static const char* automaticMissionUploadName;
// Application wide file extensions
static const char* parameterFileExtension;
......@@ -116,6 +119,7 @@ private:
SettingsFact* _showLargeCompassFact;
SettingsFact* _savePathFact;
SettingsFact* _autoLoadMissionsFact;
SettingsFact* _automaticMissionUpload;
};
#endif
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