Get ready to add the calls into the GUI into Elevator
authorIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 04:07:31 +0000 (21:07 -0700)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 7 Oct 2007 04:07:31 +0000 (21:07 -0700)
Clean up so that I can add the calls into the GUI in the Elevator class.

Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
main.cpp

index bcfe3b3..9b2d2e0 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,77 +1,64 @@
-#include <iostream>
-#include <list>
-#include <unistd.h>
-using namespace std;
-
-#include "stop.hpp"
-#include "position.hpp"
-#include "elevator.hpp"
-#include "elevatorcontroller.hpp"
-#include "elevatorgui.hpp"
-
-#include <gtkmm/main.h>
+#include "main.hpp"
 
+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);
 
-
-
-#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);
-
-       Stop s4(4, DOWN);
-       e.stop_at (s4);
-
-       Stop s5(5, ALL);
-       e.stop_at (s5);
-
-       for (int i=0; i<100; ++i)
-       {
-               usleep (500000);
-               e.move ();
-       }
-#endif
-
        return 0;
 }