Get the Play/Pause and Quit buttons working nicely
[cs356-p1-elevator.git] / main.cpp
index bcfe3b3..5ac3fe9 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,78 +1,92 @@
-#include <iostream>
-#include <list>
-#include <unistd.h>
-using namespace std;
-
-#include "stop.hpp"
-#include "position.hpp"
-#include "elevator.hpp"
-#include "elevatorcontroller.hpp"
+#include "main.hpp"
 #include "elevatorgui.hpp"
 
-#include <gtkmm/main.h>
-
+static ElevatorGUI *thegui = NULL;
 
 int main (int argc, char *argv[])
 {
-       const int floors = 7;
-       const int elevators = 3;
+       int floors = 7;
+       int elevators = 3;
+
+//#define USE_STATIC_FLOORS 1
+#ifndef USE_STATIC_FLOORS
+       do
+       {
+               std::cout << "Enter the number of floors to use [2-10]: ";
+               std::cin >> floors;
+
+               if (floors < 2 || floors > 10)
+               {
+                       std::cout << "You entered: " << floors
+                                         << " which is outside the acceptable range." << std::endl;
+                       std::cout << "Please try again..." << std::endl << std::endl;
+               }
+               else
+               {
+                       // Good input, leave now
+                       break;
+               }
+       } while (true);
+
+       do
+       {
+               std::cout << "Enter the number of elevators to use [1-5]: ";
+               std::cin >> elevators;
+
+               if (elevators < 1 || elevators > 5)
+               {
+                       std::cout << "You entered: " << elevators
+                                         << " which is outside the acceptable range." << std::endl;
+                       std::cout << "Please try again..." << std::endl << std::endl;
+               }
+               else
+               {
+                       // Good input, leave now
+                       break;
+               }
+       } while (true);
+#endif
 
        // Start GTK
        Gtk::Main app(argc, argv);
 
+       // Start the GUI
        ElevatorGUI eg(floors, elevators);
+       thegui = &eg;
+
+       // Show the GUI
        eg.show ();
 
+       // Run it!
        Gtk::Main::run (eg);
 
+       return 0;
+}
 
 
-#if TEST_ELEVATORCONTROLLER
-       const int floors = 10;
-       const int elevators = 2;
-
-       ElevatorController ec(floors, elevators);
-
-       //ec.elevator_request (0, 2);
-       ec.call_elevator_to (3, DOWN);
-
-       for (int i=0; i<35; i++)
-               ec.move_elevators ();
-
-       // Note: without the GUI, this is dependent on choosing the same elevator
-       // that was randomly chosen by the call_elevator_to() funtion.
-       //
-       // This may need to be run a few times to work :)
-       ec.elevator_request (0, 2);
-
-       for (int i=0; i<35; i++)
-               ec.move_elevators ();
-#endif
-
-
-#if TEST_ELEVATOR
-       Elevator e(2);
-
-       Stop s2(3, DOWN);
-       e.stop_at (s2);
-
-       Stop s3(1, UP);
-       e.stop_at (s3);
+void gui_update_position_label (int elevator, float new_position, Direction direction)
+{
+       thegui->gui_update_position_label (elevator, new_position, direction);
+}
 
-       Stop s4(4, DOWN);
-       e.stop_at (s4);
+void gui_unpress_call_button (int floor, Direction direction)
+{
+       thegui->gui_unpress_call_button (floor, direction);
+}
 
-       Stop s5(5, ALL);
-       e.stop_at (s5);
+void gui_unpress_request_button (int elevator, int floor)
+{
+       thegui->gui_unpress_request_button (elevator, floor);
+}
 
-       for (int i=0; i<100; ++i)
-       {
-               usleep (500000);
-               e.move ();
-       }
-#endif
+void gui_open_door (int elevator, int floor)
+{
+       thegui->gui_open_door (elevator, floor);
+}
 
-       return 0;
+void gui_close_door (int elevator, int floor)
+{
+       thegui->gui_close_door (elevator, floor);
 }
 
 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */