text "Trains";
};
+ button "btn_telemetry"
+ {
+ text "Tmtr";
+ };
+
split;
button "btn_quit"
--- /dev/null
+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";
#include "clockdialog.h"
#include "engineer.h"
#include "mainwindow.h"
+#include "telemetrydialog.h"
#include "trainlistdialog.h"
using namespace std;
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));
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();
void off_clicked();
void halt_clicked();
void trains_clicked();
+ void telemetry_clicked();
void quit_clicked();
void clock_clicked();
void power_event(bool);
--- /dev/null
+#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);
+ }
+}
--- /dev/null
+#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