COIN-OR::LEMON - Graph Library

source: glemon-0.x/algobox.cc @ 107:b1be10a9a2b6

gui
Last change on this file since 107:b1be10a9a2b6 was 106:853dd852abc7, checked in by Hegyi Péter, 18 years ago

Communication with algorithm window is developed.

File size: 3.1 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, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
7{
8  init(tabnames, nodemapnames, edgemapnames);
9}
10
11void AlgoBox::init(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
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
22  build_box();
23
24  update_maplist(nodemapnames, edgemapnames);
25
26  show_all_children();
27};
28
29void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
30{
31  std::string actname=cbt.get_active_text();
32  int prev_act=-1;
33
34  cbt.clear();
35  int actptr=0;
36
37  std::vector< std::string >::iterator emsi=stringlist.begin();
38  for(;emsi!=stringlist.end();emsi++)
39    {
40      if(actname==*emsi)
41        {
42          prev_act=actptr;
43        }
44
45      cbt.append_text(*emsi);
46      actptr++;
47    }
48
49  if(prev_act!=-1)
50    {
51      cbt.set_active(prev_act);
52    }
53  else if(actptr>0) //so there is item in the list
54    {
55      cbt.set_active(0);
56    }
57}
58
59void AlgoBox::update_tablist( std::vector< std::string > tl )
60{
61  update_cbt(tl, tabcbt);
62  emit_tab_change();
63}
64
65void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml )
66{
67  for(int i=0;i<(int)nodemapcbts.size();i++)
68    {
69      update_cbt(nml, *(nodemapcbts[i]));
70    }
71  for(int i=0;i<(int)edgemapcbts.size();i++)
72    {
73      update_cbt(eml, *(edgemapcbts[i]));
74    }
75}
76
77void AlgoBox::run()
78{
79  std::cout << "Start algorithm." << std::endl;
80}
81
82void AlgoBox::build_box()
83{
84  pack_start(*(new Gtk::HSeparator()));
85
86  label=new Gtk::Label("Specific part for each algorithm.");
87     
88  pack_start(*label);
89  pack_start(*(new Gtk::HSeparator()));
90
91  label=new Gtk::Label("Maps in chosen tab:");
92     
93  pack_start(*label);
94
95  nodemapcbts.resize(NODE_INPUT_NUM);
96  for(int i=0;i<(int)nodemapcbts.size();i++)
97    {
98      Gtk::HBox * hbox=new Gtk::HBox();
99
100      std::ostringstream o;
101      o << "NodeInput " << i+1 << ":";
102      label=new Gtk::Label(o.str());
103
104      nodemapcbts[i]=new Gtk::ComboBoxText();
105
106      hbox->pack_start(*label);
107      hbox->pack_start(*(nodemapcbts[i]));
108      pack_start(*hbox);
109    }
110
111  pack_start(*(new Gtk::HSeparator()));
112
113  edgemapcbts.resize(EDGE_INPUT_NUM);
114  for(int i=0;i<(int)edgemapcbts.size();i++)
115    {
116      Gtk::HBox * hbox=new Gtk::HBox();
117
118      std::ostringstream o;
119      o << "EdgeInput " << i+1 << ":";
120      label=new Gtk::Label(o.str());
121
122      edgemapcbts[i]=new Gtk::ComboBoxText();
123
124      hbox->pack_start(*label);
125      hbox->pack_start(*(edgemapcbts[i]));
126      pack_start(*hbox);
127    }
128
129  pack_start(*(new Gtk::HSeparator()));
130}
131
132sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
133{
134  return signal_maplist_need;
135}
136
137void AlgoBox::emit_tab_change()
138{
139  signal_maplist_need.emit(tabcbt.get_active_text());
140}
Note: See TracBrowser for help on using the repository browser.