1 #include <msp/gltk/button.h>
2 #include <msp/gltk/column.h>
3 #include <msp/gltk/label.h>
4 #include <msp/gltk/row.h>
5 #include "libr2c2/track.h"
6 #include "libr2c2/tracktype.h"
8 #include "trackproperties.h"
14 TrackProperties::TrackProperties(const Selection &s):
17 set_layout(new GLtk::Layout);
18 GLtk::Column col(*layout);
20 GLtk::Label *lbl1, *lbl2;
22 add(*(lbl1 = new GLtk::Label("Track properties")));
23 lbl1->set_style("title");
26 GLtk::Row row(*layout);
27 add(*(lbl1 = new GLtk::Label("Turnout ID")));
28 add(*(ent_turnout_id = new GLtk::Entry));
29 ent_turnout_id->set_edit_size(5, 1);
33 GLtk::Row row(*layout);
34 add(*(lbl2 = new GLtk::Label("Sensor ID")));
35 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
36 add(*(ent_sensor_id = new GLtk::Entry));
37 ent_sensor_id->set_edit_size(5, 1);
43 GLtk::Row row(*layout);
45 add_button(*(btn = new GLtk::Button("Cncl")), 0);
46 btn->set_style("red");
48 add_button(*(btn = new GLtk::Button("OK")), 1);
49 btn->set_style("green");
52 if(selection.size()==1)
54 if(unsigned tid = selection.get_object<Track>()->get_turnout_id())
55 ent_turnout_id->set_text(lexical_cast<string>(tid));
58 const set<Track *> &tracks = selection.get_objects<Track>();
60 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
62 if(static_cast<int>((*i)->get_sensor_id())!=sensor_id)
65 sensor_id = (*i)->get_sensor_id();
72 ent_sensor_id->set_text(lexical_cast<string>(sensor_id));
75 void TrackProperties::on_response(int code)
79 if(selection.size()==1)
81 Track *track = selection.get_object<Track>();
82 if(track->get_type().is_turnout())
83 track->set_turnout_id(lexical_cast<unsigned>(ent_turnout_id->get_text()));
86 string sensor_id_text = ent_sensor_id->get_text();
87 if(!sensor_id_text.empty())
89 unsigned sensor_id = lexical_cast<unsigned>(sensor_id_text);
90 const set<Track *> &tracks = selection.get_objects<Track>();
91 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
92 if(!(*i)->get_type().is_turnout())
93 (*i)->set_sensor_id(sensor_id);