COIN-OR::LEMON - Graph Library

source: glemon-0.x/algobox.cc @ 194:6b2b718420eb

Last change on this file since 194:6b2b718420eb was 194:6b2b718420eb, checked in by Hegyi Péter, 17 years ago

Header reorganising

File size: 4.6 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 edges;
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> nml;
86  std::vector<std::string> eml;
87  if(mapstorage!=NULL)
88    {
89      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
90      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
91      nml=mapstorage->getNodeMapList();
92      eml=mapstorage->getEdgeMapList();
93    }
94  for(int i=0;i<(int)nodemapcbts.size();i++)
95    {
96      (nodemapcbts[i])->update_list(nml);
97      //update_cbt(nml, *(nodemapcbts[i]));
98    }
99  for(int i=0;i<(int)edgemapcbts.size();i++)
100    {
101      (edgemapcbts[i])->update_list(eml);
102      //update_cbt(eml, *(edgemapcbts[i]));
103    }
104  signal_maplist_updated.emit();
105}
106
107void AlgoBox::nodemaplist_changed(std::string newmap)
108{
109  for(int i=0;i<(int)nodemapcbts.size();i++)
110    {
111      (nodemapcbts[i])->append_text(newmap);
112    }
113}
114
115void AlgoBox::edgemaplist_changed(std::string newmap)
116{
117  for(int i=0;i<(int)edgemapcbts.size();i++)
118    {
119      (edgemapcbts[i])->append_text(newmap);
120    }
121}
122
123void AlgoBox::run()
124{
125  std::cout << "Start algorithm." << std::endl;
126}
127
128void AlgoBox::build_box()
129{
130  pack_start(*(new Gtk::HSeparator()));
131
132  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
133     
134  pack_start(*label);
135  pack_start(*(new Gtk::HSeparator()));
136
137  label=new Gtk::Label("Maps in chosen tab:");
138     
139  pack_start(*label);
140
141  for(int i=0;i<NODE_INPUT_NUM;i++)
142    {
143      std::ostringstream o;
144      o << "NodeInput " << i+1 << ":";
145
146      addMapSelector(o.str(), false);
147    }
148
149  pack_start(*(new Gtk::HSeparator()));
150
151  for(int i=0;i<EDGE_INPUT_NUM;i++)
152    {
153
154      std::ostringstream o;
155      o << "EdgeInput " << i+1 << ":";
156
157      addMapSelector(o.str(), true);
158    }
159
160  pack_start(*(new Gtk::HSeparator()));
161}
162
163void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
164{
165  std::vector<std::string> empty_vector;
166
167  MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
168
169  if(itisedge)
170    {
171      edgemapcbts.resize(edgemapcbts.size()+1);
172      edgemapcbts[edgemapcbts.size()-1]=msp;
173    }
174  else
175    {
176      nodemapcbts.resize(nodemapcbts.size()+1);
177      nodemapcbts[nodemapcbts.size()-1]=msp;
178    }
179
180  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
181
182  pack_start(*msp);
183}
184
185sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
186{
187  return signal_maplist_need;
188}
189
190void AlgoBox::emit_tab_change()
191{
192  std::string active_tab=tabcbt.get_active_text();
193  if(active_tab!="")
194    {
195      signal_maplist_need.emit(active_tab);
196    }
197  else
198    {
199      std::vector<std::string> empty_vector;
200      update_maplist(NULL);
201    }
202}
203
204void AlgoBox::emit_new_map_signal(bool itisedge)
205{
206  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
207}
Note: See TracBrowser for help on using the repository browser.