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