COIN-OR::LEMON - Graph Library

source: glemon/algobox.cc

Last change on this file was 1:67188bd752db, checked in by Peter Hegyi <hegyi@…>, 16 years ago

SVN revision 3500 made compilable with Lemon 1.0.

File size: 4.9 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#include <algobox.h>
20#include <mapstorage.h>
21#include <mapselector.h>
22
23enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
24enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for arcs;
25
26AlgoBox::AlgoBox(std::vector<std::string> tabnames)
27{
28  init(tabnames);
29}
30
31void AlgoBox::init(std::vector<std::string> tabnames)
32{
33  set_spacing(5);
34
35  update_tablist(tabnames);
36
37  //if active tab is changed, the map names in cbt/s have to be updated
38  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
39
40  pack_start(tabcbt);
41  build_box();
42
43  show_all_children();
44};
45
46void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
47{
48  std::string actname=cbt.get_active_text();
49  int prev_act=-1;
50
51  cbt.clear();
52  int actptr=0;
53
54  std::vector< std::string >::iterator emsi=stringlist.begin();
55  for(;emsi!=stringlist.end();emsi++)
56    {
57      if(actname==*emsi)
58        {
59          prev_act=actptr;
60        }
61
62      cbt.append_text(*emsi);
63      actptr++;
64    }
65
66  if(prev_act!=-1)
67    {
68      cbt.set_active(prev_act);
69    }
70  else if(actptr>0) //so there is item in the list
71    {
72      //cbt.set_active(0);
73    }
74}
75
76void AlgoBox::update_tablist( std::vector< std::string > tl )
77{
78  update_cbt(tl, tabcbt);
79  emit_tab_change();
80}
81
82void AlgoBox::update_maplist(MapStorage * ms)
83{
84  mapstorage=ms;
85  std::vector<std::string> n_nml;
86  std::vector<std::string> s_nml;
87  std::vector<std::string> n_eml;
88  std::vector<std::string> s_eml;
89  if(mapstorage!=NULL)
90    {
91      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
92      mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::arcmaplist_changed));
93      n_nml=mapstorage->getNodeMapList(NUM);
94      s_nml=mapstorage->getNodeMapList(STR);
95      n_eml=mapstorage->getArcMapList(NUM);
96      s_eml=mapstorage->getArcMapList(STR);
97    }
98  for(int i=0;i<(int)nodemapcbts.size();i++)
99    {
100      (nodemapcbts[i])->update_list(n_nml, s_nml);
101      //update_cbt(nml, *(nodemapcbts[i]));
102    }
103  for(int i=0;i<(int)arcmapcbts.size();i++)
104    {
105      (arcmapcbts[i])->update_list(n_eml, s_eml);
106      //update_cbt(eml, *(arcmapcbts[i]));
107    }
108  signal_maplist_updated.emit();
109}
110
111void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type)
112{
113  for(int i=0;i<(int)nodemapcbts.size();i++)
114    {
115      (nodemapcbts[i])->append_text(newmap, type);
116    }
117}
118
119void AlgoBox::arcmaplist_changed(std::string newmap, MapValue::Type type)
120{
121  for(int i=0;i<(int)arcmapcbts.size();i++)
122    {
123      (arcmapcbts[i])->append_text(newmap, type);
124    }
125}
126
127void AlgoBox::run()
128{
129  std::cout << "Start algorithm." << std::endl;
130}
131
132void AlgoBox::build_box()
133{
134  pack_start(*(new Gtk::HSeparator()));
135
136  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
137     
138  pack_start(*label);
139  pack_start(*(new Gtk::HSeparator()));
140
141  label=new Gtk::Label("Maps in chosen tab:");
142     
143  pack_start(*label);
144
145  for(int i=0;i<NODE_INPUT_NUM;i++)
146    {
147      std::ostringstream o;
148      o << "NodeInput " << i+1 << ":";
149
150      addMapSelector(o.str(), false);
151    }
152
153  pack_start(*(new Gtk::HSeparator()));
154
155  for(int i=0;i<EDGE_INPUT_NUM;i++)
156    {
157
158      std::ostringstream o;
159      o << "ArcInput " << i+1 << ":";
160
161      addMapSelector(o.str(), true);
162    }
163
164  pack_start(*(new Gtk::HSeparator()));
165}
166
167void AlgoBox::addMapSelector(std::string inputname, bool itisarc, MapType type)
168{
169  std::vector<std::string> empty_vector;
170
171  MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisarc, false, type);
172
173  if(itisarc)
174    {
175      arcmapcbts.resize(arcmapcbts.size()+1);
176      arcmapcbts[arcmapcbts.size()-1]=msp;
177    }
178  else
179    {
180      nodemapcbts.resize(nodemapcbts.size()+1);
181      nodemapcbts[nodemapcbts.size()-1]=msp;
182    }
183
184  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
185
186  pack_start(*msp);
187}
188
189sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
190{
191  return signal_maplist_need;
192}
193
194void AlgoBox::emit_tab_change()
195{
196  std::string active_tab=tabcbt.get_active_text();
197  if(active_tab!="")
198    {
199      signal_maplist_need.emit(active_tab);
200    }
201  else
202    {
203      std::vector<std::string> empty_vector;
204      update_maplist(NULL);
205    }
206}
207
208void AlgoBox::emit_new_map_signal(bool itisarc)
209{
210  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisarc);
211}
Note: See TracBrowser for help on using the repository browser.