Skip to content

Commit

Permalink
Merge pull request mavlink#6328 from DonLakeFlyer/GeoTagError
Browse files Browse the repository at this point in the history
Geo Tag: Much better error reporting
  • Loading branch information
DonLakeFlyer authored Apr 9, 2018
2 parents cd1955e + 82c0424 commit 86a36ac
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
33 changes: 18 additions & 15 deletions src/AnalyzeView/GeoTagController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ void GeoTagController::startTagging(void)

QDir imageDirectory = QDir(_worker.imageDirectory());
if(!imageDirectory.exists()) {
_errorMessage = tr("Cannot find the image directory");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Cannot find the image directory"));
return;
}
if(_worker.saveDirectory() == "") {
Expand All @@ -83,23 +82,20 @@ void GeoTagController::startTagging(void)
msgBox.setWindowModality(Qt::ApplicationModal);
msgBox.addButton(tr("Replace"), QMessageBox::ActionRole);
if (msgBox.exec() == QMessageBox::Cancel) {
_errorMessage = tr("Images have already been tagged");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Images have already been tagged"));
return;
}
QDir oldTaggedFolder = QDir(_worker.imageDirectory() + "/TAGGED");
oldTaggedFolder.removeRecursively();
if(!imageDirectory.mkdir(_worker.imageDirectory() + "/TAGGED")) {
_errorMessage = tr("Couldn't replace the previously tagged images");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Couldn't replace the previously tagged images"));
return;
}
}
} else {
QDir saveDirectory = QDir(_worker.saveDirectory());
if(!saveDirectory.exists()) {
_errorMessage = tr("Cannot find the save directory");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Cannot find the save directory"));
return;
}
saveDirectory.setFilter(QDir::Files | QDir::Readable | QDir::NoSymLinks | QDir::Writable);
Expand All @@ -115,15 +111,13 @@ void GeoTagController::startTagging(void)
msgBox.setWindowModality(Qt::ApplicationModal);
msgBox.addButton(tr("Replace"), QMessageBox::ActionRole);
if (msgBox.exec() == QMessageBox::Cancel) {
_errorMessage = tr("Save folder not empty");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Save folder not empty"));
return;
}
foreach(QString dirFile, imageList)
{
if(!saveDirectory.remove(dirFile)) {
_errorMessage = tr("Couldn't replace the existing images");
emit errorMessageChanged(_errorMessage);
_setErrorMessage(tr("Couldn't replace the existing images"));
return;
}
}
Expand All @@ -144,6 +138,13 @@ void GeoTagController::_workerError(QString errorMessage)
emit errorMessageChanged(errorMessage);
}


void GeoTagController::_setErrorMessage(const QString& error)
{
_errorMessage = error;
emit errorMessageChanged(error);
}

GeoTagWorker::GeoTagWorker(void)
: _cancel(false)
, _logFile("")
Expand Down Expand Up @@ -210,9 +211,10 @@ void GeoTagWorker::run(void)
// Instantiate appropriate parser
_triggerList.clear();
bool parseComplete = false;
if(isULog) {
QString errorString;
if (isULog) {
ULogParser parser;
parseComplete = parser.getTagsFromLog(log, _triggerList);
parseComplete = parser.getTagsFromLog(log, _triggerList, errorString);

} else {
PX4LogParser parser;
Expand All @@ -227,7 +229,8 @@ void GeoTagWorker::run(void)
return;
} else {
qCDebug(GeotaggingLog) << "Log parsing failed";
emit error(tr("Log parsing failed - tagging cancelled"));
errorString = tr("%1 - tagging cancelled").arg(errorString.isEmpty() ? tr("Log parsing failed") : errorString);
emit error(errorString);
return;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/AnalyzeView/GeoTagController.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class GeoTagController : public QObject
void errorMessageChanged (QString errorMessage);

private slots:
void _workerProgressChanged(double progress);
void _workerError(QString errorMsg);
void _workerProgressChanged (double progress);
void _workerError (QString errorMsg);
void _setErrorMessage (const QString& error);

private:
QString _errorMessage;
Expand Down
5 changes: 3 additions & 2 deletions src/AnalyzeView/GeoTagPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ AnalyzePage {
}

QGCButton {
text: geoController.inProgress ? qsTr("Cancel Tagging") : qsTr("Start Tagging")
width: ScreenTools.defaultFontPixelWidth * 30
text: geoController.inProgress ? qsTr("Cancel Tagging") : qsTr("Start Tagging")
width: ScreenTools.defaultFontPixelWidth * 30

onClicked: {
if (geoController.inProgress) {
geoController.cancelTagging()
Expand Down
8 changes: 5 additions & 3 deletions src/AnalyzeView/ULogParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ bool ULogParser::parseFieldFormat(QString& fields)
return false;
}

bool ULogParser::getTagsFromLog(QByteArray& log, QList<GeoTagWorker::cameraFeedbackPacket>& cameraFeedback)
bool ULogParser::getTagsFromLog(QByteArray& log, QList<GeoTagWorker::cameraFeedbackPacket>& cameraFeedback, QString& errorMessage)
{
errorMessage.clear();

//verify it's an ULog file
if(!log.contains(_ULogMagic)) {
qWarning() << "Could not detect ULog file header magic";
errorMessage = tr("Could not detect ULog file header magic");
return false;
}

Expand Down Expand Up @@ -175,7 +177,7 @@ bool ULogParser::getTagsFromLog(QByteArray& log, QList<GeoTagWorker::cameraFeedb
}

if (cameraFeedback.count() == 0) {
qWarning() << "Could not detect camera_capture packets in ULog";
errorMessage = tr("Could not detect camera_capture packets in ULog");
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion src/AnalyzeView/ULogParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@

#include <QGeoCoordinate>
#include <QDebug>
#include <QCoreApplication>

#include "GeoTagController.h"

#define ULOG_FILE_HEADER_LEN 16

class ULogParser
{
Q_DECLARE_TR_FUNCTIONS(ULogParser)

public:
ULogParser();
~ULogParser();
bool getTagsFromLog(QByteArray& log, QList<GeoTagWorker::cameraFeedbackPacket>& cameraFeedback);

/// @return true: failed, errorMessage set
bool getTagsFromLog(QByteArray& log, QList<GeoTagWorker::cameraFeedbackPacket>& cameraFeedback, QString& errorMessage);

private:

Expand Down

0 comments on commit 86a36ac

Please sign in to comment.