Rev 344 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "elevator_window.h"Elevator_Window::Elevator_Window (): m_table (11, 8, true){int i, j;std::ostringstream strstrm;Gtk::ToggleButton *pToggleButton;Gtk::Label *pLabel;Gtk::Image *pImage;Button_Data bData;// Set up all of the buttonsupbuttons.reserve (9);downbuttons.reserve (9);for (i=0; i<9; i++){// Create an "up" buttonstrstrm.str ("");strstrm << "Up"; // Button " << i;pToggleButton = new Gtk::ToggleButton (strstrm.str());bData.str = strstrm.str();bData.button_num = i;bData.direction = MOVE_UP;bData.theButton = pToggleButton;pToggleButton->signal_clicked ().connect (sigc::bind<Button_Data> (sigc::mem_fun (*this, &Elevator_Window::on_toggle_button_pressed), bData));upbuttons.push_back (pToggleButton);// Put it in the tablem_table.attach (*pToggleButton, 1, 2, 10-(i+1), 10-i); //i+1, i+2);// Create a "down" buttonstrstrm.str ("");strstrm << "Down"; // Button " << i;pToggleButton = new Gtk::ToggleButton (strstrm.str());bData.str = strstrm.str();bData.button_num = i;bData.direction = MOVE_DOWN;bData.theButton = pToggleButton;pToggleButton->signal_clicked ().connect (sigc::bind<Button_Data> (sigc::mem_fun (*this, &Elevator_Window::on_toggle_button_pressed), bData));downbuttons.push_back (pToggleButton);// Put it in the tablem_table.attach (*pToggleButton, 2, 3, 10-(i+2), 10-(i+1)); //i, i+1);}// Labelsfor (i=0; i<10; i++){strstrm.str ("");strstrm << "Floor " << i;pLabel = new Gtk::Label (strstrm.str ());m_table.attach (*pLabel, 0, 1, 10-(i+1), 10-i);}images.reserve (10*5);// Imagesfor (i=0; i<10; i++){for (j=3; j<8; j++){pImage = new Gtk::Image ("eclose.png");images.push_back (pImage);m_table.attach (*pImage, j, j+1, i, i+1);}}// Bottom Row of LabelspLabel = new Gtk::Label ("Position:");m_table.attach (*pLabel, 2, 3, 10, 11);labels.reserve (5);for (i=3; i<8; i++){pLabel = new Gtk::Label ("0");labels.push_back (pLabel);m_table.attach (*pLabel, i, i+1, 10, 11);}set_title ("GTK Elevator Simulator");// Set the border width of the windowset_border_width (10);m_table.set_row_spacings (10);m_table.set_col_spacings (10);add (m_table);show_all_children ();}Elevator_Window::~Elevator_Window (){}void Elevator_Window::on_toggle_button_pressed (Button_Data data){std::string s;bool active = false;if (data.direction == MOVE_UP){s = "MOVE_UP";active = data.theButton->get_active ();if (active)controller->request_elevator (data.button_num, MOVE_UP);}else if (data.direction == MOVE_DOWN){s = "MOVE_DOWN";active = data.theButton->get_active ();if (active)controller->request_elevator (data.button_num+1, MOVE_DOWN);}elses = "NOT VALID";std::cout << "Button Pressed: number=" << data.button_num << " -- direc="<< s << " -- str=" << data.str << " -- active=" << active << std::endl;}void Elevator_Window::open_elevator_at (int row, int col){assert (row >= 0);assert (row < 10);assert (col >= 0);assert (col < 5);const int numRows = 10;const int numCols = 5;images.at (row*numCols+col)->set ("eopen2.png");}void Elevator_Window::close_elevator_at (int row, int col){assert (row >= 0);assert (row < 10);assert (col >= 0);assert (col < 5);const int numRows = 10;const int numCols = 5;images.at (row*numCols+col)->set ("eclose.png");}void Elevator_Window::unset_up_button (int button_num){assert (button_num >= 0);assert (button_num < 9);upbuttons.at (button_num)->set_active (false);}void Elevator_Window::unset_down_button (int button_num){assert (button_num >= 0);assert (button_num < 9);downbuttons.at (button_num)->set_active (false);}void Elevator_Window::set_label (int label_num, std::string new_text){assert (label_num >= 0);assert (label_num < 5);labels.at (label_num)->set_text (new_text);}void Elevator_Window::set_controller (Controller *controller){this->controller = controller;}/*std::string*/ void Elevator_Window::get_floors_from_user (int elevator_num){#if 0int res;std::cout << "GETTING FLOORS FROM USER" << std::endl;Gtk::Dialog d ("Dialog");Gtk::Entry entry;d.get_vbox()->pack_start (entry);d.add_button ("OK", 77);res = d.run ();std::cout << "DONE GETTING FLOORS" << std::endl;#endif}