COIN-OR::LEMON - Graph Library

source: glemon-0.x/algowin.cc @ 164:70e3c3646283

Last change on this file since 164:70e3c3646283 was 162:aaa517c9dc23, checked in by Hegyi Péter, 15 years ago

Dijkstra in GUI.

File size: 2.1 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    default:
48      break;
49    }
50  ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change));
51  ab->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_new_map_signal));
52
53  runbutton=new Gtk::Button("Run");
54  runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run));
55  runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run));
56
57  closebutton=new Gtk::Button("Close");
58  closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
59  closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
60     
61  Gtk::HBox * hbox=new Gtk::HBox();
62
63  hbox->pack_start(*runbutton);
64  hbox->pack_start(*closebutton);
65
66  vbox->pack_start(*label);
67  vbox->pack_start(*ab);
68  vbox->pack_start(*hbox);
69     
70  add(*vbox);
71
72  show_all_children();
73};
74
75void AlgoWin::update_tablist(std::vector<std::string> tabnames)
76{
77  ab->update_tablist(tabnames);
78}
79
80void AlgoWin::update_maplist(MapStorage * mapstorage)
81{
82  ab->update_maplist(mapstorage);
83}
84
85void AlgoWin::on_hide()
86{
87  signal_closed.emit(this);
88  Gtk::Window::on_hide();
89}
90
91void AlgoWin::emit_tab_change(std::string newtab)
92{
93  signal_maplist_need.emit(this, newtab);
94}
Note: See TracBrowser for help on using the repository browser.