BUGFIX: Elevators did not handle Requests in the correct order
[cs356-p1-elevator.git] / main.cpp
1 #include "main.hpp"
2 #include "elevatorgui.hpp"
3
4 static ElevatorGUI *thegui = NULL;
5
6 int main (int argc, char *argv[])
7 {
8         int floors = 7;
9         int elevators = 3;
10
11         // Start GTK
12         Gtk::Main app(argc, argv);
13
14 //#define USE_STATIC_FLOORS
15 #ifndef USE_STATIC_FLOORS
16         do
17         {
18                 Gtk::Dialog d ("Floor Dialog", true, true);
19                 Gtk::Label  l ("Enter the number of floors to use [2-10]");
20                 Gtk::Entry  e;
21
22                 d.get_vbox()->pack_start (l);
23                 d.get_vbox()->pack_start (e);
24                 l.show();
25                 e.show();
26                 d.add_button ("gtk-ok", Gtk::RESPONSE_OK);
27                 e.set_activates_default (true);
28                 d.set_default_response (Gtk::RESPONSE_OK);
29
30                 int result = d.run ();
31                 floors = atoi (e.get_text().c_str());
32
33                 if (floors < 2 || floors > 10)
34                 {
35                         Gtk::MessageDialog bad_dialog ("The number of floors entered was not within"
36                                                                " the acceptable range");
37                         bad_dialog.run ();
38                 }
39                 else
40                 {
41                         // Good input, leave now
42                         break;
43                 }
44         } while (true);
45
46         do
47         {
48                 Gtk::Dialog d ("Elevator Dialog", true, true);
49                 Gtk::Label  l ("Enter the number of elevators to use [1-5]");
50                 Gtk::Entry  e;
51
52                 d.get_vbox()->pack_start (l);
53                 d.get_vbox()->pack_start (e);
54                 l.show();
55                 e.show();
56                 d.add_button ("gtk-ok", Gtk::RESPONSE_OK);
57                 e.set_activates_default (true);
58                 d.set_default_response (Gtk::RESPONSE_OK);
59
60                 int result = d.run ();
61                 elevators = atoi (e.get_text().c_str());
62
63                 if (elevators < 1 || elevators > 5)
64                 {
65                         Gtk::MessageDialog bad_dialog ("The number of elevators entered was not within"
66                                                                " the acceptable range");
67                         bad_dialog.run ();
68                 }
69                 else
70                 {
71                         // Good input, leave now
72                         break;
73                 }
74         } while (true);
75 #endif
76
77         // Start the GUI
78         ElevatorGUI eg(floors, elevators);
79         thegui = &eg;
80
81         // Show the GUI
82         eg.show ();
83
84         // Run it!
85         Gtk::Main::run (eg);
86
87         return 0;
88 }
89
90
91 void gui_update_position_label (int elevator, float new_position, Direction direction)
92 {
93         thegui->gui_update_position_label (elevator, new_position, direction);
94 }
95
96 void gui_unpress_call_button (int floor, Direction direction)
97 {
98         thegui->gui_unpress_call_button (floor, direction);
99 }
100
101 void gui_unpress_request_button (int elevator, int floor)
102 {
103         thegui->gui_unpress_request_button (elevator, floor);
104 }
105
106 void gui_open_door (int elevator, int floor)
107 {
108         thegui->gui_open_door (elevator, floor);
109 }
110
111 void gui_close_door (int elevator, int floor)
112 {
113         thegui->gui_close_door (elevator, floor);
114 }
115
116 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */