]> git.tdb.fi Git - r2c2.git/commitdiff
Add a dialog to display telemetry data from the driver
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Feb 2015 13:44:28 +0000 (15:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Feb 2015 13:44:28 +0000 (15:44 +0200)
data/mainwindow.ui
data/telemetrydialog.ui [new file with mode: 0644]
source/engineer/mainwindow.cpp
source/engineer/mainwindow.h
source/engineer/telemetrydialog.cpp [new file with mode: 0644]
source/engineer/telemetrydialog.h [new file with mode: 0644]

index bc97b40cc04ccb081fe3ae6d500cb07c480d2bd5..b4e3a2b3be2ba9e5c3d9f7398ffbab1d788e2162 100644 (file)
@@ -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 (file)
index 0000000..a5bad4d
--- /dev/null
@@ -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";
index 7deef738a528a014d3fcc8e35521166c04a4048c..73188a207a56d935e774884de7ab8a3bd3165a4f 100644 (file)
@@ -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<GLtk::Button *>(get_item(widgets, "btn_off"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::off_clicked));
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_halt"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::halt_clicked));
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_trains"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::trains_clicked));
+       dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_telemetry"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::telemetry_clicked));
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_quit"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::quit_clicked));
        dynamic_cast<GLtk::Button *>(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<GLtk::Root>()->add(*dlg);
 }
 
+void MainWindow::telemetry_clicked()
+{
+       TelemetryDialog *dlg = new TelemetryDialog(engineer);
+       find_ancestor<GLtk::Root>()->add(*dlg);
+}
+
 void MainWindow::quit_clicked()
 {
        engineer.quit();
index d8f52083240c3fd035b354b46a48aadeb1c719fd..f707111275a40b0790b3068dbc4bcee20086e6dc 100644 (file)
@@ -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 (file)
index 0000000..bceea54
--- /dev/null
@@ -0,0 +1,53 @@
+#include <msp/gltk/column.h>
+#include <msp/gltk/row.h>
+#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<GLtk::Panel *>(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<TelemetryLabel>::iterator i=values.begin(); i!=values.end(); ++i)
+       {
+               float value = driver.get_telemetry_value(i->info->name);
+               string text = lexical_cast<string>(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 (file)
index 0000000..876ed1b
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef TELEMETRYDIALOG_H_
+#define TELEMETRYDIALOG_H_
+
+#include <msp/gltk/dialog.h>
+#include <msp/gltk/label.h>
+#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<TelemetryLabel> values;
+
+public:
+       TelemetryDialog(Engineer &);
+
+       void update();
+};
+
+#endif