From: Mikko Rasa Date: Thu, 19 Feb 2015 13:44:28 +0000 (+0200) Subject: Add a dialog to display telemetry data from the driver X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b1cfc4fbf0d12c60bbe4b9c014a33c658554e7d7;p=r2c2.git Add a dialog to display telemetry data from the driver --- diff --git a/data/mainwindow.ui b/data/mainwindow.ui index bc97b40..b4e3a2b 100644 --- a/data/mainwindow.ui +++ b/data/mainwindow.ui @@ -65,6 +65,11 @@ column text "Trains"; }; + button "btn_telemetry" + { + text "Tmtr"; + }; + split; button "btn_quit" diff --git a/data/telemetrydialog.ui b/data/telemetrydialog.ui new file mode 100644 index 0000000..a5bad4d --- /dev/null +++ b/data/telemetrydialog.ui @@ -0,0 +1,45 @@ +layout +{ + margin + { + top 2; + horizontal 8; + bottom 6; + }; +}; + +column +{ + row + { + label "lbl_title" + { + text "Telemetry"; + }; + + split; + + action_button "btn_close" 0 + { + style "red_cross"; + }; + }; + + panel "pnl_content" + { + style "group"; + layout + { + margin + { + horizontal 0; + vertical 0; + }; + }; + }; +}; + +draghandle ""; +expand true false; +constraint COPY_HEIGHT "lbl_title"; +constraint LEFT_OF "btn_close"; diff --git a/source/engineer/mainwindow.cpp b/source/engineer/mainwindow.cpp index 7deef73..73188a2 100644 --- a/source/engineer/mainwindow.cpp +++ b/source/engineer/mainwindow.cpp @@ -5,6 +5,7 @@ #include "clockdialog.h" #include "engineer.h" #include "mainwindow.h" +#include "telemetrydialog.h" #include "trainlistdialog.h" using namespace std; @@ -26,6 +27,7 @@ MainWindow::MainWindow(Engineer &e): dynamic_cast(get_item(widgets, "btn_off"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::off_clicked)); dynamic_cast(get_item(widgets, "btn_halt"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::halt_clicked)); dynamic_cast(get_item(widgets, "btn_trains"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::trains_clicked)); + dynamic_cast(get_item(widgets, "btn_telemetry"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::telemetry_clicked)); dynamic_cast(get_item(widgets, "btn_quit"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::quit_clicked)); dynamic_cast(get_item(widgets, "btn_clock"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::clock_clicked)); @@ -68,6 +70,12 @@ void MainWindow::trains_clicked() find_ancestor()->add(*dlg); } +void MainWindow::telemetry_clicked() +{ + TelemetryDialog *dlg = new TelemetryDialog(engineer); + find_ancestor()->add(*dlg); +} + void MainWindow::quit_clicked() { engineer.quit(); diff --git a/source/engineer/mainwindow.h b/source/engineer/mainwindow.h index d8f5208..f707111 100644 --- a/source/engineer/mainwindow.h +++ b/source/engineer/mainwindow.h @@ -27,6 +27,7 @@ private: void off_clicked(); void halt_clicked(); void trains_clicked(); + void telemetry_clicked(); void quit_clicked(); void clock_clicked(); void power_event(bool); diff --git a/source/engineer/telemetrydialog.cpp b/source/engineer/telemetrydialog.cpp new file mode 100644 index 0000000..bceea54 --- /dev/null +++ b/source/engineer/telemetrydialog.cpp @@ -0,0 +1,53 @@ +#include +#include +#include "engineer.h" +#include "telemetrydialog.h" + +using namespace std; +using namespace Msp; +using namespace R2C2; + +TelemetryDialog::TelemetryDialog(Engineer &e): + DynamicDialog(e), + driver(engineer.get_layout().get_driver()) +{ + Loader::WidgetMap widgets; + DataFile::load(*this, "data/telemetrydialog.ui", widgets); + + GLtk::Panel *pnl_content = dynamic_cast(get_item(widgets, "pnl_content")); + + GLtk::Column col(*pnl_content->get_layout()); + GLtk::Widget *prev_value = 0; + for(unsigned i=0;; ++i) + { + TelemetryLabel tmlabel; + tmlabel.info = driver.enumerate_telemetry(i); + if(!tmlabel.info) + break; + + GLtk::Row row(*pnl_content->get_layout()); + + pnl_content->add(*(new GLtk::Label(tmlabel.info->label))); + pnl_content->add(*(tmlabel.label = new GLtk::Label)); + values.push_back(tmlabel); + + if(prev_value) + pnl_content->get_layout()->add_constraint(*tmlabel.label, GLtk::Layout::ALIGN_LEFT, *prev_value); + prev_value = tmlabel.label; + } +} + +void TelemetryDialog::update() +{ + for(list::iterator i=values.begin(); i!=values.end(); ++i) + { + float value = driver.get_telemetry_value(i->info->name); + string text = lexical_cast(value, Fmt().fixed().precision(i->info->precision)); + if(i->info->unit) + { + text += ' '; + text += i->info->unit; + } + i->label->set_text(text); + } +} diff --git a/source/engineer/telemetrydialog.h b/source/engineer/telemetrydialog.h new file mode 100644 index 0000000..876ed1b --- /dev/null +++ b/source/engineer/telemetrydialog.h @@ -0,0 +1,27 @@ +#ifndef TELEMETRYDIALOG_H_ +#define TELEMETRYDIALOG_H_ + +#include +#include +#include "libr2c2/driver.h" +#include "dynamicdialog.h" + +class TelemetryDialog: public DynamicDialog +{ +private: + struct TelemetryLabel + { + const R2C2::Driver::TelemetryInfo *info; + Msp::GLtk::Label *label; + }; + + R2C2::Driver &driver; + std::list values; + +public: + TelemetryDialog(Engineer &); + + void update(); +}; + +#endif