summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorDaMichel <mw.pub@welter-4d.de>2016-07-29 11:12:22 +0200
committerDaMichel <mw.pub@welter-4d.de>2016-07-29 11:38:21 +0200
commit7b3be452b6be528de753a1a633a3aacdb11be86c (patch)
tree63df2693909a92529610a055e2f670d5860cedf8 /gui
parent2bae0bce582f05259f64fb13b364fe6dbd28817a (diff)
new track logging: record poses in various stages of processing into a file
Diffstat (limited to 'gui')
-rw-r--r--gui/options-dialog.cpp21
-rw-r--r--gui/options-dialog.hpp3
-rw-r--r--gui/settings.ui82
-rw-r--r--gui/ui.cpp61
-rw-r--r--gui/ui.h3
5 files changed, 168 insertions, 2 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp
index 3b54ae9a..8987ba34 100644
--- a/gui/options-dialog.cpp
+++ b/gui/options-dialog.cpp
@@ -11,6 +11,7 @@
#include <QPushButton>
#include <QLayout>
#include <QDialog>
+#include <QFileDialog>
static QString kopts_to_string(const key_opts& kopts)
{
@@ -72,6 +73,9 @@ OptionsDialog::OptionsDialog(std::function<void(bool)> pause_keybindings) :
tie_setting(main.center_method, ui.center_method);
+ tie_setting(main.tracklogging_enabled, ui.tracklogging_enabled);
+ tie_setting(main.tracklogging_filename, ui.tracklogging_filenameedit);
+
struct tmp
{
key_opts& opt;
@@ -102,6 +106,8 @@ OptionsDialog::OptionsDialog(std::function<void(bool)> pause_keybindings) :
connect(val.button, &QPushButton::pressed, this, [=]() -> void { bind_key(val.opt, val.label); });
}
}
+
+ connect(ui.tracklogging_fileselectbtn, SIGNAL(clicked()), this, SLOT(browse_datalogging_file()));
}
void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
@@ -163,3 +169,18 @@ void OptionsDialog::doCancel()
close();
}
+void OptionsDialog::browse_datalogging_file()
+{
+ QString filename = ui.tracklogging_filenameedit->text();
+ if (filename.isEmpty())
+ filename = QDir::currentPath();
+ QString newfilename = QFileDialog::getSaveFileName(this, tr("Select Filename"), filename, tr("CSV File (*.csv)"));
+ if (!newfilename.isEmpty())
+ ui.tracklogging_filenameedit->setText(newfilename);
+}
+
+void OptionsDialog::update_widgets_states(bool tracker_is_running)
+{
+ ui.tracklogging_enabled->setEnabled(!tracker_is_running);
+ ui.tracklogging_fileselectbtn->setEnabled(!tracker_is_running);
+} \ No newline at end of file
diff --git a/gui/options-dialog.hpp b/gui/options-dialog.hpp
index 66386a79..f84ee8f6 100644
--- a/gui/options-dialog.hpp
+++ b/gui/options-dialog.hpp
@@ -13,6 +13,8 @@ signals:
void saving();
public:
OptionsDialog(std::function<void(bool)> pause_keybindings);
+public slots:
+ void update_widgets_states(bool tracker_is_running);
private:
main_settings main;
std::function<void(bool)> pause_keybindings;
@@ -22,4 +24,5 @@ private slots:
void doOK();
void doCancel();
void bind_key(key_opts &kopts, QLabel* label);
+ void browse_datalogging_file();
};
diff --git a/gui/settings.ui b/gui/settings.ui
index 4654dd85..9c573da2 100644
--- a/gui/settings.ui
+++ b/gui/settings.ui
@@ -33,7 +33,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>2</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -1205,6 +1205,86 @@
</widget>
</item>
<item>
+ <widget class="QGroupBox" name="groupBox_10">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Data Logging</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="tracklogging_label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Record pose data in a csv file. WARNING: overwrites file contents without warning every time the tracker is started.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="tracklogging_enabled">
+ <property name="text">
+ <string>Enable</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="tracklogging_fileselectbtn">
+ <property name="text">
+ <string>Select File ...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="tracklogging_filenameedit">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
+ <property name="inputMask">
+ <string notr="true"/>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/gui/ui.cpp b/gui/ui.cpp
index 85d5d029..3bda6ee2 100644
--- a/gui/ui.cpp
+++ b/gui/ui.cpp
@@ -15,6 +15,7 @@
#include <QFileDialog>
#include <QDesktopServices>
#include <QCoreApplication>
+#include <cassert>
#ifdef _WIN32
# include <windows.h>
@@ -285,6 +286,45 @@ void MainWindow::reload_options()
ensure_tray();
}
+/*
+ Allocates a new logger instance depending on main settings. Result is assigned to logger variable of State object.
+ May open warning dialogs.
+ May also assign nullptr in case of an error.
+*/
+void MainWindow::initialize_logger()
+{
+ logger = nullptr;
+ if (s.tracklogging_enabled)
+ {
+ if (static_cast<QString>(s.tracklogging_filename).isEmpty())
+ {
+ QMessageBox::warning(this, tr("Logging Error"),
+ tr("No filename given for track logging. Aborting."),
+ QMessageBox::Ok,
+ QMessageBox::NoButton);
+ return;
+ }
+ try
+ {
+ logger = TrackLoggerCSV::make(s);
+ }
+ catch (std::ios_base::failure &)
+ {
+ QMessageBox::warning(this, tr("Logging Error"),
+ tr("Unable to open file: ") + s.tracklogging_filename + tr(". Aborting."),
+ QMessageBox::Ok,
+ QMessageBox::NoButton);
+ return;
+ }
+ }
+ else
+ {
+ logger = TrackLogger::make();
+ }
+ assert(logger != nullptr);
+}
+
+
void MainWindow::startTracker()
{
if (work)
@@ -310,9 +350,17 @@ void MainWindow::startTracker()
return;
}
+ initialize_logger();
+ if (logger == nullptr)
+ {
+ // error -> rollback
+ libs = SelectedLibraries();
+ return;
+ }
+
save_modules();
- work = std::make_shared<Work>(pose, libs, winId());
+ work = std::make_shared<Work>(pose, libs, *logger, winId());
reload_options();
@@ -331,6 +379,12 @@ void MainWindow::startTracker()
// trackers take care of layout state updates
const bool is_inertial = ui.video_frame->layout() == nullptr;
updateButtonState(true, is_inertial);
+
+ // Update the state of the options window directly.
+ // Might be better to emit signals and allow the options window
+ // to connect its slots to them (?)
+ if (options_widget)
+ options_widget->update_widgets_states(true);
ui.btnStopTracker->setFocus();
}
@@ -358,12 +412,16 @@ void MainWindow::stopTracker()
work = nullptr;
libs = SelectedLibraries();
+ logger = nullptr;
{
double p[6] = {0,0,0, 0,0,0};
display_pose(p, p);
}
updateButtonState(false, false);
+
+ if (options_widget)
+ options_widget->update_widgets_states(false);
set_title();
@@ -495,6 +553,7 @@ void MainWindow::show_options_dialog()
if (mk_window(&options_widget, [&](bool flag) -> void { set_keys_enabled(!flag); }))
{
connect(options_widget.get(), &OptionsDialog::saving, this, &MainWindow::reload_options);
+ options_widget->update_widgets_states(work != nullptr);
}
}
diff --git a/gui/ui.h b/gui/ui.h
index 7415d3d4..acec615e 100644
--- a/gui/ui.h
+++ b/gui/ui.h
@@ -102,6 +102,9 @@ private slots:
void startTracker();
void stopTracker();
void reload_options();
+
+ void initialize_logger();
+
signals:
void emit_start_tracker();
void emit_stop_tracker();