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[] = { "(none)", "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);
55 if(zone.get_qualifier().empty())
56 drp_qualifier->set_selected_index(0);
60 GLtk::Row row(*layout);
61 add(*(lbl1 = new GLtk::Label("Number")));
62 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
63 unsigned n = zone.get_number();
64 add(*(ent_number = new GLtk::Entry(n ? lexical_cast<string>(zone.get_number()) : string())));
65 ent_number->set_edit_size(4, 1);
69 GLtk::Row row(*layout);
70 add(*(lbl2 = new GLtk::Label("Up towards")));
71 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
72 add(*(drp_up_direction = new GLtk::Dropdown(up_directions)));
74 up_directions.append(0);
76 Track *up = zone.get_end(TrackChain::UP).next().track();
78 drp_up_direction->set_selected_index(0);
80 for(unsigned i=0; i<2; ++i)
81 if(TrackIter iter = zone.get_end(i).next())
83 up_directions.append(iter.track());
85 drp_up_direction->set_selected_index(up_directions.size()-1);
90 GLtk::Row row(*layout);
91 add(*(lbl1 = new GLtk::Label("Direction")));
92 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
94 add(*(drp_preferred_dir = new GLtk::Dropdown));
95 GLtk::ListDataStore<string> &data = dynamic_cast<GLtk::ListDataStore<string> &>(drp_preferred_dir->get_data());
96 const char *directions[] = { "either", "up", "down", 0 };
97 for(unsigned i=0; directions[i]; ++i)
99 data.append(directions[i]);
100 if(zone.get_preferred_direction()==i)
101 drp_preferred_dir->set_selected_index(i);
108 GLtk::Row row(*layout);
110 add_button(*(btn = new GLtk::Button("Cncl")), 0);
111 btn->set_style("red");
113 add_button(*(btn = new GLtk::Button("OK")), 1);
114 btn->set_style("green");
118 void ZoneProperties::on_response(int code)
123 int sel = drp_qualifier->get_selected_index();
125 qualifier = drp_qualifier->get_data().get_string(sel);
128 string num_str = ent_number->get_text();
130 number = lexical_cast<unsigned>(ent_number->get_text());
132 zone.set_name(ent_group->get_text(), qualifier, number);
134 sel = drp_up_direction->get_selected_index();
136 zone.clear_direction();
138 zone.set_direction_towards(*up_directions.get(sel), TrackChain::UP);
140 if(zone.has_direction())
142 sel = drp_preferred_dir->get_selected_index();
143 zone.set_preferred_direction(static_cast<TrackChain::Direction>(sel));