| 340 |
ira |
1 |
|
|
|
2 |
#include "elevator_window.h"
|
|
|
3 |
|
|
|
4 |
Elevator_Window::Elevator_Window ()
|
|
|
5 |
: m_table (11, 8, true)
|
|
|
6 |
{
|
|
|
7 |
int i, j;
|
|
|
8 |
std::ostringstream strstrm;
|
|
|
9 |
Gtk::ToggleButton *pToggleButton;
|
|
|
10 |
Gtk::Label *pLabel;
|
|
|
11 |
Gtk::Image *pImage;
|
|
|
12 |
Button_Data bData;
|
|
|
13 |
|
|
|
14 |
// Set up all of the buttons
|
|
|
15 |
upbuttons.reserve (9);
|
|
|
16 |
downbuttons.reserve (9);
|
|
|
17 |
|
|
|
18 |
for (i=0; i<9; i++)
|
|
|
19 |
{
|
|
|
20 |
// Create an "up" button
|
|
|
21 |
strstrm.str ("");
|
|
|
22 |
strstrm << "Up"; // Button " << i;
|
|
|
23 |
pToggleButton = new Gtk::ToggleButton (strstrm.str());
|
|
|
24 |
|
|
|
25 |
bData.str = strstrm.str();
|
|
|
26 |
bData.button_num = i;
|
|
|
27 |
bData.direction = MOVE_UP;
|
|
|
28 |
bData.theButton = pToggleButton;
|
|
|
29 |
|
|
|
30 |
pToggleButton->signal_clicked ().connect (
|
|
|
31 |
sigc::bind<Button_Data> (sigc::mem_fun (*this, &Elevator_Window::on_toggle_button_pressed), bData));
|
|
|
32 |
upbuttons.push_back (pToggleButton);
|
|
|
33 |
|
|
|
34 |
// Put it in the table
|
|
|
35 |
m_table.attach (*pToggleButton, 1, 2, 10-(i+1), 10-i); //i+1, i+2);
|
|
|
36 |
|
|
|
37 |
// Create a "down" button
|
|
|
38 |
strstrm.str ("");
|
|
|
39 |
strstrm << "Down"; // Button " << i;
|
|
|
40 |
pToggleButton = new Gtk::ToggleButton (strstrm.str());
|
|
|
41 |
|
|
|
42 |
bData.str = strstrm.str();
|
|
|
43 |
bData.button_num = i;
|
|
|
44 |
bData.direction = MOVE_DOWN;
|
|
|
45 |
bData.theButton = pToggleButton;
|
|
|
46 |
|
|
|
47 |
pToggleButton->signal_clicked ().connect (
|
|
|
48 |
sigc::bind<Button_Data> (sigc::mem_fun (*this, &Elevator_Window::on_toggle_button_pressed), bData));
|
|
|
49 |
downbuttons.push_back (pToggleButton);
|
|
|
50 |
|
|
|
51 |
// Put it in the table
|
|
|
52 |
m_table.attach (*pToggleButton, 2, 3, 10-(i+2), 10-(i+1)); //i, i+1);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// Labels
|
|
|
56 |
for (i=0; i<10; i++)
|
|
|
57 |
{
|
|
|
58 |
strstrm.str ("");
|
|
|
59 |
strstrm << "Floor " << i;
|
|
|
60 |
pLabel = new Gtk::Label (strstrm.str ());
|
|
|
61 |
|
|
|
62 |
m_table.attach (*pLabel, 0, 1, 10-(i+1), 10-i);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
images.reserve (10*5);
|
|
|
66 |
|
|
|
67 |
// Images
|
|
|
68 |
for (i=0; i<10; i++)
|
|
|
69 |
{
|
|
|
70 |
for (j=3; j<8; j++)
|
|
|
71 |
{
|
|
|
72 |
pImage = new Gtk::Image ("eclose.png");
|
|
|
73 |
|
|
|
74 |
images.push_back (pImage);
|
|
|
75 |
|
|
|
76 |
m_table.attach (*pImage, j, j+1, i, i+1);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
// Bottom Row of Labels
|
|
|
81 |
pLabel = new Gtk::Label ("Position:");
|
|
|
82 |
m_table.attach (*pLabel, 2, 3, 10, 11);
|
|
|
83 |
|
|
|
84 |
labels.reserve (5);
|
|
|
85 |
|
|
|
86 |
for (i=3; i<8; i++)
|
|
|
87 |
{
|
|
|
88 |
pLabel = new Gtk::Label ("0");
|
|
|
89 |
labels.push_back (pLabel);
|
|
|
90 |
m_table.attach (*pLabel, i, i+1, 10, 11);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
set_title ("GTK Elevator Simulator");
|
|
|
94 |
|
|
|
95 |
// Set the border width of the window
|
|
|
96 |
set_border_width (10);
|
|
|
97 |
|
|
|
98 |
m_table.set_row_spacings (10);
|
|
|
99 |
m_table.set_col_spacings (10);
|
|
|
100 |
|
|
|
101 |
add (m_table);
|
|
|
102 |
|
|
|
103 |
show_all_children ();
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
Elevator_Window::~Elevator_Window ()
|
|
|
107 |
{
|
|
|
108 |
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
void Elevator_Window::on_toggle_button_pressed (Button_Data data)
|
|
|
112 |
{
|
|
|
113 |
std::string s;
|
|
|
114 |
bool active = false;
|
|
|
115 |
|
|
|
116 |
if (data.direction == MOVE_UP)
|
|
|
117 |
{
|
|
|
118 |
s = "MOVE_UP";
|
|
|
119 |
active = data.theButton->get_active ();
|
|
|
120 |
|
|
|
121 |
if (active)
|
|
|
122 |
controller->request_elevator (data.button_num, MOVE_UP);
|
|
|
123 |
}
|
|
|
124 |
else if (data.direction == MOVE_DOWN)
|
|
|
125 |
{
|
|
|
126 |
s = "MOVE_DOWN";
|
|
|
127 |
active = data.theButton->get_active ();
|
|
|
128 |
|
|
|
129 |
if (active)
|
|
|
130 |
controller->request_elevator (data.button_num+1, MOVE_DOWN);
|
|
|
131 |
}
|
|
|
132 |
else
|
|
|
133 |
s = "NOT VALID";
|
|
|
134 |
|
|
|
135 |
std::cout << "Button Pressed: number=" << data.button_num << " -- direc="
|
|
|
136 |
<< s << " -- str=" << data.str << " -- active=" << active << std::endl;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
void Elevator_Window::open_elevator_at (int row, int col)
|
|
|
140 |
{
|
|
|
141 |
assert (row >= 0);
|
|
|
142 |
assert (row < 10);
|
|
|
143 |
assert (col >= 0);
|
|
|
144 |
assert (col < 5);
|
|
|
145 |
|
|
|
146 |
const int numRows = 10;
|
|
|
147 |
const int numCols = 5;
|
|
|
148 |
|
|
|
149 |
images.at (row*numCols+col)->set ("eopen2.png");
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
void Elevator_Window::close_elevator_at (int row, int col)
|
|
|
153 |
{
|
|
|
154 |
assert (row >= 0);
|
|
|
155 |
assert (row < 10);
|
|
|
156 |
assert (col >= 0);
|
|
|
157 |
assert (col < 5);
|
|
|
158 |
|
|
|
159 |
const int numRows = 10;
|
|
|
160 |
const int numCols = 5;
|
|
|
161 |
|
|
|
162 |
images.at (row*numCols+col)->set ("eclose.png");
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
void Elevator_Window::unset_up_button (int button_num)
|
|
|
166 |
{
|
|
|
167 |
assert (button_num >= 0);
|
|
|
168 |
assert (button_num < 9);
|
|
|
169 |
|
|
|
170 |
upbuttons.at (button_num)->set_active (false);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
void Elevator_Window::unset_down_button (int button_num)
|
|
|
174 |
{
|
|
|
175 |
assert (button_num >= 0);
|
|
|
176 |
assert (button_num < 9);
|
|
|
177 |
|
|
|
178 |
downbuttons.at (button_num)->set_active (false);
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
void Elevator_Window::set_label (int label_num, std::string new_text)
|
|
|
182 |
{
|
|
|
183 |
assert (label_num >= 0);
|
|
|
184 |
assert (label_num < 5);
|
|
|
185 |
|
|
|
186 |
labels.at (label_num)->set_text (new_text);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
void Elevator_Window::set_controller (Controller *controller)
|
|
|
190 |
{
|
|
|
191 |
this->controller = controller;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
/*std::string*/ void Elevator_Window::get_floors_from_user (int elevator_num)
|
|
|
195 |
{
|
|
|
196 |
#if 0
|
|
|
197 |
int res;
|
|
|
198 |
std::cout << "GETTING FLOORS FROM USER" << std::endl;
|
|
|
199 |
|
|
|
200 |
Gtk::Dialog d ("Dialog");
|
|
|
201 |
Gtk::Entry entry;
|
|
|
202 |
|
|
|
203 |
d.get_vbox()->pack_start (entry);
|
|
|
204 |
d.add_button ("OK", 77);
|
|
|
205 |
|
|
|
206 |
res = d.run ();
|
|
|
207 |
|
|
|
208 |
std::cout << "DONE GETTING FLOORS" << std::endl;
|
|
|
209 |
#endif
|
|
|
210 |
}
|
|
|
211 |
|