diff options
Diffstat (limited to 'opentrack-logic')
-rw-r--r-- | opentrack-logic/state.hpp | 2 | ||||
-rw-r--r-- | opentrack-logic/tracklogger.hpp | 7 | ||||
-rw-r--r-- | opentrack-logic/work.cpp | 45 | ||||
-rw-r--r-- | opentrack-logic/work.hpp | 10 |
4 files changed, 51 insertions, 13 deletions
diff --git a/opentrack-logic/state.hpp b/opentrack-logic/state.hpp index bdab9afe..1c608f7a 100644 --- a/opentrack-logic/state.hpp +++ b/opentrack-logic/state.hpp @@ -14,7 +14,6 @@ using namespace options; #include "main-settings.hpp" #include "mappings.hpp" #include "selected-libraries.hpp" -#include "tracklogger.hpp" #include "work.hpp" #include <vector> #include <QString> @@ -30,5 +29,4 @@ struct State main_settings s; Mappings pose; mem<Work> work; - mem<TrackLogger> logger; }; diff --git a/opentrack-logic/tracklogger.hpp b/opentrack-logic/tracklogger.hpp index 99bc71b0..65128d48 100644 --- a/opentrack-logic/tracklogger.hpp +++ b/opentrack-logic/tracklogger.hpp @@ -14,8 +14,6 @@ public: { } - static mem<TrackLogger> make() { return std::make_shared<TrackLogger>(); } - virtual void write(const char *) { } @@ -45,12 +43,9 @@ public: first_col(true) { out.open(filename.toStdString()); - if (!out.is_open()) - throw std::ios_base::failure("unable to open file"); } - static mem<TrackLogger> make(const main_settings &s) { return std::static_pointer_cast<TrackLogger>(std::make_shared<TrackLoggerCSV>(s.tracklogging_filename)); } - + bool is_open() const { return out.is_open(); } virtual void write(const char *s); virtual void write(const double *p, int n); virtual void next_line(); diff --git a/opentrack-logic/work.cpp b/opentrack-logic/work.cpp index e5b08c18..8d00270b 100644 --- a/opentrack-logic/work.cpp +++ b/opentrack-logic/work.cpp @@ -1,9 +1,50 @@ #include "work.hpp" +#include <QMessageBox> -Work::Work(Mappings& m, SelectedLibraries& libs, TrackLogger &logger, WId handle) : + +std::shared_ptr<TrackLogger> Work::make_logger(const main_settings &s) +{ + if (s.tracklogging_enabled) + { + if (static_cast<QString>(s.tracklogging_filename).isEmpty()) + { + QMessageBox::warning(nullptr, "Logging Error", + "No filename given for track logging. Proceeding without logging.", + QMessageBox::Ok, + QMessageBox::NoButton); + } + else + { + auto logger = std::make_shared<TrackLoggerCSV>(s.tracklogging_filename); + if (!logger->is_open()) + { + logger = nullptr; + QMessageBox::warning(nullptr, "Logging Error", + "Unable to open file: " + s.tracklogging_filename + ". Proceeding without logging.", + QMessageBox::Ok, + QMessageBox::NoButton); + } + else + { + /* As this function has the potential to fill up the hard drive + of the unwary with junk data, a warning is in order. */ + QMessageBox::warning(nullptr, "Logging Active", + "Just a heads up. You are recoding pose data to " + s.tracklogging_filename + "!", + QMessageBox::Ok, + QMessageBox::NoButton); + return logger; + } + } + } + return std::make_shared<TrackLogger>(); +} + + +Work::Work(Mappings& m, SelectedLibraries& libs, WId handle) : libs(libs), - tracker(std::make_shared<Tracker>(m, libs, logger)), + logger(make_logger(s)), + tracker(std::make_shared<Tracker>(m, libs, *logger)), sc(std::make_shared<Shortcuts>()), handle(handle), keys { diff --git a/opentrack-logic/work.hpp b/opentrack-logic/work.hpp index 6425b11c..4afb1da4 100644 --- a/opentrack-logic/work.hpp +++ b/opentrack-logic/work.hpp @@ -13,6 +13,7 @@ #include "tracker.h" #include "shortcuts.h" #include "export.hpp" +#include "tracklogger.hpp" #include <QObject> #include <QFrame> @@ -25,15 +26,18 @@ struct OPENTRACK_LOGIC_EXPORT Work { using fn_t = std::function<void(bool)>; using key_tuple = std::tuple<key_opts&, fn_t, bool>; - + main_settings s; // tracker needs settings, so settings must come before it SelectedLibraries& libs; + std::shared_ptr<TrackLogger> logger; // must come before tracker, since tracker depends on it std::shared_ptr<Tracker> tracker; std::shared_ptr<Shortcuts> sc; WId handle; std::vector<key_tuple> keys; - main_settings s; - Work(Mappings& m, SelectedLibraries& libs, TrackLogger &logger, WId handle); + Work(Mappings& m, SelectedLibraries& libs, WId handle); ~Work(); void reload_shortcuts(); + +private: + std::shared_ptr<TrackLogger> make_logger(const main_settings &s); }; |