From 567381565aa55f2ebde6bc55697eaf5ac80dc6a7 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Fri, 6 Oct 2017 08:13:27 +0200 Subject: [PATCH] WIP --- include/PlotJuggler/dataloader_base.h | 2 +- plotter_gui/mainwindow.cpp | 27 +++++++++---- plotter_gui/mainwindow.h | 4 +- plotter_gui/mainwindow.ui | 6 +++ plugins/DataLoadCSV/dataload_csv.cpp | 6 +-- plugins/DataLoadCSV/dataload_csv.h | 2 +- plugins/ROS/DataLoadROS/dataload_ros.cpp | 49 +++++++++++------------- plugins/ROS/DataLoadROS/dataload_ros.h | 2 +- 8 files changed, 57 insertions(+), 41 deletions(-) diff --git a/include/PlotJuggler/dataloader_base.h b/include/PlotJuggler/dataloader_base.h index 5f1865211..0e902823f 100644 --- a/include/PlotJuggler/dataloader_base.h +++ b/include/PlotJuggler/dataloader_base.h @@ -14,7 +14,7 @@ class DataLoader{ virtual const std::vector& compatibleFileExtensions() const = 0; - virtual PlotDataMap readDataFromFile(const QString& file_name) = 0; + virtual PlotDataMap readDataFromFile(const QString& file_name, bool use_previous_configuration) = 0; virtual const char* name() const = 0; diff --git a/plotter_gui/mainwindow.cpp b/plotter_gui/mainwindow.cpp index 528c60615..d42584567 100644 --- a/plotter_gui/mainwindow.cpp +++ b/plotter_gui/mainwindow.cpp @@ -116,6 +116,7 @@ MainWindow::MainWindow(const QCommandLineParser &commandline_parser, QWidget *pa this, SLOT(onActionLoadStreamer(QString)) ); ui->actionDeleteAllData->setEnabled( _test_option ); + ui->actionReloadPrevious->setEnabled( false ); if( _test_option ) { @@ -351,10 +352,12 @@ void MainWindow::createActions() connect(ui->actionSaveLayout, &QAction::triggered, this, &MainWindow::onActionSaveLayout ); connect(ui->actionLoadLayout, &QAction::triggered, this, &MainWindow::onActionLoadLayout ); connect(ui->actionLoadData, &QAction::triggered, this, &MainWindow::onActionLoadDataFile ); - connect(ui->actionLoadRecentDatafile, &QAction::triggered, this, &MainWindow::onActionReloadDataFileFromSettings ); + connect(ui->actionLoadRecentDatafile, &QAction::triggered, this, &MainWindow::onActionReloadRecentDataFile ); connect(ui->actionLoadRecentLayout, &QAction::triggered, this, &MainWindow::onActionReloadRecentLayout ); connect(ui->actionDeleteAllData, &QAction::triggered, this, &MainWindow::onDeleteLoadedData ); + connect(ui->actionReloadPrevious, &QAction::triggered, this, &MainWindow::onReloadDatafile ); + //--------------------------------------------- QSettings settings( "IcarusTechnology", "PlotJuggler"); @@ -859,6 +862,11 @@ void MainWindow::onActionLoadDataFile(bool reload_from_settings) onActionLoadDataFileImpl(filename, false ); } +void MainWindow::onReloadDatafile() +{ + +} + void MainWindow::importPlotDataMap(const PlotDataMap& new_data, bool delete_older) { // overwrite the old user_defined map @@ -987,10 +995,11 @@ void MainWindow::onActionLoadDataFileImpl(QString filename, bool reuse_last_conf _loaded_datafile = filename; ui->actionDeleteAllData->setEnabled( true ); + ui->actionReloadPrevious->setEnabled( true ); PlotDataMap mapped_data; try{ - mapped_data = _last_dataloader->readDataFromFile( filename ); + mapped_data = _last_dataloader->readDataFromFile( filename, reuse_last_configuration ); } catch(std::exception &ex) { @@ -1012,7 +1021,7 @@ void MainWindow::onActionLoadDataFileImpl(QString filename, bool reuse_last_conf } -void MainWindow::onActionReloadDataFileFromSettings() +void MainWindow::onActionReloadRecentDataFile() { onActionLoadDataFile( true ); } @@ -1066,6 +1075,7 @@ void MainWindow::onActionLoadStreamer(QString streamer_name) ui->actionStopStreaming->setEnabled(true); ui->actionDeleteAllData->setEnabled( false ); ui->actionDeleteAllData->setToolTip("Stop streaming to be able to delete the data"); + ui->actionReloadPrevious->setEnabled( false ); ui->pushButtonStreaming->setEnabled(true); ui->pushButtonStreaming->setChecked(true); @@ -1229,13 +1239,16 @@ void MainWindow::onActionLoadLayoutFromFile(QString filename, bool load_data) QMessageBox::StandardButton reload_previous; reload_previous = QMessageBox::question(0, tr("Wait!"), - tr("Do you want to reload the previous datafile and its configuration?\n\n[%1]\n").arg(filename), - QMessageBox::Yes | QMessageBox::No, + tr("Do you want to reload the previous datafile and its configuration?\n\n %1 \n\n" + "Yes: reload both the file and the previous configuration.\n" + "YesToAll: reload the file but change the previous configuration.\n" + "No: use the already loaded data.\n").arg(filename), + QMessageBox::YesToAll | QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes ); - if( reload_previous == QMessageBox::Yes ) + if( reload_previous != QMessageBox::No ) { - onActionLoadDataFileImpl( filename, true ); + onActionLoadDataFileImpl( filename, reload_previous == QMessageBox::YesToAll ); } } diff --git a/plotter_gui/mainwindow.h b/plotter_gui/mainwindow.h index 97926ff16..2e00fdeff 100644 --- a/plotter_gui/mainwindow.h +++ b/plotter_gui/mainwindow.h @@ -58,9 +58,11 @@ private slots: void onActionLoadDataFile(bool reload_from_settings = false); + void onReloadDatafile(); + void onActionLoadDataFileImpl(QString filename, bool reuse_last_configuration = false ); - void onActionReloadDataFileFromSettings(); + void onActionReloadRecentDataFile(); void onActionReloadRecentLayout(); diff --git a/plotter_gui/mainwindow.ui b/plotter_gui/mainwindow.ui index a6adfcf15..9e99a7615 100644 --- a/plotter_gui/mainwindow.ui +++ b/plotter_gui/mainwindow.ui @@ -444,6 +444,7 @@ background: white; + @@ -547,6 +548,11 @@ background: white; Clear buffer + + + Reload previous + + diff --git a/plugins/DataLoadCSV/dataload_csv.cpp b/plugins/DataLoadCSV/dataload_csv.cpp index 99399a7fa..6b8085696 100644 --- a/plugins/DataLoadCSV/dataload_csv.cpp +++ b/plugins/DataLoadCSV/dataload_csv.cpp @@ -99,7 +99,7 @@ int DataLoadCSV::parseHeader(QFile *file, return linecount; } -PlotDataMap DataLoadCSV::readDataFromFile(const QString &file_name) +PlotDataMap DataLoadCSV::readDataFromFile(const QString &file_name, bool use_previous_configuration) { const int TIME_INDEX_NOT_DEFINED = -2; @@ -175,7 +175,7 @@ PlotDataMap DataLoadCSV::readDataFromFile(const QString &file_name) } } - if( time_index == TIME_INDEX_NOT_DEFINED) + if( time_index == TIME_INDEX_NOT_DEFINED && !use_previous_configuration) { QStringList field_names; field_names.push_back( "INDEX (auto-generated)" ); @@ -193,9 +193,9 @@ PlotDataMap DataLoadCSV::readDataFromFile(const QString &file_name) // vector is supposed to have only one element time_index = dialog->getSelectedRowNumber().at(0) -1; _default_time_axis = field_names.at( time_index + 1 ) ; + settings.setValue("DataLoadCSV/default_time_axis", _default_time_axis); } - settings.setValue("DataLoadCSV/default_time_axis", _default_time_axis); //----------------- while (!inB.atEnd()) diff --git a/plugins/DataLoadCSV/dataload_csv.h b/plugins/DataLoadCSV/dataload_csv.h index a1d6086b6..95508e31c 100644 --- a/plugins/DataLoadCSV/dataload_csv.h +++ b/plugins/DataLoadCSV/dataload_csv.h @@ -16,7 +16,7 @@ class DataLoadCSV: public QObject, DataLoader DataLoadCSV(); virtual const std::vector& compatibleFileExtensions() const override; - virtual PlotDataMap readDataFromFile(const QString& file_name ) override; + virtual PlotDataMap readDataFromFile(const QString& file_name, bool use_previous_configuration ) override; virtual ~DataLoadCSV(); diff --git a/plugins/ROS/DataLoadROS/dataload_ros.cpp b/plugins/ROS/DataLoadROS/dataload_ros.cpp index b6d348fe4..5a91d326e 100644 --- a/plugins/ROS/DataLoadROS/dataload_ros.cpp +++ b/plugins/ROS/DataLoadROS/dataload_ros.cpp @@ -34,7 +34,7 @@ size_t getAvailableRAM() return info.freeram; } -PlotDataMap DataLoadROS::readDataFromFile(const QString &file_name) +PlotDataMap DataLoadROS::readDataFromFile(const QString &file_name, bool use_previous_configuration) { if( _bag ) _bag->close(); @@ -88,38 +88,33 @@ PlotDataMap DataLoadROS::readDataFromFile(const QString &file_name) DialogSelectRosTopics* dialog = new DialogSelectRosTopics( all_topics, _default_topic_names ); - std::set topic_selected; - - if( dialog->exec() == static_cast(QDialog::Accepted) ) + if( !use_previous_configuration ) { - _default_topic_names.clear(); - - const auto& selected_items = dialog->getSelectedItems(); - for(const auto& item: selected_items) + if( dialog->exec() == static_cast(QDialog::Accepted) ) { - std::string ss_topic = item.toStdString(); - topic_selected.insert( ss_topic ); + _default_topic_names = dialog->getSelectedItems(); - // change the names in load_configuration - _default_topic_names.push_back( item ); - } - // load the rules - if( dialog->checkBoxUseRenamingRules()->isChecked()) - { - _rules = RuleEditing::getRenamingRules(); - } - else{ - _rules.clear(); - } - for(const auto& it: _rules) - { - RosIntrospectionFactory::parser().registerRenamingRules( ROSType(it.first) , it.second ); + // load the rules + if( dialog->checkBoxUseRenamingRules()->isChecked()) + { + _rules = RuleEditing::getRenamingRules(); + } + else{ + _rules.clear(); + } + for(const auto& it: _rules) { + RosIntrospectionFactory::parser().registerRenamingRules( ROSType(it.first) , it.second ); + } } + settings.setValue("DataLoadROS/default_topics", _default_topic_names); } - - settings.setValue("DataLoadROS/default_topics", _default_topic_names); - //----------------------------------- + std::set topic_selected; + for(const auto& topic: _default_topic_names) + { + topic_selected.insert( topic.toStdString() ); + } + QProgressDialog progress_dialog; progress_dialog.setLabelText("Loading... please wait"); progress_dialog.setWindowModality( Qt::ApplicationModal ); diff --git a/plugins/ROS/DataLoadROS/dataload_ros.h b/plugins/ROS/DataLoadROS/dataload_ros.h index b790d5dc7..856c96b64 100644 --- a/plugins/ROS/DataLoadROS/dataload_ros.h +++ b/plugins/ROS/DataLoadROS/dataload_ros.h @@ -19,7 +19,7 @@ class DataLoadROS: public QObject, DataLoader DataLoadROS(); virtual const std::vector& compatibleFileExtensions() const override; - virtual PlotDataMap readDataFromFile(const QString& file_name ) override; + virtual PlotDataMap readDataFromFile(const QString& file_name, bool use_previous_configuration ) override; virtual const char* name() const override { return "DataLoad ROS bags"; }