COIN-OR::LEMON - Graph Library

source: glemon-0.x/algowin.cc @ 173:8339178ae43d

Last change on this file since 173:8339178ae43d was 165:2cd447b0bd3a, checked in by Hegyi Péter, 14 years ago

Suurballe algorithm is implemented in glemon.

File size: 2.2 KB
Line 
1#include <algowin.h>
2#include <kruskalbox.h>
3#include <dijkstrabox.h>
4
5sigc::signal<void, AlgoWin *> AlgoWin::signal_closing()
6{
7  return signal_closed;
8}
9
10sigc::signal<void, AlgoWin *, std::string> AlgoWin::signal_maplist_needed()
11{
12  return signal_maplist_need;
13}
14
15bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e)
16{
17  if(e->keyval==GDK_Escape)
18  {
19    on_hide();
20  }
21  return true;
22}
23
24AlgoWin::AlgoWin(int algoid, std::vector<std::string> tabnames)
25{
26  signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed));
27
28  Gtk::VBox * vbox=new Gtk::VBox();
29  vbox->set_spacing(5);
30
31  Gtk::Label * label=new Gtk::Label("Select graph:");
32
33  switch(algoid)
34    {
35    case 0:
36      ab=new AlgoBox(tabnames);
37      set_title("Algo Win Demo");
38      break;
39    case 1:
40      ab=new KruskalBox(tabnames);
41      set_title("Kruskal Algorithm");
42      break;
43    case 2:
44      ab=new DijkstraBox(tabnames);
45      set_title("Dijkstra Algorithm");
46      break;
47    case 3:
48      ab=new SuurballeBox(tabnames);
49      set_title("Suurballe Algorithm");
50      break;
51    default:
52      break;
53    }
54  ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change));
55  ab->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_new_map_signal));
56
57  runbutton=new Gtk::Button("Run");
58  runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run));
59  runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run));
60
61  closebutton=new Gtk::Button("Close");
62  closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
63  closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
64     
65  Gtk::HBox * hbox=new Gtk::HBox();
66
67  hbox->pack_start(*runbutton);
68  hbox->pack_start(*closebutton);
69
70  vbox->pack_start(*label);
71  vbox->pack_start(*ab);
72  vbox->pack_start(*hbox);
73     
74  add(*vbox);
75
76  show_all_children();
77};
78
79void AlgoWin::update_tablist(std::vector<std::string> tabnames)
80{
81  ab->update_tablist(tabnames);
82}
83
84void AlgoWin::update_maplist(MapStorage * mapstorage)
85{
86  ab->update_maplist(mapstorage);
87}
88
89void AlgoWin::on_hide()
90{
91  signal_closed.emit(this);
92  Gtk::Window::on_hide();
93}
94
95void AlgoWin::emit_tab_change(std::string newtab)
96{
97  signal_maplist_need.emit(this, newtab);
98}
Note: See TracBrowser for help on using the repository browser.