hegyi@1819
|
1 |
#include "map_win.h"
|
hegyi@1731
|
2 |
|
hegyi@1823
|
3 |
MapWin::MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, int identifier, bool edge):gdc(grdispc),ms(mapst),id(identifier),itisedge(edge),default_state(true),set_new_map(false),node_to_update(INVALID),edge_to_update(INVALID)
|
hegyi@1731
|
4 |
{
|
hegyi@1731
|
5 |
update_list();
|
hegyi@1731
|
6 |
|
hegyi@1731
|
7 |
cbt.set_active(0);
|
hegyi@1731
|
8 |
|
hegyi@1731
|
9 |
//binding signal to the actual entry
|
hegyi@1731
|
10 |
cbt.signal_changed().connect
|
hegyi@1731
|
11 |
(
|
hegyi@1819
|
12 |
sigc::mem_fun((*this), &MapWin::MapSelector::comboChanged),
|
hegyi@1731
|
13 |
false
|
hegyi@1731
|
14 |
);
|
hegyi@1731
|
15 |
|
hegyi@1731
|
16 |
if(itisedge)
|
hegyi@1731
|
17 |
{
|
hegyi@1731
|
18 |
label=new Gtk::Label(edge_property_strings[id]);
|
hegyi@1731
|
19 |
}
|
hegyi@1731
|
20 |
else
|
hegyi@1731
|
21 |
{
|
hegyi@1731
|
22 |
label=new Gtk::Label(node_property_strings[id]);
|
hegyi@1731
|
23 |
}
|
hegyi@1731
|
24 |
|
hegyi@1731
|
25 |
label->set_width_chars(longest_property_string_length);
|
hegyi@1731
|
26 |
|
hegyi@1731
|
27 |
defbut=new Gtk::Button();
|
hegyi@1731
|
28 |
defbut->set_label("Reset");
|
hegyi@1731
|
29 |
|
hegyi@1731
|
30 |
defbut->signal_pressed().connect
|
hegyi@1731
|
31 |
(
|
hegyi@1819
|
32 |
sigc::mem_fun(*this, &MapWin::MapSelector::reset)
|
hegyi@1731
|
33 |
);
|
hegyi@1731
|
34 |
|
hegyi@1731
|
35 |
newbut=new Gtk::Button(Gtk::Stock::NEW);
|
hegyi@1731
|
36 |
|
hegyi@1733
|
37 |
newbut->signal_pressed().connect
|
hegyi@1733
|
38 |
(
|
hegyi@1819
|
39 |
sigc::mem_fun(*this, &MapWin::MapSelector::new_but_pressed)
|
hegyi@1733
|
40 |
);
|
hegyi@1733
|
41 |
|
hegyi@1731
|
42 |
add(*label);
|
hegyi@1731
|
43 |
|
hegyi@1731
|
44 |
add(cbt);
|
hegyi@1731
|
45 |
|
hegyi@1731
|
46 |
add(*defbut);
|
hegyi@1731
|
47 |
add(*newbut);
|
hegyi@1731
|
48 |
}
|
hegyi@1731
|
49 |
|
hegyi@1819
|
50 |
void MapWin::MapSelector::new_but_pressed()
|
hegyi@1737
|
51 |
{
|
hegyi@1737
|
52 |
set_new_map=true;
|
hegyi@1823
|
53 |
(new NewMapWin("NewMapWin", gdc, itisedge, false))->run();
|
hegyi@1737
|
54 |
}
|
hegyi@1737
|
55 |
|
hegyi@1819
|
56 |
void MapWin::MapSelector::update_list()
|
hegyi@1731
|
57 |
{
|
hegyi@1731
|
58 |
cbt.clear();
|
hegyi@1731
|
59 |
if(itisedge)
|
hegyi@1731
|
60 |
{
|
hegyi@1731
|
61 |
std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
|
hegyi@1731
|
62 |
for(;emsi!=ms.endOfEdgeMaps();emsi++)
|
hegyi@1731
|
63 |
{
|
hegyi@1731
|
64 |
cbt.append_text(emsi->first);
|
hegyi@1731
|
65 |
}
|
hegyi@1731
|
66 |
}
|
hegyi@1731
|
67 |
else
|
hegyi@1731
|
68 |
{
|
hegyi@1731
|
69 |
std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
|
hegyi@1731
|
70 |
for(;emsi!=ms.endOfNodeMaps();emsi++)
|
hegyi@1731
|
71 |
{
|
hegyi@1731
|
72 |
cbt.append_text(emsi->first);
|
hegyi@1731
|
73 |
}
|
hegyi@1731
|
74 |
}
|
hegyi@1731
|
75 |
cbt.prepend_text("Default values");
|
hegyi@1731
|
76 |
}
|
hegyi@1731
|
77 |
|
hegyi@1819
|
78 |
void MapWin::MapSelector::comboChanged()
|
hegyi@1731
|
79 |
{
|
hegyi@1731
|
80 |
if(cbt.get_active_row_number()!=0)
|
hegyi@1731
|
81 |
{
|
hegyi@1731
|
82 |
default_state=false;
|
hegyi@1731
|
83 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@1731
|
84 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@1731
|
85 |
{
|
hegyi@1731
|
86 |
if(itisedge)
|
hegyi@1731
|
87 |
{
|
hegyi@1731
|
88 |
if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
|
hegyi@1731
|
89 |
{
|
hegyi@1731
|
90 |
Edge edge=edge_to_update;
|
hegyi@1731
|
91 |
switch(id)
|
hegyi@1731
|
92 |
{
|
hegyi@1731
|
93 |
case E_WIDTH:
|
hegyi@1731
|
94 |
gdc.changeEdgeWidth(mapname, edge);
|
hegyi@1731
|
95 |
break;
|
hegyi@1731
|
96 |
case E_COLOR:
|
hegyi@1731
|
97 |
gdc.changeEdgeColor(mapname, edge);
|
hegyi@1731
|
98 |
break;
|
hegyi@1731
|
99 |
case E_TEXT:
|
hegyi@1731
|
100 |
gdc.changeEdgeText(mapname, edge);
|
hegyi@1731
|
101 |
break;
|
hegyi@1731
|
102 |
default:
|
hegyi@1731
|
103 |
std::cerr<<"Error\n";
|
hegyi@1731
|
104 |
}
|
hegyi@1731
|
105 |
}
|
hegyi@1731
|
106 |
}
|
hegyi@1731
|
107 |
else
|
hegyi@1731
|
108 |
{
|
hegyi@1731
|
109 |
if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
|
hegyi@1731
|
110 |
{
|
hegyi@1731
|
111 |
Node node=node_to_update;
|
hegyi@1731
|
112 |
switch(id)
|
hegyi@1731
|
113 |
{
|
hegyi@1731
|
114 |
case N_RADIUS:
|
hegyi@1731
|
115 |
gdc.changeNodeRadius(mapname, node);
|
hegyi@1731
|
116 |
break;
|
hegyi@1731
|
117 |
case N_COLOR:
|
hegyi@1731
|
118 |
gdc.changeNodeColor(mapname, node);
|
hegyi@1731
|
119 |
break;
|
hegyi@1731
|
120 |
case N_TEXT:
|
hegyi@1731
|
121 |
gdc.changeNodeText(mapname, node);
|
hegyi@1731
|
122 |
break;
|
hegyi@1731
|
123 |
default:
|
hegyi@1731
|
124 |
std::cerr<<"Error\n";
|
hegyi@1731
|
125 |
}
|
hegyi@1731
|
126 |
}
|
hegyi@1731
|
127 |
}
|
hegyi@1731
|
128 |
}
|
hegyi@1731
|
129 |
}
|
hegyi@1731
|
130 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@1731
|
131 |
{
|
hegyi@1731
|
132 |
reset();
|
hegyi@1731
|
133 |
}
|
hegyi@1731
|
134 |
}
|
hegyi@1731
|
135 |
|
hegyi@1819
|
136 |
void MapWin::MapSelector::reset()
|
hegyi@1731
|
137 |
{
|
hegyi@1731
|
138 |
default_state=true;
|
hegyi@1731
|
139 |
cbt.set_active(0);
|
hegyi@1731
|
140 |
|
hegyi@1731
|
141 |
if(itisedge)
|
hegyi@1731
|
142 |
{
|
hegyi@1731
|
143 |
Edge edge=edge_to_update;
|
hegyi@1731
|
144 |
switch(id)
|
hegyi@1731
|
145 |
{
|
hegyi@1731
|
146 |
case E_WIDTH:
|
hegyi@1731
|
147 |
gdc.resetEdgeWidth(edge);
|
hegyi@1731
|
148 |
break;
|
hegyi@1731
|
149 |
case E_COLOR:
|
hegyi@1731
|
150 |
gdc.resetEdgeColor(edge);
|
hegyi@1731
|
151 |
break;
|
hegyi@1731
|
152 |
case E_TEXT:
|
hegyi@1731
|
153 |
gdc.resetEdgeText(edge);
|
hegyi@1731
|
154 |
break;
|
hegyi@1731
|
155 |
default:
|
hegyi@1731
|
156 |
std::cerr<<"Error\n";
|
hegyi@1731
|
157 |
}
|
hegyi@1731
|
158 |
}
|
hegyi@1731
|
159 |
else
|
hegyi@1731
|
160 |
{
|
hegyi@1731
|
161 |
Node node=node_to_update;
|
hegyi@1731
|
162 |
switch(id)
|
hegyi@1731
|
163 |
{
|
hegyi@1731
|
164 |
case N_RADIUS:
|
hegyi@1731
|
165 |
gdc.resetNodeRadius(node);
|
hegyi@1731
|
166 |
break;
|
hegyi@1731
|
167 |
case N_COLOR:
|
hegyi@1731
|
168 |
gdc.resetNodeColor(node);
|
hegyi@1731
|
169 |
break;
|
hegyi@1731
|
170 |
case N_TEXT:
|
hegyi@1731
|
171 |
gdc.resetNodeText(node);
|
hegyi@1731
|
172 |
break;
|
hegyi@1731
|
173 |
default:
|
hegyi@1731
|
174 |
std::cerr<<"Error\n";
|
hegyi@1731
|
175 |
}
|
hegyi@1731
|
176 |
}
|
hegyi@1731
|
177 |
}
|
hegyi@1731
|
178 |
|
hegyi@1819
|
179 |
void MapWin::MapSelector::update(Node node)
|
hegyi@1731
|
180 |
{
|
hegyi@1731
|
181 |
node_to_update=node;
|
hegyi@1731
|
182 |
if(default_state)
|
hegyi@1731
|
183 |
{
|
hegyi@1731
|
184 |
reset();
|
hegyi@1731
|
185 |
}
|
hegyi@1731
|
186 |
else
|
hegyi@1731
|
187 |
{
|
hegyi@1731
|
188 |
comboChanged();
|
hegyi@1731
|
189 |
}
|
hegyi@1731
|
190 |
node_to_update=INVALID;
|
hegyi@1731
|
191 |
}
|
hegyi@1731
|
192 |
|
hegyi@1819
|
193 |
void MapWin::MapSelector::update(Edge edge)
|
hegyi@1731
|
194 |
{
|
hegyi@1731
|
195 |
edge_to_update=edge;
|
hegyi@1731
|
196 |
if(default_state)
|
hegyi@1731
|
197 |
{
|
hegyi@1731
|
198 |
reset();
|
hegyi@1731
|
199 |
}
|
hegyi@1731
|
200 |
else
|
hegyi@1731
|
201 |
{
|
hegyi@1731
|
202 |
comboChanged();
|
hegyi@1731
|
203 |
}
|
hegyi@1731
|
204 |
edge_to_update=INVALID;
|
hegyi@1731
|
205 |
}
|
hegyi@1731
|
206 |
|
hegyi@1819
|
207 |
Glib::ustring MapWin::MapSelector::get_active_text()
|
hegyi@1731
|
208 |
{
|
hegyi@1731
|
209 |
return cbt.get_active_text();
|
hegyi@1731
|
210 |
}
|
hegyi@1731
|
211 |
|
hegyi@1819
|
212 |
void MapWin::MapSelector::set_active_text(Glib::ustring text)
|
hegyi@1731
|
213 |
{
|
hegyi@1731
|
214 |
cbt.set_active_text(text);
|
hegyi@1731
|
215 |
}
|
hegyi@1731
|
216 |
|
hegyi@1819
|
217 |
void MapWin::MapSelector::append_text(Glib::ustring text)
|
hegyi@1731
|
218 |
{
|
hegyi@1731
|
219 |
cbt.append_text(text);
|
hegyi@1737
|
220 |
if(set_new_map)
|
hegyi@1737
|
221 |
{
|
hegyi@1737
|
222 |
set_active_text(text);
|
hegyi@1737
|
223 |
set_new_map=false;
|
hegyi@1737
|
224 |
}
|
hegyi@1731
|
225 |
}
|