1 #include <msp/core/maputils.h>
2 #include <msp/core/raii.h>
3 #include <msp/gltk/button.h>
4 #include <msp/gltk/label.h>
5 #include <msp/gltk/row.h>
6 #include "libr2c2/vehicle.h"
7 #include "controlpanel.h"
15 ControlPanel::ControlPanel(Engineer &e, Train &t):
20 Loader::WidgetMap widgets;
21 DataFile::load(*this, "data/controlpanel.ui", widgets);
23 dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_protocol"))->set_text(train.get_protocol());
24 dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_address"))->set_text(lexical_cast<string>(train.get_address()));
26 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_place"))->signal_clicked.connect(sigc::mem_fun(this, &ControlPanel::place_clicked));
27 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_take"))->signal_clicked.connect(sigc::mem_fun(this, &ControlPanel::take_clicked));
28 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_view"))->signal_clicked.connect(sigc::mem_fun(this, &ControlPanel::view_clicked));
30 GLtk::Panel *pnl_functions = dynamic_cast<GLtk::Panel *>(get_item(widgets, "pnl_functions"));
32 const VehicleType::FunctionMap &funcs = train.get_vehicle(0).get_type().get_functions();
33 GLtk::Row row(*pnl_functions->get_layout());
34 for(VehicleType::FunctionMap::const_iterator i=funcs.begin(); i!=funcs.end(); ++i)
36 GLtk::Toggle *tgl = new GLtk::Toggle(i->second);
37 tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &ControlPanel::ui_function_toggled), i->first));
38 pnl_functions->add(*tgl);
39 tgl_funcs[i->first] = tgl;
42 train.signal_function_changed.connect(sigc::mem_fun(this, &ControlPanel::train_function_changed));
45 void ControlPanel::ui_function_toggled(bool value, unsigned func)
48 train.set_function(func, value);
51 void ControlPanel::train_function_changed(unsigned func, bool value)
53 SetFlag setf(updating);
54 map<unsigned, GLtk::Toggle *>::iterator i = tgl_funcs.find(func);
55 if(i!=tgl_funcs.end())
56 i->second->set_value(value);
59 void ControlPanel::place_clicked()
61 pick_conn = engineer.signal_pick_done.connect(sigc::mem_fun(this, &ControlPanel::place_pick_done));
65 void ControlPanel::place_pick_done(Track *track, unsigned ep)
67 pick_conn.disconnect();
68 train.place(TrackIter(track, ep).block_iter());
71 void ControlPanel::take_clicked()
76 void ControlPanel::view_clicked()
78 GLtk::Container *root = parent;
79 while(root->get_parent())
80 root = root->get_parent();
82 TrainView *dlg = new TrainView(engineer, train);