COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/algobox.cc @ 1884:9c061834b33b

Last change on this file since 1884:9c061834b33b was 1884:9c061834b33b, checked in by Hegyi Péter, 18 years ago

In algorithm window maps can be selected and reated through MapSelector? widget.

File size: 4.0 KB
RevLine 
[1876]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
[1878]6AlgoBox::AlgoBox(std::vector<std::string> tabnames)
[1876]7{
[1878]8  init(tabnames);
[1876]9}
10
[1878]11void AlgoBox::init(std::vector<std::string> tabnames)
[1876]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    {
[1878]52      //cbt.set_active(0);
[1876]53    }
54}
55
56void AlgoBox::update_tablist( std::vector< std::string > tl )
57{
58  update_cbt(tl, tabcbt);
59  emit_tab_change();
60}
61
[1879]62void AlgoBox::update_maplist(MapStorage * ms)
[1876]63{
[1879]64  mapstorage=ms;
[1878]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();
[1879]72      eml=mapstorage->getEdgeMapList();
[1878]73    }
[1876]74  for(int i=0;i<(int)nodemapcbts.size();i++)
75    {
[1884]76      (nodemapcbts[i])->update_list(nml);
77      //update_cbt(nml, *(nodemapcbts[i]));
[1876]78    }
79  for(int i=0;i<(int)edgemapcbts.size();i++)
80    {
[1884]81      (edgemapcbts[i])->update_list(eml);
82      //update_cbt(eml, *(edgemapcbts[i]));
[1876]83    }
84}
85
[1878]86void AlgoBox::nodemaplist_changed(std::string newmap)
87{
88  for(int i=0;i<(int)nodemapcbts.size();i++)
89    {
90      (nodemapcbts[i])->append_text(newmap);
91    }
92}
93
94void AlgoBox::edgemaplist_changed(std::string newmap)
95{
96  for(int i=0;i<(int)edgemapcbts.size();i++)
97    {
98      (edgemapcbts[i])->append_text(newmap);
99    }
100}
101
[1876]102void AlgoBox::run()
103{
104  std::cout << "Start algorithm." << std::endl;
105}
106
107void AlgoBox::build_box()
108{
109  pack_start(*(new Gtk::HSeparator()));
110
[1884]111  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
[1876]112     
113  pack_start(*label);
114  pack_start(*(new Gtk::HSeparator()));
115
116  label=new Gtk::Label("Maps in chosen tab:");
117     
118  pack_start(*label);
119
120  nodemapcbts.resize(NODE_INPUT_NUM);
121  for(int i=0;i<(int)nodemapcbts.size();i++)
122    {
[1884]123      std::vector<std::string> empty_vector;
[1876]124
125      std::ostringstream o;
126      o << "NodeInput " << i+1 << ":";
127
[1884]128      nodemapcbts[i]=new MapSelector(empty_vector,"",o.str(),false, false);
129      nodemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
[1876]130
[1884]131      pack_start(*(nodemapcbts[i]));
[1876]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    {
[1884]139      std::vector<std::string> empty_vector;
[1876]140
141      std::ostringstream o;
142      o << "EdgeInput " << i+1 << ":";
143
[1884]144      edgemapcbts[i]=new MapSelector(empty_vector,"",o.str(),true, false);
145      edgemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
[1876]146
[1884]147      pack_start(*(edgemapcbts[i]));
[1876]148    }
149
150  pack_start(*(new Gtk::HSeparator()));
151}
152
153sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
154{
155  return signal_maplist_need;
156}
157
158void AlgoBox::emit_tab_change()
159{
[1878]160  std::string active_tab=tabcbt.get_active_text();
161  if(active_tab!="")
162    {
163      signal_maplist_need.emit(active_tab);
164    }
165  else
166    {
167      std::vector<std::string> empty_vector;
168      update_maplist(NULL);
169    }
[1876]170}
[1884]171
172void AlgoBox::emit_new_map_signal(bool itisedge)
173{
174  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
175}
Note: See TracBrowser for help on using the repository browser.