From e90a477d2624726180ab3932a4e5e5a9619957e2 Mon Sep 17 00:00:00 2001 From: Markus Grotz <markus.grotz@kit.edu> Date: Thu, 1 Dec 2016 17:59:23 +0100 Subject: [PATCH] Plotter now uses the filename specified by the TopicReplayer --- .../ArmarXPlotter/ArmarXPlotter.cpp | 29 +++++++++++++++---- .../ArmarXPlotter/ArmarXPlotter.h | 4 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp index 313217468..5c43f0c87 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp @@ -53,6 +53,7 @@ #include <QTextEdit> #include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/filesystem/path.hpp> #include <IceUtil/IceUtil.h> @@ -242,16 +243,31 @@ namespace armarx if (toggled) { - std::string filename = "datalog-" + IceUtil::Time::now().toDateTime() + ".csv"; - boost::replace_all(filename, "/", "-"); - filename = loggingDir.toStdString() + "/" + filename; - ARMARX_INFO << "Logging to " << filename; - logstream.open(filename); + boost::filesystem::path outputPath; + if (filename.empty()) + { + outputPath = loggingDir.toStdString() + "/datalog.csv"; + + std::string time = IceUtil::Time::now().toDateTime(); + boost::replace_all(time, "/", "-"); + boost::replace_all(time, " ", "_"); + boost::replace_all(time, ":", "-"); + outputPath = outputPath.parent_path() / (outputPath.stem().string() + "-" + time + outputPath.extension().string()); + + } + else + { + boost::filesystem::path path = filename; + outputPath = loggingDir.toStdString() + "/" + path.stem().string() + ".csv"; + } + + ARMARX_INFO << "Logging to " << outputPath.string(); + logstream.open(outputPath.string()); logStartTime = IceUtil::Time::now(); if (!logstream.is_open()) { - ARMARX_ERROR << "Could not open file for logging: " << filename; + ARMARX_ERROR << "Could not open file for logging: " << outputPath.string(); ui.btnLogToFile->setChecked(false); } else @@ -268,6 +284,7 @@ namespace armarx } else { + filename = ""; logstream.flush(); ARMARX_INFO << "done writing log"; logstream.close(); diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h index 29790655f..2313c9699 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h @@ -88,7 +88,7 @@ namespace armarx public: - void onStartReplay(const Ice::Current& c = Ice::Current()) + void onStartReplay(const std::string& filename, const Ice::Current& c = Ice::Current()) { if (!syncDataLogging) { @@ -97,6 +97,7 @@ namespace armarx if (!ui.btnLogToFile->isChecked()) { + this->filename = filename; ui.btnLogToFile->setChecked(true); } else @@ -200,6 +201,7 @@ namespace armarx int pollingInterval = 33; std::ofstream logstream; IceUtil::Time logStartTime; + std::string filename = ""; int graphStyle; std::map<std::string, std::map<IceUtil::Time, std::map<std::string, boost::shared_ptr<QwtPlotMarker>>>> markers; -- GitLab