diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index a126125..ddad6c0 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -1375,23 +1375,8 @@ void MainWindow::loadWidgets() //loadPilotView(); } -void MainWindow::loadDataView() -{ - clearView(); - - // DATAPLOT - if (dataplotWidget) - { - QStackedWidget *centerStack = dynamic_cast(centralWidget()); - if (centerStack) - centerStack->setCurrentWidget(dataplotWidget); - } -} - void MainWindow::loadDataView(QString fileName) { - clearView(); - // DATAPLOT if (dataplotWidget) { diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index cb69f3d..f866e9a 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -151,8 +151,6 @@ public slots: void loadWidgets(); /** @brief Load data view, allowing to plot flight data */ - void loadDataView(); - /** @brief Load data view, allowing to plot flight data */ void loadDataView(QString fileName); /** @brief Load 3D map view */ diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index afaf40d..287c962 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -126,6 +126,13 @@ void QGCDataPlot2D::savePlot() fileName = QFileDialog::getSaveFileName( this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), "PDF Documents (*.pdf);;SVG Images (*.svg)"); + + if (!fileName.contains(".")) + { + // .csv is default extension + fileName.append(".pdf"); + } + while(!(fileName.endsWith(".svg") || fileName.endsWith(".pdf"))) { QMessageBox msgBox; diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index afa3a2f..7c119fd 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -57,7 +57,7 @@ maxTime(QUINT64_MIN), maxInterval(MAX_STORAGE_INTERVAL), timeScaleStep(DEFAULT_SCALE_INTERVAL), // 10 seconds automaticScrollActive(false), -m_active(true), +m_active(false), m_groundTime(true), d_data(NULL), d_curve(NULL) @@ -286,6 +286,14 @@ void LinechartPlot::enforceGroundTime(bool enforce) m_groundTime = enforce; } +/** + * @return True if the data points are stamped with the packet receive time + */ +bool LinechartPlot::groundTime() +{ + return m_groundTime; +} + void LinechartPlot::addCurve(QString id) { QColor currentColor = getNextColor(); @@ -469,6 +477,23 @@ bool LinechartPlot::isVisible(QString id) } /** + * @return The visibility, true if it is visible, false otherwise + **/ +bool LinechartPlot::anyCurveVisible() +{ + bool visible = false; + foreach (QString key, curves.keys()) + { + if (curves.value(key)->isVisible()) + { + visible = true; + } + } + + return visible; +} + +/** * @brief Allows to block interference of the automatic scrolling with user interaction * When the plot is updated very fast (at 1 ms for example) with new data, it might * get impossible for an user to interact. Therefore the automatic scrolling must be diff --git a/src/ui/linechart/LinechartPlot.h b/src/ui/linechart/LinechartPlot.h index 6f0f3b5..60f1254 100644 --- a/src/ui/linechart/LinechartPlot.h +++ b/src/ui/linechart/LinechartPlot.h @@ -190,6 +190,8 @@ public: QList getCurves(); bool isVisible(QString id); + /** @brief Check if any curve is visible */ + bool anyCurveVisible(); int getPlotId(); /** @brief Get the number of values to average over */ @@ -243,6 +245,8 @@ public slots: /** @brief Enforce the use of the receive timestamp */ void enforceGroundTime(bool enforce); + /** @brief Check if the receive timestamp is enforced */ + bool groundTime(); // General interaction void setWindowPosition(quint64 end); diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 8bebe56..2133660 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -48,6 +48,7 @@ This file is part of the PIXHAWK project #include "LinechartWidget.h" #include "LinechartPlot.h" #include "LogCompressor.h" +#include "QGC.h" #include "MG.h" @@ -225,7 +226,18 @@ void LinechartWidget::appendData(int uasId, QString curve, double value, quint64 { if (activePlot->isVisible(curve)) { - logFile->write(QString(QString::number(usec) + "\t" + QString::number(uasId) + "\t" + curve + "\t" + QString::number(value) + "\n").toLatin1()); + quint64 time = 0; + // Adjust time + if (activePlot->groundTime()) + { + time = QGC::groundTimeUsecs() - logStartTime; + } + else + { + time = usec - logStartTime; + } + + logFile->write(QString(QString::number(time) + "\t" + QString::number(uasId) + "\t" + curve + "\t" + QString::number(value) + "\n").toLatin1()); logFile->flush(); } } @@ -261,14 +273,35 @@ void LinechartWidget::refresh() void LinechartWidget::startLogging() { - // Let user select the log file name - QDate date(QDate::currentDate()); - // QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log") - QString fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.txt, *.csv);;")); // Store reference to file // Append correct file ending if needed bool abort = false; - while (!(fileName.endsWith(".txt") || fileName.endsWith(".csv"))) + + // Check if any curve is enabled + if (!activePlot->anyCurveVisible()) + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText("No curves selected for logging."); + msgBox.setInformativeText("Please check all curves you want to log. Currently no data would be logged, aborting the logging."); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.exec(); + return; + } + + // Let user select the log file name + QDate date(QDate::currentDate()); + // QString("./pixhawk-log-" + date.toString("yyyy-MM-dd") + "-" + QString::number(logindex) + ".log") + QString fileName = QFileDialog::getSaveFileName(this, tr("Specify log file name"), QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), tr("Logfile (*.csv, *.txt);;")); + + if (!fileName.contains(".")) + { + // .csv is default extension + fileName.append(".csv"); + } + + while (!(fileName.endsWith(".txt") || fileName.endsWith(".csv")) && !abort) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Critical); @@ -292,6 +325,7 @@ void LinechartWidget::startLogging() if (logFile->open(QIODevice::WriteOnly | QIODevice::Text)) { logging = true; + logStartTime = QGC::groundTimeUsecs(); logindex++; logButton->setText(tr("Stop logging")); disconnect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 3f94e90..5ce13eb 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -131,6 +131,7 @@ protected: bool logging; QTimer* updateTimer; LogCompressor* compressor; + quint64 logStartTime; static const int MAX_CURVE_MENUITEM_NUMBER = 8; static const int PAGESTEP_TIME_SCROLLBAR_VALUE = (MAX_TIME_SCROLLBAR_VALUE - MIN_TIME_SCROLLBAR_VALUE) / 10;