]> git.tdb.fi Git - r2c2.git/blob - source/designer/zoneproperties.cpp
Rewrite goal initialization for TrainRouteMetric
[r2c2.git] / source / designer / zoneproperties.cpp
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"
8
9 using namespace std;
10 using namespace Msp;
11 using namespace R2C2;
12
13 string track_block_name(Track *const &track)
14 {
15         if(track)
16                 return track->get_block().get_name();
17         else
18                 return "(unspecified)";
19 }
20
21 ZoneProperties::ZoneProperties(Zone &z):
22         zone(z),
23         up_directions(&track_block_name)
24 {
25         set_layout(new GLtk::Layout);
26         GLtk::Column col(*layout);
27
28         GLtk::Label *lbl1, *lbl2;
29
30         add(*(lbl1 = new GLtk::Label("Zone properties")));
31         lbl1->set_style("title");
32
33         {
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);
38         }
39
40         {
41                 GLtk::Row row(*layout);
42                 add(*(lbl2 = new GLtk::Label("Qualifier")));
43                 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
44
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)
49                 {
50                         data.append(qualifiers[i]);
51                         if(zone.get_qualifier()==qualifiers[i])
52                                 drp_qualifier->set_selected_index(i);
53                 }
54         }
55
56         {
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);
62         }
63
64         {
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)));
69
70                 up_directions.append(0);
71
72                 Track *up = zone.get_end(TrackChain::UP).next().track();
73                 if(!up)
74                         drp_up_direction->set_selected_index(0);
75
76                 for(unsigned i=0; i<2; ++i)
77                         if(TrackIter iter = zone.get_end(i).next())
78                         {
79                                 up_directions.append(iter.track());
80                                 if(iter.track()==up)
81                                         drp_up_direction->set_selected_index(up_directions.size()-1);
82                         }
83         }
84
85         GLtk::Button *btn;
86
87         {
88                 GLtk::Row row(*layout);
89                 row.split();
90                 add_button(*(btn = new GLtk::Button("Cncl")), 0);
91                 btn->set_style("red");
92
93                 add_button(*(btn = new GLtk::Button("OK")), 1);
94                 btn->set_style("green");
95         }
96 }
97
98 void ZoneProperties::on_response(int code)
99 {
100         if(code==1)
101         {
102                 string qualifier;
103                 int sel = drp_qualifier->get_selected_index();
104                 if(sel>=0)
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);
108
109                 sel = drp_up_direction->get_selected_index();
110                 if(sel==0)
111                         zone.clear_direction();
112                 else
113                         zone.set_direction_towards(*up_directions.get(sel), TrackChain::UP);
114         }
115 }