3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/gltk/label.h>
10 #include "libr2c2/tracktype.h"
11 #include "selection.h"
12 #include "trackproperties.h"
18 TrackProperties::TrackProperties(const Selection &s):
25 add(*(lbl = new GLtk::Label("Track properties")));
26 lbl->set_geometry(GLtk::Geometry(10, geom.h-30, geom.w-20, 20));
28 add(*(lbl = new GLtk::Label("Turnout ID")));
29 lbl->set_geometry(GLtk::Geometry(10, geom.h-65, 70, 20));
31 add(*(ent_turnout_id = new GLtk::Entry));
32 ent_turnout_id->set_geometry(GLtk::Geometry(80, geom.h-65, 50, 20));
34 add(*(lbl = new GLtk::Label("Sensor ID")));
35 lbl->set_geometry(GLtk::Geometry(150, geom.h-65, 70, 20));
37 add(*(ent_sensor_id = new GLtk::Entry));
38 ent_sensor_id->set_geometry(GLtk::Geometry(220, geom.h-65, 50, 20));
42 add_button(*(btn = new GLtk::Button("Cncl")), 0);
43 btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
44 btn->set_style("red");
46 add_button(*(btn = new GLtk::Button("OK")), 1);
47 btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
48 btn->set_style("green");
50 if(selection.size()==1)
52 if(unsigned tid = selection.get_track()->get_turnout_id())
53 ent_turnout_id->set_text(lexical_cast(tid));
56 const set<Track *> &tracks = selection.get_tracks();
58 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
60 if(static_cast<int>((*i)->get_sensor_id())!=sensor_id)
63 sensor_id = (*i)->get_sensor_id();
70 ent_sensor_id->set_text(lexical_cast(sensor_id));
73 void TrackProperties::on_response(int code)
77 if(selection.size()==1)
79 Track *track = selection.get_track();
80 if(track->get_type().is_turnout())
81 track->set_turnout_id(lexical_cast<unsigned>(ent_turnout_id->get_text()));
84 string sensor_id_text = ent_sensor_id->get_text();
85 if(!sensor_id_text.empty())
87 unsigned sensor_id = lexical_cast<unsigned>(sensor_id_text);
88 const set<Track *> &tracks = selection.get_tracks();
89 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
90 if(!(*i)->get_type().is_turnout())
91 (*i)->set_sensor_id(sensor_id);