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 |
|
ladanyi@53
|
19 |
#include "mapstorage.h"
|
ladanyi@98
|
20 |
#include "gui_writer.h"
|
ladanyi@98
|
21 |
#include "gui_reader.h"
|
alpar@128
|
22 |
#include <limits>
|
alpar@128
|
23 |
#include <cmath>
|
ladanyi@63
|
24 |
#include <gtkmm.h>
|
deba@77
|
25 |
|
ladanyi@98
|
26 |
MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
|
ladanyi@6
|
27 |
{
|
ladanyi@53
|
28 |
nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
|
ladanyi@53
|
29 |
coords.setXMap(*nodemap_storage["coordinates_x"]);
|
ladanyi@53
|
30 |
nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
|
ladanyi@53
|
31 |
coords.setYMap(*nodemap_storage["coordinates_y"]);
|
ladanyi@53
|
32 |
|
ladanyi@98
|
33 |
edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
|
ladanyi@98
|
34 |
arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
|
ladanyi@98
|
35 |
edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
|
ladanyi@98
|
36 |
arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
|
ladanyi@98
|
37 |
|
ladanyi@134
|
38 |
nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
|
ladanyi@134
|
39 |
edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
|
ladanyi@64
|
40 |
|
ladanyi@134
|
41 |
nodemap_default["label"] = 1.0;
|
ladanyi@134
|
42 |
edgemap_default["label"] = 1.0;
|
hegyi@94
|
43 |
|
hegyi@94
|
44 |
active_nodemaps.resize(NODE_PROPERTY_NUM);
|
hegyi@94
|
45 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@94
|
46 |
{
|
hegyi@94
|
47 |
active_nodemaps[i]="";
|
hegyi@94
|
48 |
}
|
hegyi@94
|
49 |
|
hegyi@94
|
50 |
active_edgemaps.resize(EDGE_PROPERTY_NUM);
|
hegyi@94
|
51 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@94
|
52 |
{
|
hegyi@94
|
53 |
active_edgemaps[i]="";
|
hegyi@94
|
54 |
}
|
ladanyi@53
|
55 |
}
|
ladanyi@53
|
56 |
|
ladanyi@53
|
57 |
MapStorage::~MapStorage()
|
ladanyi@53
|
58 |
{
|
ladanyi@53
|
59 |
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
|
ladanyi@53
|
60 |
nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
|
ladanyi@53
|
61 |
{
|
ladanyi@53
|
62 |
delete it->second;
|
ladanyi@53
|
63 |
}
|
ladanyi@53
|
64 |
for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
|
ladanyi@53
|
65 |
edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
|
ladanyi@53
|
66 |
{
|
ladanyi@53
|
67 |
delete it->second;
|
ladanyi@53
|
68 |
}
|
ladanyi@53
|
69 |
}
|
ladanyi@6
|
70 |
|
hegyi@118
|
71 |
int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
|
ladanyi@6
|
72 |
{
|
hegyi@46
|
73 |
if( nodemap_storage.find(name) == nodemap_storage.end() )
|
hegyi@46
|
74 |
{
|
hegyi@46
|
75 |
nodemap_storage[name]=nodemap;
|
ladanyi@63
|
76 |
// set the maps default value
|
ladanyi@63
|
77 |
nodemap_default[name] = default_value;
|
hegyi@108
|
78 |
|
hegyi@108
|
79 |
//announce changement in maps
|
hegyi@108
|
80 |
signal_node_map.emit(name);
|
hegyi@46
|
81 |
return 0;
|
hegyi@46
|
82 |
}
|
hegyi@46
|
83 |
return 1;
|
ladanyi@6
|
84 |
}
|
ladanyi@6
|
85 |
|
hegyi@94
|
86 |
void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname)
|
hegyi@94
|
87 |
{
|
hegyi@94
|
88 |
if(itisedge)
|
hegyi@94
|
89 |
{
|
hegyi@94
|
90 |
active_edgemaps[prop]=mapname;
|
hegyi@94
|
91 |
}
|
hegyi@94
|
92 |
else
|
hegyi@94
|
93 |
{
|
hegyi@94
|
94 |
active_nodemaps[prop]=mapname;
|
hegyi@94
|
95 |
}
|
hegyi@94
|
96 |
signal_prop.emit(itisedge, prop);
|
hegyi@94
|
97 |
}
|
hegyi@94
|
98 |
|
hegyi@172
|
99 |
void MapStorage::broadcastActiveMaps()
|
hegyi@172
|
100 |
{
|
hegyi@172
|
101 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@172
|
102 |
{
|
hegyi@172
|
103 |
signal_map_win.emit(false, i, active_nodemaps[i]);
|
hegyi@172
|
104 |
}
|
hegyi@172
|
105 |
|
hegyi@172
|
106 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@172
|
107 |
{
|
hegyi@172
|
108 |
signal_map_win.emit(true, i, active_edgemaps[i]);
|
hegyi@172
|
109 |
}
|
hegyi@172
|
110 |
}
|
hegyi@172
|
111 |
|
hegyi@172
|
112 |
|
hegyi@94
|
113 |
std::string MapStorage::getActiveEdgeMap(int prop)
|
hegyi@94
|
114 |
{
|
hegyi@94
|
115 |
return active_edgemaps[prop];
|
hegyi@94
|
116 |
}
|
hegyi@94
|
117 |
|
hegyi@94
|
118 |
std::string MapStorage::getActiveNodeMap(int prop)
|
hegyi@94
|
119 |
{
|
hegyi@94
|
120 |
return active_nodemaps[prop];
|
hegyi@94
|
121 |
}
|
hegyi@94
|
122 |
|
hegyi@94
|
123 |
std::vector<std::string> MapStorage::getEdgeMapList()
|
hegyi@94
|
124 |
{
|
hegyi@94
|
125 |
std::vector<std::string> eml;
|
hegyi@94
|
126 |
eml.resize(edgemap_storage.size());
|
hegyi@94
|
127 |
int i=0;
|
hegyi@94
|
128 |
std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
|
hegyi@94
|
129 |
for(;emsi!=endOfEdgeMaps();emsi++)
|
hegyi@94
|
130 |
{
|
hegyi@94
|
131 |
eml[i]=(emsi->first);
|
hegyi@94
|
132 |
i++;
|
hegyi@94
|
133 |
}
|
hegyi@94
|
134 |
return eml;
|
hegyi@94
|
135 |
}
|
hegyi@94
|
136 |
|
hegyi@94
|
137 |
std::vector<std::string> MapStorage::getNodeMapList()
|
hegyi@94
|
138 |
{
|
hegyi@94
|
139 |
std::vector<std::string> nml;
|
hegyi@94
|
140 |
nml.resize(nodemap_storage.size());
|
hegyi@94
|
141 |
int i=0;
|
hegyi@94
|
142 |
std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
|
hegyi@94
|
143 |
for(;nmsi!=endOfNodeMaps();nmsi++)
|
hegyi@94
|
144 |
{
|
hegyi@94
|
145 |
nml[i]=(nmsi->first);
|
hegyi@94
|
146 |
i++;
|
hegyi@94
|
147 |
}
|
hegyi@94
|
148 |
return nml;
|
hegyi@94
|
149 |
}
|
hegyi@94
|
150 |
|
hegyi@94
|
151 |
MapStorage::Signal_Prop MapStorage::signal_prop_ch()
|
hegyi@94
|
152 |
{
|
hegyi@94
|
153 |
return signal_prop;
|
hegyi@94
|
154 |
}
|
hegyi@94
|
155 |
|
hegyi@118
|
156 |
int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
|
ladanyi@6
|
157 |
{
|
hegyi@46
|
158 |
if( edgemap_storage.find(name) == edgemap_storage.end() )
|
hegyi@46
|
159 |
{
|
hegyi@46
|
160 |
edgemap_storage[name]=edgemap;
|
ladanyi@63
|
161 |
// set the maps default value
|
ladanyi@63
|
162 |
edgemap_default[name] = default_value;
|
hegyi@108
|
163 |
|
hegyi@108
|
164 |
//announce changement in maps
|
hegyi@108
|
165 |
signal_edge_map.emit(name);
|
hegyi@46
|
166 |
return 0;
|
hegyi@46
|
167 |
}
|
hegyi@46
|
168 |
return 1;
|
ladanyi@6
|
169 |
}
|
ladanyi@6
|
170 |
|
ladanyi@6
|
171 |
double MapStorage::maxOfNodeMap(const std::string & name)
|
ladanyi@6
|
172 |
{
|
ladanyi@6
|
173 |
double max=0;
|
ladanyi@53
|
174 |
for (NodeIt j(graph); j!=INVALID; ++j)
|
ladanyi@6
|
175 |
{
|
ladanyi@6
|
176 |
if( (*nodemap_storage[name])[j]>max )
|
ladanyi@6
|
177 |
{
|
ladanyi@6
|
178 |
max=(*nodemap_storage[name])[j];
|
ladanyi@6
|
179 |
}
|
ladanyi@6
|
180 |
}
|
ladanyi@6
|
181 |
return max;
|
ladanyi@6
|
182 |
}
|
ladanyi@6
|
183 |
|
ladanyi@6
|
184 |
double MapStorage::maxOfEdgeMap(const std::string & name)
|
ladanyi@6
|
185 |
{
|
ladanyi@6
|
186 |
double max=0;
|
ladanyi@53
|
187 |
for (EdgeIt j(graph); j!=INVALID; ++j)
|
ladanyi@6
|
188 |
{
|
ladanyi@6
|
189 |
if( (*edgemap_storage[name])[j]>max )
|
ladanyi@6
|
190 |
{
|
ladanyi@6
|
191 |
max=(*edgemap_storage[name])[j];
|
ladanyi@6
|
192 |
}
|
ladanyi@6
|
193 |
}
|
ladanyi@6
|
194 |
return max;
|
ladanyi@6
|
195 |
}
|
ladanyi@6
|
196 |
|
ladanyi@6
|
197 |
double MapStorage::minOfNodeMap(const std::string & name)
|
ladanyi@6
|
198 |
{
|
ladanyi@53
|
199 |
NodeIt j(graph);
|
hegyi@58
|
200 |
double min;
|
hegyi@58
|
201 |
if(j!=INVALID)
|
hegyi@58
|
202 |
{
|
hegyi@58
|
203 |
min=(*nodemap_storage[name])[j];
|
hegyi@58
|
204 |
}
|
hegyi@58
|
205 |
else
|
hegyi@58
|
206 |
{
|
hegyi@58
|
207 |
min=0;
|
hegyi@58
|
208 |
}
|
ladanyi@6
|
209 |
for (; j!=INVALID; ++j)
|
ladanyi@6
|
210 |
{
|
ladanyi@6
|
211 |
if( (*nodemap_storage[name])[j]<min )
|
ladanyi@6
|
212 |
{
|
ladanyi@6
|
213 |
min=(*nodemap_storage[name])[j];
|
ladanyi@6
|
214 |
}
|
ladanyi@6
|
215 |
}
|
ladanyi@6
|
216 |
return min;
|
ladanyi@6
|
217 |
}
|
ladanyi@6
|
218 |
|
ladanyi@6
|
219 |
double MapStorage::minOfEdgeMap(const std::string & name)
|
ladanyi@6
|
220 |
{
|
ladanyi@53
|
221 |
EdgeIt j(graph);
|
hegyi@58
|
222 |
double min;
|
hegyi@58
|
223 |
if(j!=INVALID)
|
hegyi@58
|
224 |
{
|
hegyi@58
|
225 |
min=(*edgemap_storage[name])[j];
|
hegyi@58
|
226 |
}
|
hegyi@58
|
227 |
else
|
hegyi@58
|
228 |
{
|
hegyi@58
|
229 |
min=0;
|
hegyi@58
|
230 |
}
|
ladanyi@53
|
231 |
for (EdgeIt j(graph); j!=INVALID; ++j)
|
ladanyi@6
|
232 |
{
|
ladanyi@6
|
233 |
if( (*edgemap_storage[name])[j]<min )
|
ladanyi@6
|
234 |
{
|
ladanyi@6
|
235 |
min=(*edgemap_storage[name])[j];
|
ladanyi@6
|
236 |
}
|
ladanyi@6
|
237 |
}
|
ladanyi@6
|
238 |
return min;
|
ladanyi@6
|
239 |
}
|
ladanyi@6
|
240 |
|
ladanyi@63
|
241 |
int MapStorage::readFromFile(const std::string &filename)
|
ladanyi@53
|
242 |
{
|
ladanyi@53
|
243 |
bool read_x = false;
|
ladanyi@53
|
244 |
bool read_y = false;
|
ladanyi@64
|
245 |
bool read_edge_id = false;
|
ladanyi@53
|
246 |
|
ladanyi@53
|
247 |
try {
|
ladanyi@53
|
248 |
LemonReader lreader(filename);
|
ladanyi@53
|
249 |
ContentReader content(lreader);
|
ladanyi@53
|
250 |
lreader.run();
|
ladanyi@53
|
251 |
|
ladanyi@101
|
252 |
if (content.nodeSetNum() < 1)
|
ladanyi@101
|
253 |
{
|
ladanyi@101
|
254 |
Gtk::MessageDialog mdialog("No nodeset found in file.");
|
ladanyi@101
|
255 |
mdialog.run();
|
ladanyi@101
|
256 |
clear();
|
ladanyi@101
|
257 |
return 1;
|
ladanyi@101
|
258 |
}
|
ladanyi@101
|
259 |
|
ladanyi@101
|
260 |
if (content.edgeSetNum() < 1)
|
ladanyi@101
|
261 |
{
|
ladanyi@101
|
262 |
Gtk::MessageDialog mdialog("No edgeset found in file.");
|
ladanyi@101
|
263 |
mdialog.run();
|
ladanyi@101
|
264 |
clear();
|
ladanyi@101
|
265 |
return 1;
|
ladanyi@101
|
266 |
}
|
ladanyi@101
|
267 |
|
ladanyi@53
|
268 |
const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
|
ladanyi@53
|
269 |
const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
|
ladanyi@53
|
270 |
|
ladanyi@53
|
271 |
GraphReader<Graph> greader(filename, graph);
|
ladanyi@53
|
272 |
for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
|
ladanyi@53
|
273 |
it != nodeMapNames.end(); ++it)
|
ladanyi@53
|
274 |
{
|
ladanyi@53
|
275 |
if (*it == "coordinates_x")
|
ladanyi@53
|
276 |
{
|
ladanyi@53
|
277 |
read_x = true;
|
ladanyi@53
|
278 |
//std::cout << "read X nodemap" << std::endl;
|
ladanyi@53
|
279 |
}
|
ladanyi@53
|
280 |
else if (*it == "coordinates_y")
|
ladanyi@53
|
281 |
{
|
ladanyi@53
|
282 |
read_y = true;
|
ladanyi@53
|
283 |
//std::cout << "read Y nodemap" << std::endl;
|
ladanyi@53
|
284 |
}
|
ladanyi@134
|
285 |
else if (*it == "label")
|
ladanyi@53
|
286 |
{
|
ladanyi@53
|
287 |
//std::cout << "read id nodemap" << std::endl;
|
ladanyi@53
|
288 |
}
|
ladanyi@53
|
289 |
else
|
ladanyi@53
|
290 |
{
|
ladanyi@53
|
291 |
nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
|
ladanyi@53
|
292 |
//std::cout << "read " << *it << " nodemap" << std::endl;
|
ladanyi@53
|
293 |
}
|
ladanyi@53
|
294 |
greader.readNodeMap(*it, *nodemap_storage[*it]);
|
ladanyi@53
|
295 |
}
|
ladanyi@53
|
296 |
for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
|
ladanyi@53
|
297 |
it != edgeMapNames.end(); ++it)
|
ladanyi@53
|
298 |
{
|
ladanyi@134
|
299 |
if (*it == "label")
|
ladanyi@53
|
300 |
{
|
ladanyi@53
|
301 |
//std::cout << "read id edgemap" << std::endl;
|
ladanyi@135
|
302 |
read_edge_id = true;
|
ladanyi@53
|
303 |
}
|
ladanyi@53
|
304 |
else
|
ladanyi@53
|
305 |
{
|
ladanyi@53
|
306 |
edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
|
ladanyi@53
|
307 |
//std::cout << "read " << *it << " edgemap" << std::endl;
|
ladanyi@53
|
308 |
}
|
ladanyi@53
|
309 |
greader.readEdgeMap(*it, *edgemap_storage[*it]);
|
ladanyi@53
|
310 |
}
|
ladanyi@98
|
311 |
GuiReader gui_reader(greader, this);
|
ladanyi@53
|
312 |
greader.run();
|
ladanyi@101
|
313 |
} catch (Exception& error) {
|
ladanyi@79
|
314 |
Gtk::MessageDialog mdialog(error.what());
|
ladanyi@53
|
315 |
mdialog.run();
|
ladanyi@63
|
316 |
clear();
|
ladanyi@63
|
317 |
return 1;
|
ladanyi@53
|
318 |
}
|
ladanyi@53
|
319 |
|
ladanyi@64
|
320 |
if (!read_edge_id)
|
ladanyi@64
|
321 |
{
|
ladanyi@134
|
322 |
edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
|
ladanyi@64
|
323 |
int i = 1;
|
ladanyi@64
|
324 |
for (EdgeIt e(graph); e != INVALID; ++e)
|
ladanyi@64
|
325 |
{
|
ladanyi@134
|
326 |
(*edgemap_storage["label"])[e] = i++;
|
ladanyi@64
|
327 |
}
|
ladanyi@64
|
328 |
}
|
ladanyi@64
|
329 |
|
ladanyi@53
|
330 |
if (!read_x || !read_y)
|
ladanyi@53
|
331 |
{
|
ladanyi@53
|
332 |
int node_num = 0;
|
ladanyi@53
|
333 |
for (NodeIt n(graph); n != INVALID; ++n)
|
ladanyi@53
|
334 |
{
|
ladanyi@53
|
335 |
node_num++;
|
ladanyi@53
|
336 |
}
|
ladanyi@53
|
337 |
const double pi = 3.142;
|
ladanyi@53
|
338 |
double step = 2 * pi / (double) node_num;
|
ladanyi@53
|
339 |
int i = 0;
|
ladanyi@53
|
340 |
for (NodeIt n(graph); n != INVALID; ++n)
|
ladanyi@53
|
341 |
{
|
deba@77
|
342 |
nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
|
deba@77
|
343 |
nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
|
ladanyi@53
|
344 |
i++;
|
ladanyi@53
|
345 |
}
|
ladanyi@53
|
346 |
}
|
ladanyi@63
|
347 |
|
ladanyi@98
|
348 |
if (!arrow_pos_read_ok)
|
ladanyi@98
|
349 |
{
|
ladanyi@98
|
350 |
arrow_pos_read_ok = false;
|
ladanyi@98
|
351 |
for (EdgeIt e(graph); e != INVALID; ++e)
|
ladanyi@98
|
352 |
{
|
ladanyi@151
|
353 |
if (graph.source(e) == graph.target(e))
|
ladanyi@151
|
354 |
{
|
ladanyi@151
|
355 |
arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
|
ladanyi@151
|
356 |
}
|
ladanyi@151
|
357 |
else
|
ladanyi@151
|
358 |
{
|
ladanyi@151
|
359 |
arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
|
ladanyi@151
|
360 |
}
|
ladanyi@98
|
361 |
}
|
ladanyi@98
|
362 |
}
|
ladanyi@98
|
363 |
|
ladanyi@63
|
364 |
// fill in the default values for the maps
|
ladanyi@63
|
365 |
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
|
ladanyi@63
|
366 |
nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
|
ladanyi@63
|
367 |
{
|
ladanyi@134
|
368 |
if ((it->first != "label") &&
|
ladanyi@63
|
369 |
(it->first != "coordiantes_x") &&
|
ladanyi@63
|
370 |
(it->first != "coordinates_y"))
|
ladanyi@63
|
371 |
{
|
ladanyi@63
|
372 |
nodemap_default[it->first] = 0.0;
|
ladanyi@63
|
373 |
}
|
ladanyi@134
|
374 |
else if (it->first == "label")
|
ladanyi@64
|
375 |
{
|
ladanyi@64
|
376 |
NodeIt n(graph);
|
ladanyi@134
|
377 |
double max = (*nodemap_storage["label"])[n];
|
ladanyi@64
|
378 |
for (; n != INVALID; ++n)
|
ladanyi@64
|
379 |
{
|
ladanyi@134
|
380 |
if ((*nodemap_storage["label"])[n] > max)
|
ladanyi@134
|
381 |
max = (*nodemap_storage["label"])[n];
|
ladanyi@64
|
382 |
}
|
ladanyi@134
|
383 |
nodemap_default["label"] = max + 1.0;
|
ladanyi@64
|
384 |
}
|
ladanyi@63
|
385 |
}
|
ladanyi@63
|
386 |
for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
|
ladanyi@63
|
387 |
edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
|
ladanyi@63
|
388 |
{
|
ladanyi@134
|
389 |
if (it->first != "label")
|
ladanyi@63
|
390 |
{
|
ladanyi@63
|
391 |
edgemap_default[it->first] = 0.0;
|
ladanyi@63
|
392 |
}
|
ladanyi@64
|
393 |
else
|
ladanyi@64
|
394 |
{
|
ladanyi@67
|
395 |
double max = std::numeric_limits<double>::min();
|
ladanyi@67
|
396 |
for (EdgeIt e(graph); e != INVALID; ++e)
|
ladanyi@64
|
397 |
{
|
ladanyi@134
|
398 |
if ((*edgemap_storage["label"])[e] > max)
|
ladanyi@134
|
399 |
max = (*edgemap_storage["label"])[e];
|
ladanyi@64
|
400 |
}
|
ladanyi@67
|
401 |
if (max > std::numeric_limits<double>::min())
|
ladanyi@134
|
402 |
edgemap_default["label"] = max + 1.0;
|
ladanyi@67
|
403 |
else
|
ladanyi@134
|
404 |
edgemap_default["label"] = 1.0;
|
ladanyi@64
|
405 |
}
|
ladanyi@63
|
406 |
}
|
ladanyi@63
|
407 |
|
ladanyi@63
|
408 |
return 0;
|
ladanyi@53
|
409 |
}
|
ladanyi@53
|
410 |
|
ladanyi@53
|
411 |
void MapStorage::writeToFile(const std::string &filename)
|
ladanyi@53
|
412 |
{
|
ladanyi@53
|
413 |
GraphWriter<Graph> gwriter(filename, graph);
|
ladanyi@53
|
414 |
|
ladanyi@53
|
415 |
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
|
ladanyi@53
|
416 |
nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
|
ladanyi@53
|
417 |
{
|
ladanyi@53
|
418 |
gwriter.writeNodeMap(it->first, *(it->second));
|
ladanyi@53
|
419 |
}
|
ladanyi@53
|
420 |
for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
|
ladanyi@53
|
421 |
edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
|
ladanyi@53
|
422 |
{
|
ladanyi@98
|
423 |
if ((it->first != "arrow_pos_x") &&
|
ladanyi@98
|
424 |
(it->first != "arrow_pos_y"))
|
ladanyi@98
|
425 |
{
|
ladanyi@98
|
426 |
gwriter.writeEdgeMap(it->first, *(it->second));
|
ladanyi@98
|
427 |
}
|
ladanyi@53
|
428 |
}
|
ladanyi@98
|
429 |
|
ladanyi@98
|
430 |
GuiWriter gui_writer(gwriter, this);
|
ladanyi@98
|
431 |
|
ladanyi@53
|
432 |
gwriter.run();
|
ladanyi@53
|
433 |
}
|
ladanyi@53
|
434 |
|
ladanyi@53
|
435 |
void MapStorage::clear()
|
ladanyi@53
|
436 |
{
|
ladanyi@53
|
437 |
for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
|
ladanyi@53
|
438 |
nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
|
ladanyi@53
|
439 |
{
|
ladanyi@53
|
440 |
if ((it->first != "coordinates_x") &&
|
ladanyi@53
|
441 |
(it->first != "coordinates_y") &&
|
ladanyi@134
|
442 |
(it->first != "label"))
|
ladanyi@53
|
443 |
{
|
ladanyi@53
|
444 |
delete it->second;
|
ladanyi@53
|
445 |
nodemap_storage.erase(it);
|
ladanyi@53
|
446 |
}
|
ladanyi@53
|
447 |
}
|
ladanyi@53
|
448 |
for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
|
ladanyi@53
|
449 |
edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
|
ladanyi@53
|
450 |
{
|
ladanyi@134
|
451 |
if ((it->first != "label") &&
|
ladanyi@98
|
452 |
(it->first != "arrow_pos_x") &&
|
ladanyi@98
|
453 |
(it->first != "arrow_pos_y"))
|
ladanyi@53
|
454 |
{
|
ladanyi@53
|
455 |
delete it->second;
|
ladanyi@53
|
456 |
edgemap_storage.erase(it);
|
ladanyi@53
|
457 |
}
|
ladanyi@53
|
458 |
}
|
ladanyi@63
|
459 |
for (std::map<std::string, double>::iterator it =
|
ladanyi@63
|
460 |
nodemap_default.begin(); it != nodemap_default.end(); ++it)
|
ladanyi@63
|
461 |
{
|
ladanyi@134
|
462 |
if (it->first != "label")
|
ladanyi@64
|
463 |
nodemap_default.erase(it);
|
ladanyi@63
|
464 |
}
|
ladanyi@63
|
465 |
for (std::map<std::string, double>::iterator it =
|
ladanyi@63
|
466 |
edgemap_default.begin(); it != edgemap_default.end(); ++it)
|
ladanyi@63
|
467 |
{
|
ladanyi@134
|
468 |
if (it->first != "label")
|
ladanyi@64
|
469 |
edgemap_default.erase(it);
|
ladanyi@63
|
470 |
}
|
ladanyi@53
|
471 |
graph.clear();
|
ladanyi@53
|
472 |
file_name = "";
|
ladanyi@53
|
473 |
modified = false;
|
hegyi@172
|
474 |
|
hegyi@172
|
475 |
arrow_pos_read_ok = false;
|
hegyi@172
|
476 |
|
hegyi@172
|
477 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@172
|
478 |
{
|
hegyi@172
|
479 |
changeActiveMap(false, i, "");
|
hegyi@172
|
480 |
signal_map_win.emit(false, i, "");
|
hegyi@172
|
481 |
}
|
hegyi@172
|
482 |
|
hegyi@172
|
483 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@172
|
484 |
{
|
hegyi@172
|
485 |
changeActiveMap(true, i, "");
|
hegyi@172
|
486 |
signal_map_win.emit(true, i, "");
|
hegyi@172
|
487 |
}
|
ladanyi@53
|
488 |
}
|
ladanyi@98
|
489 |
|
ladanyi@98
|
490 |
void MapStorage::ArrowPosReadOK()
|
ladanyi@98
|
491 |
{
|
ladanyi@98
|
492 |
arrow_pos_read_ok = true;
|
ladanyi@98
|
493 |
}
|
hegyi@111
|
494 |
|
hegyi@111
|
495 |
void MapStorage::mapChanged(bool itisedge, std::string mapname)
|
hegyi@111
|
496 |
{
|
hegyi@111
|
497 |
if(itisedge)
|
hegyi@111
|
498 |
{
|
hegyi@111
|
499 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@111
|
500 |
{
|
hegyi@111
|
501 |
if(active_edgemaps[i]==mapname)
|
hegyi@111
|
502 |
{
|
hegyi@111
|
503 |
signal_prop.emit(itisedge, i);
|
hegyi@111
|
504 |
}
|
hegyi@111
|
505 |
}
|
hegyi@111
|
506 |
}
|
hegyi@111
|
507 |
else
|
hegyi@111
|
508 |
{
|
hegyi@111
|
509 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@111
|
510 |
{
|
hegyi@111
|
511 |
if(active_nodemaps[i]==mapname)
|
hegyi@111
|
512 |
{
|
hegyi@111
|
513 |
signal_prop.emit(itisedge, i);
|
hegyi@111
|
514 |
}
|
hegyi@111
|
515 |
}
|
hegyi@111
|
516 |
}
|
hegyi@111
|
517 |
}
|