COIN-OR::LEMON - Graph Library

source: glemon-0.x/algobox.cc @ 109:9f8dc346ac6e

gui
Last change on this file since 109:9f8dc346ac6e was 109:9f8dc346ac6e, checked in by Hegyi Péter, 14 years ago

Kruskal algorithm can be run from GUI from now on.

File size: 3.7 KB
Line 
1#include <algobox.h>
2
3enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
4enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
5
6AlgoBox::AlgoBox(std::vector<std::string> tabnames)
7{
8  init(tabnames);
9}
10
11void AlgoBox::init(std::vector<std::string> tabnames)
12{
13  set_spacing(5);
14
15  update_tablist(tabnames);
16
17  //if active tab is changed, the map names in cbt/s have to be updated
18  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
19
20  pack_start(tabcbt);
21  build_box();
22
23  show_all_children();
24};
25
26void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
27{
28  std::string actname=cbt.get_active_text();
29  int prev_act=-1;
30
31  cbt.clear();
32  int actptr=0;
33
34  std::vector< std::string >::iterator emsi=stringlist.begin();
35  for(;emsi!=stringlist.end();emsi++)
36    {
37      if(actname==*emsi)
38        {
39          prev_act=actptr;
40        }
41
42      cbt.append_text(*emsi);
43      actptr++;
44    }
45
46  if(prev_act!=-1)
47    {
48      cbt.set_active(prev_act);
49    }
50  else if(actptr>0) //so there is item in the list
51    {
52      //cbt.set_active(0);
53    }
54}
55
56void AlgoBox::update_tablist( std::vector< std::string > tl )
57{
58  update_cbt(tl, tabcbt);
59  emit_tab_change();
60}
61
62void AlgoBox::update_maplist(MapStorage * ms)
63{
64  mapstorage=ms;
65  std::vector<std::string> nml;
66  std::vector<std::string> eml;
67  if(mapstorage!=NULL)
68    {
69      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
70      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
71      nml=mapstorage->getNodeMapList();
72      eml=mapstorage->getEdgeMapList();
73    }
74  for(int i=0;i<(int)nodemapcbts.size();i++)
75    {
76      update_cbt(nml, *(nodemapcbts[i]));
77    }
78  for(int i=0;i<(int)edgemapcbts.size();i++)
79    {
80      update_cbt(eml, *(edgemapcbts[i]));
81    }
82}
83
84void AlgoBox::nodemaplist_changed(std::string newmap)
85{
86  for(int i=0;i<(int)nodemapcbts.size();i++)
87    {
88      (nodemapcbts[i])->append_text(newmap);
89    }
90}
91
92void AlgoBox::edgemaplist_changed(std::string newmap)
93{
94  for(int i=0;i<(int)edgemapcbts.size();i++)
95    {
96      (edgemapcbts[i])->append_text(newmap);
97    }
98}
99
100void AlgoBox::run()
101{
102  std::cout << "Start algorithm." << std::endl;
103}
104
105void AlgoBox::build_box()
106{
107  pack_start(*(new Gtk::HSeparator()));
108
109  label=new Gtk::Label("Specific part for each algorithm.");
110     
111  pack_start(*label);
112  pack_start(*(new Gtk::HSeparator()));
113
114  label=new Gtk::Label("Maps in chosen tab:");
115     
116  pack_start(*label);
117
118  nodemapcbts.resize(NODE_INPUT_NUM);
119  for(int i=0;i<(int)nodemapcbts.size();i++)
120    {
121      Gtk::HBox * hbox=new Gtk::HBox();
122
123      std::ostringstream o;
124      o << "NodeInput " << i+1 << ":";
125      label=new Gtk::Label(o.str());
126
127      nodemapcbts[i]=new Gtk::ComboBoxText();
128
129      hbox->pack_start(*label);
130      hbox->pack_start(*(nodemapcbts[i]));
131      pack_start(*hbox);
132    }
133
134  pack_start(*(new Gtk::HSeparator()));
135
136  edgemapcbts.resize(EDGE_INPUT_NUM);
137  for(int i=0;i<(int)edgemapcbts.size();i++)
138    {
139      Gtk::HBox * hbox=new Gtk::HBox();
140
141      std::ostringstream o;
142      o << "EdgeInput " << i+1 << ":";
143      label=new Gtk::Label(o.str());
144
145      edgemapcbts[i]=new Gtk::ComboBoxText();
146
147      hbox->pack_start(*label);
148      hbox->pack_start(*(edgemapcbts[i]));
149      pack_start(*hbox);
150    }
151
152  pack_start(*(new Gtk::HSeparator()));
153}
154
155sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
156{
157  return signal_maplist_need;
158}
159
160void AlgoBox::emit_tab_change()
161{
162  std::string active_tab=tabcbt.get_active_text();
163  if(active_tab!="")
164    {
165      signal_maplist_need.emit(active_tab);
166    }
167  else
168    {
169      std::vector<std::string> empty_vector;
170      update_maplist(NULL);
171    }
172}
Note: See TracBrowser for help on using the repository browser.