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"
7 #include "objectproperties.h"
14 ObjectProperties::ObjectProperties(const Selection &selection):
18 set_layout(new GLtk::Layout);
19 GLtk::Column col(*layout);
21 GLtk::Label *lbl_title;
23 add(*(lbl_title = new GLtk::Label("Object properties")));
24 lbl_title->set_style("title");
25 layout->set_expand(*lbl_title, true, false);
27 Object *object = selection.get_object();
28 if(Track *track = dynamic_cast<Track *>(object))
30 if(track->get_type().is_turnout())
32 if(selection.size()==1)
34 lbl_title->set_text("Turnout properties");
35 properties = new TurnoutProperties(*this, *track);
40 set<Track *> tracks = selection.get_objects<Track>();
41 if(tracks.size()==selection.size())
43 bool all_linear = true;
44 for(set<Track *>::iterator i=tracks.begin(); (all_linear && i!=tracks.end()); ++i)
45 all_linear = !(*i)->get_type().is_turnout();
48 lbl_title->set_text("Track properties");
49 properties = new TrackCircuitProperties(*this, tracks);
54 else if(selection.size()==1)
56 if(Signal *signal = dynamic_cast<Signal *>(object))
58 lbl_title->set_text("Signal properties");
59 properties = new SignalProperties(*this, *signal);
61 else if(BeamGate *gate = dynamic_cast<BeamGate *>(object))
63 lbl_title->set_text("Beam gate properties");
64 properties = new BeamGateProperties(*this, *gate);
69 add(*(new GLtk::Label("No properties available")));
74 GLtk::Row row(*layout);
76 add_button(*(btn = new GLtk::Button("Cncl")), 0);
77 btn->set_style("red");
79 add_button(*(btn = new GLtk::Button("OK")), 1);
80 btn->set_style("green");
84 GLtk::Entry *ObjectProperties::add_property(const string &label, const string &value, unsigned size)
86 GLtk::Row row(*layout);
87 add(*(new GLtk::Label(label)));
89 GLtk::Entry *entry = new GLtk::Entry(value);
92 entry->set_edit_size(size, 1);
95 layout->add_constraint(*entry, GLtk::Layout::ALIGN_LEFT, *prev_widget);
101 void ObjectProperties::on_response(int code)
103 if(code==1 && properties)
108 ObjectProperties::TurnoutProperties::TurnoutProperties(ObjectProperties &p, Track &t):
110 ent_address(p.add_property("Turnout address", lexical_cast<string>(track.get_turnout_address()), 5))
113 void ObjectProperties::TurnoutProperties::apply()
115 track.set_turnout_address(lexical_cast<unsigned>(ent_address->get_text()));
119 ObjectProperties::TrackCircuitProperties::TrackCircuitProperties(ObjectProperties &p, const set<Track *> &t):
121 ent_address(p.add_property("Sensor address", string(), 5))
124 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
126 int a = (*i)->get_sensor_address();
137 ent_address->set_text(lexical_cast<string>(addr));
140 void ObjectProperties::TrackCircuitProperties::apply()
142 const string &text = ent_address->get_text();
145 unsigned addr = lexical_cast<unsigned>(text);
146 for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
147 (*i)->set_sensor_address(addr);
152 ObjectProperties::SignalProperties::SignalProperties(ObjectProperties &p, Signal &s):
154 ent_address(p.add_property("Signal address", lexical_cast<string>(signal.get_address()), 5))
157 void ObjectProperties::SignalProperties::apply()
159 signal.set_address(lexical_cast<unsigned>(ent_address->get_text()));
163 ObjectProperties::BeamGateProperties::BeamGateProperties(ObjectProperties &p, BeamGate &g):
165 ent_address(p.add_property("Sensor address", lexical_cast<string>(gate.get_address()), 5))
168 void ObjectProperties::BeamGateProperties::apply()
170 gate.set_address(lexical_cast<unsigned>(ent_address->get_text()));