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/block.h"
6 #include "libr2c2/track.h"
7 #include "zoneproperties.h"
13 string track_block_name(Track *const &track)
16 return track->get_block().get_name();
18 return "(unspecified)";
21 ZoneProperties::ZoneProperties(Zone &z):
23 up_directions(&track_block_name)
25 set_layout(new GLtk::Layout);
26 GLtk::Column col(*layout);
28 GLtk::Label *lbl1, *lbl2;
30 add(*(lbl1 = new GLtk::Label("Zone properties")));
31 lbl1->set_style("title");
34 GLtk::Row row(*layout);
35 add(*(lbl1 = new GLtk::Label("Group")));
36 add(*(ent_group = new GLtk::Entry(zone.get_group())));
37 ent_group->set_edit_size(30, 1);
41 GLtk::Row row(*layout);
42 add(*(lbl2 = new GLtk::Label("Qualifier")));
43 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
45 add(*(drp_qualifier = new GLtk::Dropdown));
46 GLtk::ListDataStore<string> &data = dynamic_cast<GLtk::ListDataStore<string> &>(drp_qualifier->get_data());
47 const char *qualifiers[] = { "track", "platform", "siding", 0 };
48 for(unsigned i=0; qualifiers[i]; ++i)
50 data.append(qualifiers[i]);
51 if(zone.get_qualifier()==qualifiers[i])
52 drp_qualifier->set_selected_index(i);
57 GLtk::Row row(*layout);
58 add(*(lbl1 = new GLtk::Label("Number")));
59 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
60 add(*(ent_number = new GLtk::Entry(lexical_cast<string>(zone.get_number()))));
61 ent_number->set_edit_size(4, 1);
65 GLtk::Row row(*layout);
66 add(*(lbl2 = new GLtk::Label("Up towards")));
67 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
68 add(*(drp_up_direction = new GLtk::Dropdown(up_directions)));
70 up_directions.append(0);
72 Track *up = zone.get_end(TrackChain::UP).next().track();
74 drp_up_direction->set_selected_index(0);
76 for(unsigned i=0; i<2; ++i)
77 if(TrackIter iter = zone.get_end(i).next())
79 up_directions.append(iter.track());
81 drp_up_direction->set_selected_index(up_directions.size()-1);
88 GLtk::Row row(*layout);
90 add_button(*(btn = new GLtk::Button("Cncl")), 0);
91 btn->set_style("red");
93 add_button(*(btn = new GLtk::Button("OK")), 1);
94 btn->set_style("green");
98 void ZoneProperties::on_response(int code)
103 int sel = drp_qualifier->get_selected_index();
105 qualifier = drp_qualifier->get_data().get_string(sel);
106 unsigned number = lexical_cast<unsigned>(ent_number->get_text());
107 zone.set_name(ent_group->get_text(), qualifier, number);
109 sel = drp_up_direction->get_selected_index();
111 zone.clear_direction();
113 zone.set_direction_towards(*up_directions.get(sel), TrackChain::UP);