113 { |
150 { |
114 signal_map_win.emit(true, i, active_edgemaps[i]); |
151 signal_map_win.emit(true, i, active_edgemaps[i]); |
115 } |
152 } |
116 } |
153 } |
117 |
154 |
118 |
|
119 std::string MapStorage::getActiveEdgeMap(int prop) |
155 std::string MapStorage::getActiveEdgeMap(int prop) |
120 { |
156 { |
121 return active_edgemaps[prop]; |
157 return active_edgemaps[prop]; |
122 } |
158 } |
123 |
159 |
124 std::string MapStorage::getActiveNodeMap(int prop) |
160 std::string MapStorage::getActiveNodeMap(int prop) |
125 { |
161 { |
126 return active_nodemaps[prop]; |
162 return active_nodemaps[prop]; |
127 } |
163 } |
128 |
164 |
129 std::vector<std::string> MapStorage::getEdgeMapList() |
165 std::vector<std::string> MapStorage::getEdgeMapList(MapType type) |
130 { |
166 { |
131 std::vector<std::string> eml; |
167 if (type == ALL) |
132 eml.resize(edgemap_storage.size()); |
168 { |
133 int i=0; |
169 std::vector<std::string> ret; |
134 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps(); |
170 for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
135 for(;emsi!=endOfEdgeMaps();emsi++) |
171 it != edgemaps.end(); ++it) |
136 { |
172 { |
137 eml[i]=(emsi->first); |
173 ret.push_back(it->first); |
138 i++; |
174 } |
139 } |
175 return ret; |
140 return eml; |
176 } |
141 } |
177 else |
142 |
178 { |
143 std::vector<std::string> MapStorage::getNodeMapList() |
179 std::vector<std::string> ret; |
144 { |
180 for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
145 std::vector<std::string> nml; |
181 it != edgemaps.end(); ++it) |
146 nml.resize(nodemap_storage.size()); |
182 { |
147 int i=0; |
183 EdgeMapData* data = getEdgeMapData(it->first); |
148 std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps(); |
184 MapValue::Type t = data->type(); |
149 for(;nmsi!=endOfNodeMaps();nmsi++) |
185 if ((t == MapValue::NUMERIC && (type & NUM)) || |
150 { |
186 (t == MapValue::STRING && (type & STR))) |
151 nml[i]=(nmsi->first); |
187 { |
152 i++; |
188 ret.push_back(it->first); |
153 } |
189 } |
154 return nml; |
190 } |
|
191 return ret; |
|
192 } |
|
193 } |
|
194 |
|
195 std::vector<std::string> MapStorage::getNodeMapList(MapType type) |
|
196 { |
|
197 if (type == ALL) |
|
198 { |
|
199 std::vector<std::string> ret; |
|
200 for (NodeMapStore::const_iterator it = nodemaps.begin(); |
|
201 it != nodemaps.end(); ++it) |
|
202 { |
|
203 ret.push_back(it->first); |
|
204 } |
|
205 return ret; |
|
206 } |
|
207 else |
|
208 { |
|
209 std::vector<std::string> ret; |
|
210 for (NodeMapStore::const_iterator it = nodemaps.begin(); |
|
211 it != nodemaps.end(); ++it) |
|
212 { |
|
213 NodeMapData* data = getNodeMapData(it->first); |
|
214 MapValue::Type t = data->type(); |
|
215 if ((t == MapValue::NUMERIC && (type & NUM)) || |
|
216 (t == MapValue::STRING && (type & STR))) |
|
217 { |
|
218 ret.push_back(it->first); |
|
219 } |
|
220 } |
|
221 return ret; |
|
222 } |
155 } |
223 } |
156 |
224 |
157 sigc::signal<void, bool, int> MapStorage::signal_prop_ch() |
225 sigc::signal<void, bool, int> MapStorage::signal_prop_ch() |
158 { |
226 { |
159 return signal_prop; |
227 return signal_prop; |
160 } |
228 } |
161 |
229 |
162 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value) |
230 int MapStorage::readFromFile(const std::string &filename) |
163 { |
231 { |
164 if( edgemap_storage.find(name) == edgemap_storage.end() ) |
232 using std::vector; |
165 { |
233 using std::map; |
166 edgemap_storage[name]=edgemap; |
234 using std::string; |
167 // set the maps default value |
235 |
168 edgemap_default[name] = default_value; |
236 // check whether the .conf file exists |
169 |
237 bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(), |
170 //announce changement in maps |
238 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)); |
171 signal_edge_map.emit(name); |
239 |
172 return 0; |
240 // check whether the .lgf file contains a gui section |
173 } |
241 bool gui_data_in_lgf = false; |
174 return 1; |
242 { |
175 } |
243 std::ifstream ifs(filename.c_str()); |
176 |
244 std::string line; |
177 double MapStorage::maxOfNodeMap(const std::string & name) |
245 while (getline(ifs, line)) |
178 { |
246 { |
179 double max=0; |
247 int pos = line.find("@gui"); |
180 for (NodeIt j(graph); j!=INVALID; ++j) |
248 if (pos != std::string::npos) |
181 { |
249 { |
182 if( (*nodemap_storage[name])[j]>max ) |
250 bool only_whitespace_before = true; |
183 { |
251 for (int i = 0; i < pos; ++i) |
184 max=(*nodemap_storage[name])[j]; |
252 { |
185 } |
253 if (!std::isspace(line[i])) |
186 } |
254 { |
187 return max; |
255 only_whitespace_before = false; |
188 } |
256 break; |
189 |
257 } |
190 double MapStorage::maxOfEdgeMap(const std::string & name) |
258 } |
191 { |
259 if (only_whitespace_before) gui_data_in_lgf = true; |
192 double max=0; |
260 } |
193 for (EdgeIt j(graph); j!=INVALID; ++j) |
261 } |
194 { |
262 } |
195 if( (*edgemap_storage[name])[j]>max ) |
263 |
196 { |
264 bool gui_data_found = gui_data_in_lgf || gui_data_in_conf; |
197 max=(*edgemap_storage[name])[j]; |
265 |
198 } |
266 // ask for user input if both exist |
199 } |
267 bool use_gui_data_in_lgf = false; |
200 return max; |
268 if (gui_data_in_conf && gui_data_in_lgf) |
201 } |
269 { |
202 |
270 Gtk::MessageDialog mdialog(_("<b>Found both ") + filename + |
203 double MapStorage::minOfNodeMap(const std::string & name) |
271 _(".conf and a gui section in ") + filename + _(".</b>"), true, |
204 { |
272 Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE); |
205 NodeIt j(graph); |
273 mdialog.add_button(_("Use the ._conf file"), 1); |
206 double min; |
274 mdialog.add_button(_("Use the _gui section"), 2); |
207 if(j!=INVALID) |
275 switch (mdialog.run()) |
208 { |
276 { |
209 min=(*nodemap_storage[name])[j]; |
277 case 1: |
210 } |
278 use_gui_data_in_lgf = false; |
|
279 break; |
|
280 case 2: |
|
281 use_gui_data_in_lgf = true; |
|
282 break; |
|
283 case Gtk::RESPONSE_NONE: |
|
284 return 1; |
|
285 } |
|
286 } |
211 else |
287 else |
212 { |
288 { |
213 min=0; |
289 use_gui_data_in_lgf = gui_data_in_lgf; |
214 } |
290 } |
215 for (; j!=INVALID; ++j) |
291 |
216 { |
292 if (gui_data_found) |
217 if( (*nodemap_storage[name])[j]<min ) |
293 { |
218 { |
294 GUISectData gui_data; |
219 min=(*nodemap_storage[name])[j]; |
295 if (use_gui_data_in_lgf) |
220 } |
296 { |
221 } |
297 // read the gui section from the .lgf file |
222 return min; |
298 try |
223 } |
299 { |
224 |
300 LemonReader lreader(filename); |
225 double MapStorage::minOfEdgeMap(const std::string & name) |
301 GuiReader gui_reader(lreader, this, gui_data); |
226 { |
302 lreader.run(); |
227 EdgeIt j(graph); |
303 gui_sect_save_dest = LGF_FILE; |
228 double min; |
304 } |
229 if(j!=INVALID) |
305 catch (Exception& error) |
230 { |
306 { |
231 min=(*edgemap_storage[name])[j]; |
307 clear(); |
232 } |
308 return 1; |
233 else |
309 } |
234 { |
310 } |
235 min=0; |
311 else |
236 } |
312 { |
237 for (EdgeIt j(graph); j!=INVALID; ++j) |
313 // read the gui section from the .conf file |
238 { |
314 try |
239 if( (*edgemap_storage[name])[j]<min ) |
315 { |
240 { |
316 LemonReader lreader(filename + ".conf"); |
241 min=(*edgemap_storage[name])[j]; |
317 GuiReader gui_reader(lreader, this, gui_data); |
242 } |
318 lreader.run(); |
243 } |
319 gui_sect_save_dest = CONF_FILE; |
244 return min; |
320 } |
245 } |
321 catch (Exception& error) |
246 |
322 { |
247 int MapStorage::readFromFile(const std::string &filename) |
323 clear(); |
248 { |
324 return 1; |
249 bool read_x = false; |
325 } |
250 bool read_y = false; |
326 } |
251 bool read_edge_id = false; |
327 |
252 |
328 // read the graph and maps form the .lgf file |
253 try { |
329 try |
254 LemonReader lreader(filename); |
330 { |
255 ContentReader content(lreader); |
331 std::string node_coord_xmap_name, node_coord_ymap_name; |
256 lreader.run(); |
332 std::string arrow_coord_xmap_name, arrow_coord_ymap_name; |
257 |
333 |
258 if (content.nodeSetNum() < 1) |
334 if (gui_data.node_coords_save_dest == |
259 { |
335 MapStorage::SpecMapSaveOpts::NESET_SECT) |
260 Gtk::MessageDialog mdialog("No nodeset found in file."); |
336 { |
261 mdialog.run(); |
337 switch (gui_data.node_coords_save_map_num) |
|
338 { |
|
339 case SpecMapSaveOpts::ONE_MAP: |
|
340 node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x"; |
|
341 node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y"; |
|
342 node_coords_one_map_name = gui_data.node_coords_one_map_name; |
|
343 break; |
|
344 case SpecMapSaveOpts::TWO_MAPS: |
|
345 node_coord_xmap_name = gui_data.node_coords_two_maps_1_name; |
|
346 node_coord_ymap_name = gui_data.node_coords_two_maps_2_name; |
|
347 node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name; |
|
348 node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name; |
|
349 break; |
|
350 } |
|
351 node_coords_save_dest = gui_data.node_coords_save_dest; |
|
352 node_coords_save_map_num = gui_data.node_coords_save_map_num; |
|
353 } |
|
354 |
|
355 if (gui_data.arrow_coords_save_dest == |
|
356 MapStorage::SpecMapSaveOpts::NESET_SECT) |
|
357 { |
|
358 switch (gui_data.arrow_coords_save_map_num) |
|
359 { |
|
360 case SpecMapSaveOpts::ONE_MAP: |
|
361 arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x"; |
|
362 arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y"; |
|
363 arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name; |
|
364 break; |
|
365 case SpecMapSaveOpts::TWO_MAPS: |
|
366 arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name; |
|
367 arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name; |
|
368 arrow_coords_two_maps_1_name = |
|
369 gui_data.arrow_coords_two_maps_1_name; |
|
370 arrow_coords_two_maps_2_name = |
|
371 gui_data.arrow_coords_two_maps_2_name; |
|
372 break; |
|
373 } |
|
374 arrow_coords_save_dest = gui_data.arrow_coords_save_dest; |
|
375 arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num; |
|
376 } |
|
377 readLGF(filename, true, |
|
378 gui_data.main_node_map_names, gui_data.main_edge_map_names, |
|
379 gui_data.node_map_types, gui_data.edge_map_types, |
|
380 node_coord_xmap_name, node_coord_ymap_name, |
|
381 arrow_coord_xmap_name, arrow_coord_ymap_name); |
|
382 } |
|
383 catch (Exception& error) |
|
384 { |
262 clear(); |
385 clear(); |
263 return 1; |
386 return 1; |
264 } |
387 } |
265 |
388 |
266 if (content.edgeSetNum() < 1) |
389 // add the maps from the gui section |
267 { |
390 for (vector<string>::const_iterator |
268 Gtk::MessageDialog mdialog("No edgeset found in file."); |
391 it = gui_data.gui_node_map_names.begin(); |
269 mdialog.run(); |
392 it != gui_data.gui_node_map_names.end(); ++it) |
270 clear(); |
393 { |
271 return 1; |
394 string map_name = *it; |
272 } |
395 switch (gui_data.node_map_types[map_name]) |
273 |
396 { |
274 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0); |
397 case MapValue::NUMERIC: |
275 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0); |
398 { |
276 |
399 createNodeMap(map_name, MapValue::NUMERIC, double()); |
277 GraphReader<Graph> greader(filename, graph); |
400 NumericNodeMap& dmap = getNumericNodeMap(map_name); |
278 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin(); |
401 map<int, double>& smap = *gui_data.numeric_node_maps[map_name]; |
279 it != nodeMapNames.end(); ++it) |
402 for (NodeIt n(graph); n != INVALID; ++n) |
280 { |
403 { |
281 if (*it == "coordinates_x") |
404 dmap[n] = smap[node_label[n]]; |
282 { |
405 } |
283 read_x = true; |
406 break; |
284 //std::cout << "read X nodemap" << std::endl; |
407 } |
285 } |
408 case MapValue::STRING: |
286 else if (*it == "coordinates_y") |
409 { |
287 { |
410 createNodeMap(map_name, MapValue::STRING, string()); |
288 read_y = true; |
411 StringNodeMap& dmap = getStringNodeMap(map_name); |
289 //std::cout << "read Y nodemap" << std::endl; |
412 map<int, string>& smap = *gui_data.string_node_maps[map_name]; |
290 } |
413 for (NodeIt n(graph); n != INVALID; ++n) |
291 else if (*it == "label") |
414 { |
292 { |
415 dmap[n] = smap[node_label[n]]; |
293 //std::cout << "read id nodemap" << std::endl; |
416 } |
|
417 break; |
|
418 } |
|
419 } |
|
420 getNodeMapData(map_name)->save_dest = GUI_SECT; |
|
421 } |
|
422 for (vector<string>::const_iterator |
|
423 it = gui_data.gui_edge_map_names.begin(); |
|
424 it != gui_data.gui_edge_map_names.end(); ++it) |
|
425 { |
|
426 string map_name = *it; |
|
427 switch (gui_data.edge_map_types[map_name]) |
|
428 { |
|
429 case MapValue::NUMERIC: |
|
430 { |
|
431 createEdgeMap(map_name, MapValue::NUMERIC, double()); |
|
432 NumericEdgeMap& dmap = getNumericEdgeMap(map_name); |
|
433 map<int, double>& smap = *gui_data.numeric_edge_maps[map_name]; |
|
434 for (EdgeIt e(graph); e != INVALID; ++e) |
|
435 { |
|
436 dmap[e] = smap[edge_label[e]]; |
|
437 } |
|
438 break; |
|
439 } |
|
440 case MapValue::STRING: |
|
441 { |
|
442 createEdgeMap(map_name, MapValue::STRING, string()); |
|
443 StringEdgeMap& dmap = getStringEdgeMap(map_name); |
|
444 map<int, string>& smap = *gui_data.string_edge_maps[map_name]; |
|
445 for (EdgeIt e(graph); e != INVALID; ++e) |
|
446 { |
|
447 dmap[e] = smap[edge_label[e]]; |
|
448 } |
|
449 break; |
|
450 } |
|
451 } |
|
452 getEdgeMapData(map_name)->save_dest = GUI_SECT; |
|
453 } |
|
454 |
|
455 // restore the node coordinate maps |
|
456 if (gui_data.node_coords_save_dest == |
|
457 MapStorage::SpecMapSaveOpts::GUI_SECT) |
|
458 { |
|
459 for (NodeIt n(graph); n != INVALID; ++n) |
|
460 { |
|
461 node_coords.set(n, gui_data.node_coord_map[node_label[n]]); |
|
462 } |
|
463 node_coords_save_dest = gui_data.node_coords_save_dest; |
|
464 } |
|
465 // restore the arrow coordinate maps |
|
466 if (gui_data.arrow_coords_save_dest == |
|
467 MapStorage::SpecMapSaveOpts::GUI_SECT) |
|
468 { |
|
469 for (EdgeIt e(graph); e != INVALID; ++e) |
|
470 { |
|
471 arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]); |
|
472 } |
|
473 arrow_coords_save_dest = gui_data.arrow_coords_save_dest; |
|
474 } |
|
475 } |
|
476 else |
|
477 { |
|
478 // there is no gui section neither in the .lgf file nor in the .conf file |
|
479 { |
|
480 LemonReader lreader(filename); |
|
481 ContentReader content(lreader); |
|
482 try |
|
483 { |
|
484 lreader.run(); |
|
485 } |
|
486 catch (Exception& error) |
|
487 { |
|
488 Gtk::MessageDialog mdialog(error.what()); |
|
489 mdialog.run(); |
|
490 clear(); |
|
491 return 1; |
|
492 } |
|
493 |
|
494 if (content.nodeSetNum() < 1) |
|
495 { |
|
496 Gtk::MessageDialog mdialog("No nodeset found in file."); |
|
497 mdialog.run(); |
|
498 clear(); |
|
499 return 1; |
|
500 } |
|
501 |
|
502 if (content.edgeSetNum() < 1) |
|
503 { |
|
504 Gtk::MessageDialog mdialog("No edgeset found in file."); |
|
505 mdialog.run(); |
|
506 clear(); |
|
507 return 1; |
|
508 } |
|
509 |
|
510 std::vector<std::string> nodeMapNames = content.nodeSetMaps(0); |
|
511 std::vector<std::string> edgeMapNames = content.edgeSetMaps(0); |
|
512 |
|
513 bool read_edge_label = true; |
|
514 if (std::find(edgeMapNames.begin(), edgeMapNames.end(), "label") == |
|
515 edgeMapNames.end()) |
|
516 { |
|
517 read_edge_label = false; |
|
518 } |
|
519 |
|
520 nodeMapNames.erase( |
|
521 std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"), |
|
522 nodeMapNames.end()); |
|
523 |
|
524 edgeMapNames.erase( |
|
525 std::remove(edgeMapNames.begin(), edgeMapNames.end(), "label"), |
|
526 edgeMapNames.end()); |
|
527 |
|
528 FileImportDialog::ImportData data(nodeMapNames, edgeMapNames); |
|
529 FileImportDialog fidialog(&data); |
|
530 int response = fidialog.run(); |
|
531 if (response == Gtk::RESPONSE_OK) |
|
532 { |
|
533 try |
|
534 { |
|
535 std::string node_coord_xmap_name, node_coord_ymap_name; |
|
536 std::string arrow_coord_xmap_name, arrow_coord_ymap_name; |
|
537 bool gen_node_coords = false; |
|
538 bool gen_arrow_coords = false; |
|
539 |
|
540 switch (data.node_coord_load_from) |
|
541 { |
|
542 case FileImportDialog::ImportData::ONE_MAP: |
|
543 node_coord_xmap_name = data.node_coord_one_map_name + ":x"; |
|
544 node_coord_ymap_name = data.node_coord_one_map_name + ":y"; |
|
545 node_coords_one_map_name = data.node_coord_one_map_name; |
|
546 |
|
547 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; |
|
548 node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; |
|
549 break; |
|
550 case FileImportDialog::ImportData::TWO_MAPS: |
|
551 node_coord_xmap_name = data.node_coord_two_maps_1_name; |
|
552 node_coord_ymap_name = data.node_coord_two_maps_2_name; |
|
553 node_coords_two_maps_1_name = data.node_coord_two_maps_1_name; |
|
554 node_coords_two_maps_2_name = data.node_coord_two_maps_2_name; |
|
555 |
|
556 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; |
|
557 node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; |
|
558 break; |
|
559 case FileImportDialog::ImportData::DONT_READ: |
|
560 node_coord_xmap_name = ""; |
|
561 node_coord_ymap_name = ""; |
|
562 |
|
563 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; |
|
564 gen_node_coords = true; |
|
565 break; |
|
566 } |
|
567 |
|
568 switch (data.arrow_coord_load_from) |
|
569 { |
|
570 case FileImportDialog::ImportData::ONE_MAP: |
|
571 arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x"; |
|
572 arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y"; |
|
573 arrow_coords_one_map_name = data.arrow_coord_one_map_name; |
|
574 |
|
575 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; |
|
576 arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; |
|
577 break; |
|
578 case FileImportDialog::ImportData::TWO_MAPS: |
|
579 arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name; |
|
580 arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name; |
|
581 arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name; |
|
582 arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name; |
|
583 |
|
584 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; |
|
585 arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; |
|
586 break; |
|
587 case FileImportDialog::ImportData::DONT_READ: |
|
588 arrow_coord_xmap_name = ""; |
|
589 arrow_coord_ymap_name = ""; |
|
590 |
|
591 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; |
|
592 gen_arrow_coords = true; |
|
593 break; |
|
594 } |
|
595 |
|
596 // read edge and node maps |
|
597 std::vector<std::string> node_map_names; |
|
598 std::vector<std::string> edge_map_names; |
|
599 std::map<std::string, MapValue::Type> node_map_types; |
|
600 std::map<std::string, MapValue::Type> edge_map_types; |
|
601 for (std::vector<std::string>::const_iterator it = |
|
602 data.numeric_node_map_names.begin(); |
|
603 it != data.numeric_node_map_names.end(); ++it) |
|
604 { |
|
605 node_map_names.push_back(*it); |
|
606 node_map_types[*it] = MapValue::NUMERIC; |
|
607 } |
|
608 for (std::vector<std::string>::const_iterator it = |
|
609 data.string_node_map_names.begin(); |
|
610 it != data.string_node_map_names.end(); ++it) |
|
611 { |
|
612 node_map_names.push_back(*it); |
|
613 node_map_types[*it] = MapValue::STRING; |
|
614 } |
|
615 for (std::vector<std::string>::const_iterator it = |
|
616 data.numeric_edge_map_names.begin(); |
|
617 it != data.numeric_edge_map_names.end(); ++it) |
|
618 { |
|
619 edge_map_names.push_back(*it); |
|
620 edge_map_types[*it] = MapValue::NUMERIC; |
|
621 } |
|
622 for (std::vector<std::string>::const_iterator it = |
|
623 data.string_edge_map_names.begin(); |
|
624 it != data.string_edge_map_names.end(); ++it) |
|
625 { |
|
626 edge_map_names.push_back(*it); |
|
627 edge_map_types[*it] = MapValue::STRING; |
|
628 } |
|
629 |
|
630 readLGF(filename, read_edge_label, |
|
631 node_map_names, edge_map_names, |
|
632 node_map_types, edge_map_types, |
|
633 node_coord_xmap_name, node_coord_ymap_name, |
|
634 arrow_coord_xmap_name, arrow_coord_ymap_name); |
|
635 |
|
636 // generate edge labels |
|
637 if (!read_edge_label) |
|
638 { |
|
639 int l = 0; |
|
640 for (EdgeIt e(graph); e != INVALID; ++e) |
|
641 { |
|
642 edge_label[e] = l++; |
|
643 } |
|
644 } |
|
645 |
|
646 if (gen_node_coords) |
|
647 { |
|
648 // generate node coordinates |
|
649 int node_num = 0; |
|
650 for (NodeIt n(graph); n != INVALID; ++n) { node_num++; } |
|
651 const double pi = 3.142; |
|
652 double step = 2 * pi / (double) node_num; |
|
653 int i = 0; |
|
654 for (NodeIt n(graph); n != INVALID; ++n) |
|
655 { |
|
656 setNodeCoords(n, |
|
657 XY(250.0 * std::cos(i * step), |
|
658 250.0 * std::sin(i * step))); |
|
659 i++; |
|
660 } |
|
661 } |
|
662 if (gen_arrow_coords) |
|
663 { |
|
664 // generate arrow coordinates |
|
665 for (EdgeIt e(graph); e != INVALID; ++e) |
|
666 { |
|
667 if (graph.source(e) == graph.target(e)) |
|
668 { |
|
669 setArrowCoords(e, |
|
670 getNodeCoords(graph.source(e)) + XY(0.0, 80.0)); |
|
671 } |
|
672 else |
|
673 { |
|
674 setArrowCoords(e, |
|
675 (getNodeCoords(graph.source(e)) + |
|
676 getNodeCoords(graph.target(e))) / 2.0); |
|
677 } |
|
678 } |
|
679 } |
|
680 } |
|
681 catch (Exception& error) |
|
682 { |
|
683 clear(); |
|
684 return 1; |
|
685 } |
294 } |
686 } |
295 else |
687 else |
296 { |
688 { |
297 nodemap_storage[*it] = new Graph::NodeMap<double>(graph); |
689 clear(); |
298 //std::cout << "read " << *it << " nodemap" << std::endl; |
690 return 1; |
299 } |
691 } |
300 greader.readNodeMap(*it, *nodemap_storage[*it]); |
692 } |
301 } |
693 } |
302 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin(); |
694 |
303 it != edgeMapNames.end(); ++it) |
695 // set max_node_label |
304 { |
696 { |
305 if (*it == "label") |
697 max_node_label = std::numeric_limits<int>::min(); |
306 { |
698 for (NodeIt n(graph); n != INVALID; ++n) |
307 //std::cout << "read id edgemap" << std::endl; |
699 { |
308 read_edge_id = true; |
700 if (node_label[n] > max_node_label) |
309 } |
701 { |
310 else |
702 max_node_label = node_label[n]; |
311 { |
703 } |
312 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph); |
704 } |
313 //std::cout << "read " << *it << " edgemap" << std::endl; |
705 } |
314 } |
706 // set max_edge_label |
315 greader.readEdgeMap(*it, *edgemap_storage[*it]); |
707 { |
316 } |
708 max_edge_label = std::numeric_limits<int>::min(); |
317 GuiReader gui_reader(greader, this); |
|
318 greader.run(); |
|
319 } catch (Exception& error) { |
|
320 Gtk::MessageDialog mdialog(error.what()); |
|
321 mdialog.run(); |
|
322 clear(); |
|
323 return 1; |
|
324 } |
|
325 |
|
326 if (!read_edge_id) |
|
327 { |
|
328 edgemap_storage["label"] = new Graph::EdgeMap<double>(graph); |
|
329 int i = 1; |
|
330 for (EdgeIt e(graph); e != INVALID; ++e) |
709 for (EdgeIt e(graph); e != INVALID; ++e) |
331 { |
710 { |
332 (*edgemap_storage["label"])[e] = i++; |
711 if (edge_label[e] > max_edge_label) |
333 } |
712 { |
334 } |
713 max_edge_label = edge_label[e]; |
335 |
714 } |
336 if (!read_x || !read_y) |
715 } |
337 { |
716 } |
338 int node_num = 0; |
717 |
339 for (NodeIt n(graph); n != INVALID; ++n) |
718 return 0; |
340 { |
719 } |
341 node_num++; |
720 |
342 } |
721 void MapStorage::writeToFile(const std::string &filename) |
343 const double pi = 3.142; |
722 { |
344 double step = 2 * pi / (double) node_num; |
723 // relabel nodes and edges |
345 int i = 0; |
724 int i = 0; |
346 for (NodeIt n(graph); n != INVALID; ++n) |
725 for (NodeIt n(graph); n != INVALID; ++n) |
347 { |
726 { |
348 nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step)); |
727 node_label[n] = i++; |
349 nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step)); |
728 } |
350 i++; |
729 max_node_label = i-1; |
351 } |
730 i = 0; |
352 } |
731 for (EdgeIt e(graph); e != INVALID; ++e) |
353 |
732 { |
354 if (!arrow_pos_read_ok) |
733 edge_label[e] = i++; |
355 { |
734 } |
356 arrow_pos_read_ok = false; |
735 max_edge_label = i-1; |
357 for (EdgeIt e(graph); e != INVALID; ++e) |
736 |
358 { |
737 // write .lgf file |
359 if (graph.source(e) == graph.target(e)) |
738 { |
360 { |
739 GraphWriter<Graph> gwriter(filename, graph); |
361 arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0)); |
740 |
362 } |
741 gwriter.writeNodeMap("label", node_label); |
363 else |
742 gwriter.writeEdgeMap("label", edge_label); |
364 { |
743 |
365 arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); |
744 // write node maps |
366 } |
745 for (NodeMapStore::const_iterator it = nodemaps.begin(); |
367 } |
746 it != nodemaps.end(); ++it) |
368 } |
747 { |
369 |
748 if (it->second->save_dest == NESET_SECT) |
370 // fill in the default values for the maps |
749 { |
371 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
750 switch (it->second->type()) |
372 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) |
751 { |
373 { |
752 case MapValue::NUMERIC: |
374 if ((it->first != "label") && |
753 gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first)); |
375 (it->first != "coordiantes_x") && |
754 break; |
376 (it->first != "coordinates_y")) |
755 case MapValue::STRING: |
377 { |
756 gwriter.writeNodeMap(it->first, getStringNodeMap(it->first)); |
378 nodemap_default[it->first] = 0.0; |
757 break; |
379 } |
758 } |
380 else if (it->first == "label") |
759 } |
381 { |
760 } |
382 NodeIt n(graph); |
761 |
383 double max = (*nodemap_storage["label"])[n]; |
762 // write edge maps |
384 for (; n != INVALID; ++n) |
763 for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
385 { |
764 it != edgemaps.end(); ++it) |
386 if ((*nodemap_storage["label"])[n] > max) |
765 { |
387 max = (*nodemap_storage["label"])[n]; |
766 if (it->second->save_dest == NESET_SECT) |
388 } |
767 { |
389 nodemap_default["label"] = max + 1.0; |
768 switch (it->second->type()) |
390 } |
769 { |
391 } |
770 case MapValue::NUMERIC: |
392 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = |
771 gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first)); |
393 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) |
772 break; |
394 { |
773 case MapValue::STRING: |
395 if (it->first != "label") |
774 gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first)); |
396 { |
775 break; |
397 edgemap_default[it->first] = 0.0; |
776 } |
|
777 } |
|
778 } |
|
779 |
|
780 // write node coordinates |
|
781 switch (getNodeCoordsSaveDest()) |
|
782 { |
|
783 case MapStorage::SpecMapSaveOpts::GUI_SECT: |
|
784 break; |
|
785 case MapStorage::SpecMapSaveOpts::NESET_SECT: |
|
786 switch (getNodeCoordsSaveMapNum()) |
|
787 { |
|
788 case MapStorage::SpecMapSaveOpts::ONE_MAP: |
|
789 gwriter.writeNodeMap(node_coords_one_map_name + ":x", |
|
790 node_coords_x); |
|
791 gwriter.writeNodeMap(node_coords_one_map_name + ":y", |
|
792 node_coords_y); |
|
793 break; |
|
794 case MapStorage::SpecMapSaveOpts::TWO_MAPS: |
|
795 gwriter.writeNodeMap(node_coords_two_maps_1_name, |
|
796 node_coords_x); |
|
797 gwriter.writeNodeMap(node_coords_two_maps_2_name, |
|
798 node_coords_y); |
|
799 break; |
|
800 } |
|
801 break; |
|
802 } |
|
803 |
|
804 // write arrow coordinates |
|
805 switch (getArrowCoordsSaveDest()) |
|
806 { |
|
807 case MapStorage::SpecMapSaveOpts::GUI_SECT: |
|
808 break; |
|
809 case MapStorage::SpecMapSaveOpts::NESET_SECT: |
|
810 switch (getArrowCoordsSaveMapNum()) |
|
811 { |
|
812 case MapStorage::SpecMapSaveOpts::ONE_MAP: |
|
813 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x", |
|
814 arrow_coords_x); |
|
815 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y", |
|
816 arrow_coords_y); |
|
817 break; |
|
818 case MapStorage::SpecMapSaveOpts::TWO_MAPS: |
|
819 gwriter.writeEdgeMap(arrow_coords_two_maps_1_name, |
|
820 arrow_coords_x); |
|
821 gwriter.writeEdgeMap(arrow_coords_two_maps_2_name, |
|
822 arrow_coords_y); |
|
823 break; |
|
824 } |
|
825 break; |
|
826 } |
|
827 |
|
828 if (gui_sect_save_dest == LGF_FILE) |
|
829 { |
|
830 GuiWriter gui_writer(gwriter, this); |
|
831 gwriter.run(); |
398 } |
832 } |
399 else |
833 else |
400 { |
834 { |
401 double max = std::numeric_limits<double>::min(); |
835 gwriter.run(); |
402 for (EdgeIt e(graph); e != INVALID; ++e) |
836 } |
403 { |
837 } |
404 if ((*edgemap_storage["label"])[e] > max) |
838 |
405 max = (*edgemap_storage["label"])[e]; |
839 // write .conf file |
406 } |
840 if (gui_sect_save_dest == CONF_FILE) |
407 if (max > std::numeric_limits<double>::min()) |
841 { |
408 edgemap_default["label"] = max + 1.0; |
842 LemonWriter lwriter(filename + ".conf"); |
409 else |
843 GuiWriter gui_writer(lwriter, this); |
410 edgemap_default["label"] = 1.0; |
844 lwriter.run(); |
411 } |
845 } |
412 } |
|
413 |
|
414 return 0; |
|
415 } |
|
416 |
|
417 void MapStorage::writeToFile(const std::string &filename) |
|
418 { |
|
419 GraphWriter<Graph> gwriter(filename, graph); |
|
420 |
|
421 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
|
422 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) |
|
423 { |
|
424 gwriter.writeNodeMap(it->first, *(it->second)); |
|
425 } |
|
426 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = |
|
427 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) |
|
428 { |
|
429 if ((it->first != "arrow_pos_x") && |
|
430 (it->first != "arrow_pos_y")) |
|
431 { |
|
432 gwriter.writeEdgeMap(it->first, *(it->second)); |
|
433 } |
|
434 } |
|
435 |
|
436 GuiWriter gui_writer(gwriter, this); |
|
437 |
|
438 gwriter.run(); |
|
439 } |
846 } |
440 |
847 |
441 void MapStorage::clear() |
848 void MapStorage::clear() |
442 { |
849 { |
443 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it = |
850 for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) |
444 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) |
851 { |
445 { |
852 delete it->second; |
446 if ((it->first != "coordinates_x") && |
853 nodemaps.erase(it); |
447 (it->first != "coordinates_y") && |
854 } |
448 (it->first != "label")) |
855 for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it) |
449 { |
856 { |
450 delete it->second; |
857 delete it->second; |
451 nodemap_storage.erase(it); |
858 edgemaps.erase(it); |
452 } |
|
453 } |
|
454 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it = |
|
455 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) |
|
456 { |
|
457 if ((it->first != "label") && |
|
458 (it->first != "arrow_pos_x") && |
|
459 (it->first != "arrow_pos_y")) |
|
460 { |
|
461 delete it->second; |
|
462 edgemap_storage.erase(it); |
|
463 } |
|
464 } |
|
465 for (std::map<std::string, double>::iterator it = |
|
466 nodemap_default.begin(); it != nodemap_default.end(); ++it) |
|
467 { |
|
468 if (it->first != "label") |
|
469 nodemap_default.erase(it); |
|
470 } |
|
471 for (std::map<std::string, double>::iterator it = |
|
472 edgemap_default.begin(); it != edgemap_default.end(); ++it) |
|
473 { |
|
474 if (it->first != "label") |
|
475 edgemap_default.erase(it); |
|
476 } |
859 } |
477 graph.clear(); |
860 graph.clear(); |
478 file_name = ""; |
861 file_name = ""; |
479 modified = false; |
862 modified = false; |
480 |
863 max_node_label = 0; |
481 arrow_pos_read_ok = false; |
864 max_edge_label = 0; |
482 |
865 background_set = false; |
|
866 |
|
867 gui_sect_save_dest = LGF_FILE; |
|
868 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; |
|
869 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; |
|
870 node_coords_one_map_name = "coord"; |
|
871 node_coords_two_maps_1_name = "coord_x"; |
|
872 node_coords_two_maps_2_name = "coord_y"; |
|
873 arrow_coords_one_map_name = "arrow"; |
|
874 arrow_coords_two_maps_1_name = "arrow_x"; |
|
875 arrow_coords_two_maps_2_name = "arrow_y"; |
|
876 |
483 for(int i=0;i<NODE_PROPERTY_NUM;i++) |
877 for(int i=0;i<NODE_PROPERTY_NUM;i++) |
484 { |
878 { |
485 changeActiveMap(false, i, ""); |
879 changeActiveMap(false, i, ""); |
486 signal_map_win.emit(false, i, ""); |
880 signal_map_win.emit(false, i, ""); |
487 } |
881 } |
551 } |
940 } |
552 |
941 |
553 void MapStorage::redesign_data_changed() |
942 void MapStorage::redesign_data_changed() |
554 { |
943 { |
555 signal_design_win.emit(attraction, propulsation, iterations); |
944 signal_design_win.emit(attraction, propulsation, iterations); |
|
945 } |
|
946 |
|
947 XY MapStorage::getNodeCoords(Node n) const |
|
948 { |
|
949 return node_coords[n]; |
|
950 } |
|
951 |
|
952 void MapStorage::setNodeCoords(Node n, XY c) |
|
953 { |
|
954 node_coords.set(n, c); |
|
955 } |
|
956 |
|
957 XY MapStorage::getArrowCoords(Edge e) const |
|
958 { |
|
959 return arrow_coords[e]; |
|
960 } |
|
961 |
|
962 void MapStorage::setArrowCoords(Edge e, XY c) |
|
963 { |
|
964 arrow_coords.set(e, c); |
|
965 } |
|
966 |
|
967 MapValue MapStorage::get(const std::string& name, Node node) const |
|
968 { |
|
969 NodeMapData* data = getNodeMapData(name); |
|
970 return data->get(node); |
|
971 } |
|
972 |
|
973 void MapStorage::set(const std::string& name, Node node, MapValue val) |
|
974 { |
|
975 NodeMapData* data = getNodeMapData(name); |
|
976 data->set(node, val); |
|
977 } |
|
978 |
|
979 MapValue MapStorage::get(const std::string& name, Edge edge) const |
|
980 { |
|
981 EdgeMapData* data = getEdgeMapData(name); |
|
982 return data->get(edge); |
|
983 } |
|
984 |
|
985 void MapStorage::set(const std::string& name, Edge edge, MapValue val) |
|
986 { |
|
987 EdgeMapData* data = getEdgeMapData(name); |
|
988 data->set(edge, val); |
|
989 } |
|
990 |
|
991 const std::string& MapStorage::getFileName() const |
|
992 { |
|
993 return file_name; |
|
994 } |
|
995 |
|
996 void MapStorage::setFileName(const std::string& fn) |
|
997 { |
|
998 file_name = fn; |
|
999 } |
|
1000 |
|
1001 bool MapStorage::getModified() const |
|
1002 { |
|
1003 return modified; |
|
1004 } |
|
1005 |
|
1006 void MapStorage::setModified(bool m) |
|
1007 { |
|
1008 modified = m; |
|
1009 } |
|
1010 |
|
1011 Node MapStorage::addNode(XY coords) |
|
1012 { |
|
1013 Node node = graph.addNode(); |
|
1014 |
|
1015 setNodeCoords(node, coords); |
|
1016 |
|
1017 max_node_label++; |
|
1018 |
|
1019 node_label[node] = max_node_label; |
|
1020 |
|
1021 std::vector<std::string> node_maps = getNodeMapList(); |
|
1022 for (std::vector<std::string>::const_iterator it = node_maps.begin(); |
|
1023 it != node_maps.end(); ++it) |
|
1024 { |
|
1025 NodeMapData* data = getNodeMapData(*it); |
|
1026 set(*it, node, data->default_value); |
|
1027 } |
|
1028 |
|
1029 return node; |
|
1030 } |
|
1031 |
|
1032 Edge MapStorage::addEdge(Node from, Node to) |
|
1033 { |
|
1034 Edge edge = graph.addEdge(from, to); |
|
1035 |
|
1036 if (from == to) |
|
1037 { |
|
1038 setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0)); |
|
1039 } |
|
1040 else |
|
1041 { |
|
1042 setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0); |
|
1043 } |
|
1044 |
|
1045 max_edge_label++; |
|
1046 |
|
1047 edge_label[edge] = max_edge_label; |
|
1048 |
|
1049 std::vector<std::string> edge_maps = getEdgeMapList(); |
|
1050 for (std::vector<std::string>::const_iterator it = edge_maps.begin(); |
|
1051 it != edge_maps.end(); ++it) |
|
1052 { |
|
1053 EdgeMapData* data = getEdgeMapData(*it); |
|
1054 set(*it, edge, data->default_value); |
|
1055 } |
|
1056 return edge; |
|
1057 } |
|
1058 |
|
1059 MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name) |
|
1060 { |
|
1061 NodeMapData* data = getNodeMapData(name); |
|
1062 if (data->type() != MapValue::NUMERIC) |
|
1063 throw Error("Numeric node map " + name + " does not exists."); |
|
1064 return static_cast<NumericNodeMapData*>(data)->map; |
|
1065 } |
|
1066 |
|
1067 MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name) |
|
1068 { |
|
1069 NodeMapData* data = getNodeMapData(name); |
|
1070 if (data->type() != MapValue::STRING) |
|
1071 throw Error("String node map " + name + " does not exists."); |
|
1072 return static_cast<StringNodeMapData*>(data)->map; |
|
1073 } |
|
1074 |
|
1075 MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name) |
|
1076 { |
|
1077 EdgeMapData* data = getEdgeMapData(name); |
|
1078 if (data->type() != MapValue::NUMERIC) |
|
1079 throw Error("Numeric edge map " + name + " does not exists."); |
|
1080 return static_cast<NumericEdgeMapData*>(data)->map; |
|
1081 } |
|
1082 |
|
1083 MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name) |
|
1084 { |
|
1085 EdgeMapData* data = getEdgeMapData(name); |
|
1086 if (data->type() != MapValue::STRING) |
|
1087 throw Error("String edge map " + name + " does not exists."); |
|
1088 return static_cast<StringEdgeMapData*>(data)->map; |
|
1089 } |
|
1090 |
|
1091 MapValueEdgeMap MapStorage::getEdgeMap(const std::string& name) |
|
1092 { |
|
1093 return MapValueEdgeMap(name, this); |
|
1094 } |
|
1095 |
|
1096 MapValueNodeMap MapStorage::getNodeMap(const std::string& name) |
|
1097 { |
|
1098 return MapValueNodeMap(name, this); |
|
1099 } |
|
1100 |
|
1101 int MapStorage::getLabel(Node n) const |
|
1102 { |
|
1103 return node_label[n]; |
|
1104 } |
|
1105 |
|
1106 int MapStorage::getLabel(Edge e) const |
|
1107 { |
|
1108 return edge_label[e]; |
|
1109 } |
|
1110 |
|
1111 MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation() |
|
1112 { |
|
1113 return gui_sect_save_dest; |
|
1114 } |
|
1115 |
|
1116 void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest) |
|
1117 { |
|
1118 gui_sect_save_dest = dest; |
|
1119 } |
|
1120 |
|
1121 MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const |
|
1122 { |
|
1123 NodeMapData *data = getNodeMapData(name); |
|
1124 return data->save_dest; |
|
1125 } |
|
1126 |
|
1127 MapStorage::MapSaveDest MapStorage::getEdgeMapSaveDest(std::string name) const |
|
1128 { |
|
1129 EdgeMapData *data = getEdgeMapData(name); |
|
1130 return data->save_dest; |
|
1131 } |
|
1132 |
|
1133 void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest) |
|
1134 { |
|
1135 NodeMapData *data = getNodeMapData(name); |
|
1136 data->save_dest = dest; |
|
1137 } |
|
1138 |
|
1139 void MapStorage::setEdgeMapSaveDest(std::string name, MapStorage::MapSaveDest dest) |
|
1140 { |
|
1141 EdgeMapData *data = getEdgeMapData(name); |
|
1142 data->save_dest = dest; |
|
1143 } |
|
1144 |
|
1145 MapStorage::EdgeMapData* MapStorage::getEdgeMapData(std::string name) const |
|
1146 { |
|
1147 EdgeMapStore::const_iterator it = edgemaps.find(name); |
|
1148 if (it != edgemaps.end()) |
|
1149 return it->second; |
|
1150 else |
|
1151 throw Error("Edge map " + name + " does not exists."); |
|
1152 } |
|
1153 |
|
1154 MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const |
|
1155 { |
|
1156 NodeMapStore::const_iterator it = nodemaps.find(name); |
|
1157 if (it != nodemaps.end()) |
|
1158 return it->second; |
|
1159 else |
|
1160 throw Error("Node map " + name + " does not exists."); |
|
1161 } |
|
1162 |
|
1163 MapValue::Type MapStorage::getNodeMapElementType(std::string name) const |
|
1164 { |
|
1165 NodeMapData *data = getNodeMapData(name); |
|
1166 return data->type(); |
|
1167 } |
|
1168 |
|
1169 MapValue::Type MapStorage::getEdgeMapElementType(std::string name) const |
|
1170 { |
|
1171 EdgeMapData *data = getEdgeMapData(name); |
|
1172 return data->type(); |
|
1173 } |
|
1174 |
|
1175 const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap() |
|
1176 { |
|
1177 return node_label; |
|
1178 } |
|
1179 |
|
1180 const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap() |
|
1181 { |
|
1182 return edge_label; |
|
1183 } |
|
1184 |
|
1185 const Graph& MapStorage::getGraph() |
|
1186 { |
|
1187 return graph; |
|
1188 } |
|
1189 |
|
1190 bool MapStorage::nodeMapExists(std::string name) |
|
1191 { |
|
1192 NodeMapStore::const_iterator it = nodemaps.find(name); |
|
1193 if (it == nodemaps.end()) |
|
1194 return false; |
|
1195 else |
|
1196 return true; |
|
1197 } |
|
1198 |
|
1199 bool MapStorage::edgeMapExists(std::string name) |
|
1200 { |
|
1201 EdgeMapStore::const_iterator it = edgemaps.find(name); |
|
1202 if (it == edgemaps.end()) |
|
1203 return false; |
|
1204 else |
|
1205 return true; |
|
1206 } |
|
1207 |
|
1208 std::vector<std::string> MapStorage::getEdgeMaps(MapType type) |
|
1209 { |
|
1210 std::vector<std::string> maps; |
|
1211 for (EdgeMapStore::const_iterator it = edgemaps.begin(); it != edgemaps.end(); ++it) |
|
1212 { |
|
1213 if (it->second->type() & type) |
|
1214 { |
|
1215 maps.push_back(it->first); |
|
1216 } |
|
1217 } |
|
1218 return maps; |
|
1219 } |
|
1220 |
|
1221 std::vector<std::string> MapStorage::getNodeMaps(MapType type) |
|
1222 { |
|
1223 std::vector<std::string> maps; |
|
1224 for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) |
|
1225 { |
|
1226 if (it->second->type() & type) |
|
1227 { |
|
1228 maps.push_back(it->first); |
|
1229 } |
|
1230 } |
|
1231 return maps; |
|
1232 } |
|
1233 |
|
1234 MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap() |
|
1235 { |
|
1236 return node_coords; |
|
1237 } |
|
1238 |
|
1239 MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap() |
|
1240 { |
|
1241 return arrow_coords; |
|
1242 } |
|
1243 |
|
1244 MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest() |
|
1245 { |
|
1246 return node_coords_save_dest; |
|
1247 } |
|
1248 |
|
1249 MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest() |
|
1250 { |
|
1251 return arrow_coords_save_dest; |
|
1252 } |
|
1253 |
|
1254 void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) |
|
1255 { |
|
1256 node_coords_save_dest = dest; |
|
1257 } |
|
1258 |
|
1259 void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) |
|
1260 { |
|
1261 arrow_coords_save_dest = dest; |
|
1262 } |
|
1263 |
|
1264 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum() |
|
1265 { |
|
1266 return node_coords_save_map_num; |
|
1267 } |
|
1268 |
|
1269 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum() |
|
1270 { |
|
1271 return arrow_coords_save_map_num; |
|
1272 } |
|
1273 |
|
1274 void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) |
|
1275 { |
|
1276 node_coords_save_map_num = num; |
|
1277 } |
|
1278 |
|
1279 void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) |
|
1280 { |
|
1281 arrow_coords_save_map_num = num; |
|
1282 } |
|
1283 |
|
1284 const std::string& MapStorage::getNodeCoordsOneMapName() |
|
1285 { |
|
1286 return node_coords_one_map_name; |
|
1287 } |
|
1288 const std::string& MapStorage::getNodeCoordsTwoMaps1Name() |
|
1289 { |
|
1290 return node_coords_two_maps_1_name; |
|
1291 } |
|
1292 const std::string& MapStorage::getNodeCoordsTwoMaps2Name() |
|
1293 { |
|
1294 return node_coords_two_maps_2_name; |
|
1295 } |
|
1296 |
|
1297 void MapStorage::setNodeCoordsOneMapName(const std::string& name) |
|
1298 { |
|
1299 node_coords_one_map_name = name; |
|
1300 } |
|
1301 void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name) |
|
1302 { |
|
1303 node_coords_two_maps_1_name = name; |
|
1304 } |
|
1305 void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name) |
|
1306 { |
|
1307 node_coords_two_maps_2_name = name; |
|
1308 } |
|
1309 |
|
1310 const std::string& MapStorage::getArrowCoordsOneMapName() |
|
1311 { |
|
1312 return arrow_coords_one_map_name; |
|
1313 } |
|
1314 const std::string& MapStorage::getArrowCoordsTwoMaps1Name() |
|
1315 { |
|
1316 return arrow_coords_two_maps_1_name; |
|
1317 } |
|
1318 const std::string& MapStorage::getArrowCoordsTwoMaps2Name() |
|
1319 { |
|
1320 return arrow_coords_two_maps_2_name; |
|
1321 } |
|
1322 |
|
1323 void MapStorage::setArrowCoordsOneMapName(const std::string& name) |
|
1324 { |
|
1325 arrow_coords_one_map_name = name; |
|
1326 } |
|
1327 void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name) |
|
1328 { |
|
1329 arrow_coords_two_maps_1_name = name; |
|
1330 } |
|
1331 void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name) |
|
1332 { |
|
1333 arrow_coords_two_maps_2_name = name; |
|
1334 } |
|
1335 |
|
1336 void MapStorage::readLGF( |
|
1337 const std::string& filename, |
|
1338 bool read_edge_label, |
|
1339 const std::vector<std::string>& node_map_names, |
|
1340 const std::vector<std::string>& edge_map_names, |
|
1341 const std::map<std::string, MapValue::Type>& node_map_types, |
|
1342 const std::map<std::string, MapValue::Type>& edge_map_types, |
|
1343 const std::string& node_coord_xmap_name, |
|
1344 const std::string& node_coord_ymap_name, |
|
1345 const std::string& arrow_coord_xmap_name, |
|
1346 const std::string& arrow_coord_ymap_name) |
|
1347 { |
|
1348 using std::vector; |
|
1349 using std::map; |
|
1350 using std::string; |
|
1351 |
|
1352 GraphReader<Graph> greader(filename, graph); |
|
1353 |
|
1354 // read the label maps |
|
1355 greader.readNodeMap("label", node_label); |
|
1356 if (read_edge_label) |
|
1357 greader.readEdgeMap("label", edge_label); |
|
1358 |
|
1359 // read the node maps |
|
1360 for (vector<string>::const_iterator |
|
1361 it = node_map_names.begin(); |
|
1362 it != node_map_names.end(); ++it) |
|
1363 { |
|
1364 switch (node_map_types.find(*it)->second) |
|
1365 { |
|
1366 case MapValue::NUMERIC: |
|
1367 { |
|
1368 createNodeMap(*it, MapValue::NUMERIC, double()); |
|
1369 greader.readNodeMap(*it, getNumericNodeMap(*it)); |
|
1370 break; |
|
1371 } |
|
1372 case MapValue::STRING: |
|
1373 { |
|
1374 createNodeMap(*it, MapValue::STRING, string()); |
|
1375 greader.readNodeMap(*it, getStringNodeMap(*it)); |
|
1376 break; |
|
1377 } |
|
1378 } |
|
1379 getNodeMapData(*it)->save_dest = NESET_SECT; |
|
1380 } |
|
1381 |
|
1382 // read the edge maps |
|
1383 for (vector<string>::const_iterator |
|
1384 it = edge_map_names.begin(); |
|
1385 it != edge_map_names.end(); ++it) |
|
1386 { |
|
1387 switch (edge_map_types.find(*it)->second) |
|
1388 { |
|
1389 case MapValue::NUMERIC: |
|
1390 { |
|
1391 createEdgeMap(*it, MapValue::NUMERIC, double()); |
|
1392 greader.readEdgeMap(*it, getNumericEdgeMap(*it)); |
|
1393 break; |
|
1394 } |
|
1395 case MapValue::STRING: |
|
1396 { |
|
1397 createEdgeMap(*it, MapValue::STRING, string()); |
|
1398 greader.readEdgeMap(*it, getStringEdgeMap(*it)); |
|
1399 break; |
|
1400 } |
|
1401 } |
|
1402 getEdgeMapData(*it)->save_dest = NESET_SECT; |
|
1403 } |
|
1404 |
|
1405 // read the node coordinate maps |
|
1406 if (node_coord_xmap_name != "") |
|
1407 greader.readNodeMap(node_coord_xmap_name, node_coords_x); |
|
1408 if (node_coord_ymap_name != "") |
|
1409 greader.readNodeMap(node_coord_ymap_name, node_coords_y); |
|
1410 |
|
1411 // read the arrow coordinate maps |
|
1412 if (arrow_coord_xmap_name != "") |
|
1413 greader.readEdgeMap(arrow_coord_xmap_name, arrow_coords_x); |
|
1414 if (arrow_coord_ymap_name != "") |
|
1415 greader.readEdgeMap(arrow_coord_ymap_name, arrow_coords_y); |
|
1416 |
|
1417 greader.run(); |
556 } |
1418 } |
557 |
1419 |
558 void MapStorage::setBackground(const std::string& file_name) |
1420 void MapStorage::setBackground(const std::string& file_name) |
559 { |
1421 { |
560 if (file_name == background_file_name) return; |
1422 if (file_name == background_file_name) return; |