hegyi@1
|
1 |
/* -*- C++ -*-
|
hegyi@1
|
2 |
*
|
hegyi@1
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
hegyi@1
|
4 |
*
|
hegyi@1
|
5 |
* Copyright (C) 2003-2006
|
hegyi@1
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
hegyi@1
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
hegyi@1
|
8 |
*
|
hegyi@1
|
9 |
* Permission to use, modify and distribute this software is granted
|
hegyi@1
|
10 |
* provided that this copyright notice appears in all copies. For
|
hegyi@1
|
11 |
* precise terms see the accompanying LICENSE file.
|
hegyi@1
|
12 |
*
|
hegyi@1
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
hegyi@1
|
14 |
* express or implied, and with no claim as to its suitability for any
|
hegyi@1
|
15 |
* purpose.
|
hegyi@1
|
16 |
*
|
hegyi@1
|
17 |
*/
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#include <mapselector.h>
|
hegyi@1
|
20 |
|
hegyi@1
|
21 |
MapSelector::MapSelector(std::vector<std::string> n_ml,
|
hegyi@1
|
22 |
std::vector<std::string> s_ml, std::string act,
|
hegyi@1
|
23 |
std::string labeltext, bool arc, bool d, MapType type) :
|
hegyi@1
|
24 |
def(d),
|
hegyi@1
|
25 |
itisarc(arc),
|
hegyi@1
|
26 |
set_new_map(false),
|
hegyi@1
|
27 |
label(labeltext),
|
hegyi@1
|
28 |
map_type(type),
|
hegyi@1
|
29 |
newbut(Gtk::Stock::NEW)
|
hegyi@1
|
30 |
{
|
hegyi@1
|
31 |
update_list(n_ml, s_ml);
|
hegyi@1
|
32 |
|
hegyi@1
|
33 |
if(act=="")
|
hegyi@1
|
34 |
{
|
hegyi@1
|
35 |
cbt.set_active(0);
|
hegyi@1
|
36 |
default_state=true;
|
hegyi@1
|
37 |
}
|
hegyi@1
|
38 |
else
|
hegyi@1
|
39 |
{
|
hegyi@1
|
40 |
cbt.set_active_text((Glib::ustring)act);
|
hegyi@1
|
41 |
default_state=false;
|
hegyi@1
|
42 |
}
|
hegyi@1
|
43 |
|
hegyi@1
|
44 |
//binding signal to the actual entry
|
hegyi@1
|
45 |
cbt.signal_changed().connect
|
hegyi@1
|
46 |
(
|
hegyi@1
|
47 |
sigc::mem_fun((*this), &MapSelector::comboChanged),
|
hegyi@1
|
48 |
false
|
hegyi@1
|
49 |
);
|
hegyi@1
|
50 |
|
hegyi@1
|
51 |
label.set_width_chars(longest_property_string_length);
|
hegyi@1
|
52 |
|
hegyi@1
|
53 |
if(def)
|
hegyi@1
|
54 |
{
|
hegyi@1
|
55 |
defbut.set_label("Reset");
|
hegyi@1
|
56 |
defbut.signal_pressed().connect
|
hegyi@1
|
57 |
(
|
hegyi@1
|
58 |
sigc::mem_fun(*this, &MapSelector::reset)
|
hegyi@1
|
59 |
);
|
hegyi@1
|
60 |
}
|
hegyi@1
|
61 |
|
hegyi@1
|
62 |
|
hegyi@1
|
63 |
newbut.signal_pressed().connect
|
hegyi@1
|
64 |
(
|
hegyi@1
|
65 |
sigc::mem_fun(*this, &MapSelector::new_but_pressed)
|
hegyi@1
|
66 |
);
|
hegyi@1
|
67 |
|
hegyi@1
|
68 |
add(label);
|
hegyi@1
|
69 |
|
hegyi@1
|
70 |
add(cbt);
|
hegyi@1
|
71 |
|
hegyi@1
|
72 |
if(def)
|
hegyi@1
|
73 |
{
|
hegyi@1
|
74 |
add(defbut);
|
hegyi@1
|
75 |
}
|
hegyi@1
|
76 |
|
hegyi@1
|
77 |
add(newbut);
|
hegyi@1
|
78 |
}
|
hegyi@1
|
79 |
|
hegyi@1
|
80 |
void MapSelector::new_but_pressed()
|
hegyi@1
|
81 |
{
|
hegyi@1
|
82 |
set_new_map=true;
|
hegyi@1
|
83 |
signal_newmapwin.emit(itisarc);
|
hegyi@1
|
84 |
}
|
hegyi@1
|
85 |
|
hegyi@1
|
86 |
void MapSelector::update_list(std::vector<std::string> n_ml,
|
hegyi@1
|
87 |
std::vector<std::string> s_ml)
|
hegyi@1
|
88 |
{
|
hegyi@1
|
89 |
int prev_act=cbt.get_active_row_number();
|
hegyi@1
|
90 |
cbt.clear();
|
hegyi@1
|
91 |
cbt_content.clear();
|
hegyi@1
|
92 |
|
hegyi@1
|
93 |
if (map_type & NUM)
|
hegyi@1
|
94 |
{
|
hegyi@1
|
95 |
std::vector< std::string >::iterator emsi=n_ml.begin();
|
hegyi@1
|
96 |
for(;emsi!=n_ml.end();emsi++)
|
hegyi@1
|
97 |
{
|
hegyi@1
|
98 |
cbt.append_text(*emsi);
|
hegyi@1
|
99 |
cbt_content.push_back(*emsi);
|
hegyi@1
|
100 |
}
|
hegyi@1
|
101 |
}
|
hegyi@1
|
102 |
if (map_type & STR)
|
hegyi@1
|
103 |
{
|
hegyi@1
|
104 |
std::vector< std::string >::iterator emsi=s_ml.begin();
|
hegyi@1
|
105 |
for(;emsi!=s_ml.end();emsi++)
|
hegyi@1
|
106 |
{
|
hegyi@1
|
107 |
cbt.append_text(*emsi);
|
hegyi@1
|
108 |
cbt_content.push_back(*emsi);
|
hegyi@1
|
109 |
}
|
hegyi@1
|
110 |
}
|
hegyi@1
|
111 |
if(def)
|
hegyi@1
|
112 |
{
|
hegyi@1
|
113 |
cbt.prepend_text("Default values");
|
hegyi@1
|
114 |
cbt_content.push_back("Default values");
|
hegyi@1
|
115 |
}
|
hegyi@1
|
116 |
if(prev_act!=-1)
|
hegyi@1
|
117 |
{
|
hegyi@1
|
118 |
cbt.set_active(prev_act);
|
hegyi@1
|
119 |
}
|
hegyi@1
|
120 |
}
|
hegyi@1
|
121 |
|
hegyi@1
|
122 |
void MapSelector::comboChanged()
|
hegyi@1
|
123 |
{
|
hegyi@1
|
124 |
if(cbt.get_active_row_number()!=0 || !def)
|
hegyi@1
|
125 |
{
|
hegyi@1
|
126 |
default_state=false;
|
hegyi@1
|
127 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@1
|
128 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@1
|
129 |
{
|
hegyi@1
|
130 |
signal_cbt.emit(mapname);
|
hegyi@1
|
131 |
}
|
hegyi@1
|
132 |
}
|
hegyi@1
|
133 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@1
|
134 |
{
|
hegyi@1
|
135 |
reset();
|
hegyi@1
|
136 |
}
|
hegyi@1
|
137 |
}
|
hegyi@1
|
138 |
|
hegyi@1
|
139 |
void MapSelector::reset()
|
hegyi@1
|
140 |
{
|
hegyi@1
|
141 |
default_state=true;
|
hegyi@1
|
142 |
|
hegyi@1
|
143 |
cbt.set_active(0);
|
hegyi@1
|
144 |
|
hegyi@1
|
145 |
signal_cbt.emit("");
|
hegyi@1
|
146 |
}
|
hegyi@1
|
147 |
|
hegyi@1
|
148 |
|
hegyi@1
|
149 |
Glib::ustring MapSelector::get_active_text()
|
hegyi@1
|
150 |
{
|
hegyi@1
|
151 |
return cbt.get_active_text();
|
hegyi@1
|
152 |
}
|
hegyi@1
|
153 |
|
hegyi@1
|
154 |
void MapSelector::set_active_text(Glib::ustring text)
|
hegyi@1
|
155 |
{
|
hegyi@1
|
156 |
if(text.compare(""))
|
hegyi@1
|
157 |
{
|
hegyi@1
|
158 |
cbt.set_active_text(text);
|
hegyi@1
|
159 |
}
|
hegyi@1
|
160 |
else
|
hegyi@1
|
161 |
{
|
hegyi@1
|
162 |
cbt.set_active_text("Default values");
|
hegyi@1
|
163 |
}
|
hegyi@1
|
164 |
}
|
hegyi@1
|
165 |
|
hegyi@1
|
166 |
void MapSelector::append_text(Glib::ustring text, MapValue::Type type)
|
hegyi@1
|
167 |
{
|
hegyi@1
|
168 |
if (type & map_type)
|
hegyi@1
|
169 |
{
|
hegyi@1
|
170 |
cbt.append_text(text);
|
hegyi@1
|
171 |
cbt_content.push_back(text);
|
hegyi@1
|
172 |
|
hegyi@1
|
173 |
if(set_new_map)
|
hegyi@1
|
174 |
{
|
hegyi@1
|
175 |
set_active_text(text);
|
hegyi@1
|
176 |
set_new_map=false;
|
hegyi@1
|
177 |
}
|
hegyi@1
|
178 |
}
|
hegyi@1
|
179 |
}
|
hegyi@1
|
180 |
|
hegyi@1
|
181 |
sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
|
hegyi@1
|
182 |
{
|
hegyi@1
|
183 |
return signal_cbt;
|
hegyi@1
|
184 |
}
|
hegyi@1
|
185 |
|
hegyi@1
|
186 |
sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
|
hegyi@1
|
187 |
{
|
hegyi@1
|
188 |
return signal_newmapwin;
|
hegyi@1
|
189 |
}
|