[174] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
[201] | 10 | * provided that this copyright notice appears in all cop ies. For |
---|
[174] | 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[201] | 19 | #include "i18n.h" |
---|
[128] | 20 | #include <limits> |
---|
| 21 | #include <cmath> |
---|
[201] | 22 | #include <iostream> |
---|
| 23 | #include <fstream> |
---|
| 24 | #include <string> |
---|
| 25 | #include <algorithm> |
---|
[63] | 26 | #include <gtkmm.h> |
---|
[201] | 27 | #include "file_import_dialog.h" |
---|
[194] | 28 | #include <mapstorage.h> |
---|
| 29 | #include <gui_writer.h> |
---|
| 30 | #include <gui_reader.h> |
---|
| 31 | #include <lemon/graph_to_eps.h> |
---|
[77] | 32 | |
---|
[191] | 33 | const int i_d=20; |
---|
[177] | 34 | const double a_d=0.05; |
---|
| 35 | const double p_d=40000; |
---|
| 36 | |
---|
[201] | 37 | MapStorage::MapStorage() : |
---|
| 38 | gui_sect_save_dest(LGF_FILE), |
---|
| 39 | node_coords_save_dest(SpecMapSaveOpts::GUI_SECT), |
---|
| 40 | arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT), |
---|
| 41 | modified(false), |
---|
| 42 | file_name(""), |
---|
| 43 | max_node_label(0), |
---|
| 44 | max_edge_label(0), |
---|
| 45 | node_coords_one_map_name("coord"), |
---|
| 46 | node_coords_two_maps_1_name("coord_x"), |
---|
| 47 | node_coords_two_maps_2_name("coord_y"), |
---|
| 48 | arrow_coords_one_map_name("arrow"), |
---|
| 49 | arrow_coords_two_maps_1_name("arrow_x"), |
---|
| 50 | arrow_coords_two_maps_2_name("arrow_y"), |
---|
| 51 | iterations(i_d), |
---|
| 52 | attraction(a_d), |
---|
| 53 | propulsation(p_d), |
---|
| 54 | node_coords_x(graph), |
---|
| 55 | node_coords_y(graph), |
---|
| 56 | arrow_coords_x(graph), |
---|
| 57 | arrow_coords_y(graph), |
---|
| 58 | node_label(graph), |
---|
| 59 | edge_label(graph), |
---|
| 60 | background_set(false) |
---|
[6] | 61 | { |
---|
[201] | 62 | node_coords.setXMap(node_coords_x); |
---|
| 63 | node_coords.setYMap(node_coords_y); |
---|
| 64 | arrow_coords.setXMap(arrow_coords_x); |
---|
| 65 | arrow_coords.setYMap(arrow_coords_y); |
---|
[94] | 66 | |
---|
| 67 | active_nodemaps.resize(NODE_PROPERTY_NUM); |
---|
| 68 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
| 69 | { |
---|
| 70 | active_nodemaps[i]=""; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | active_edgemaps.resize(EDGE_PROPERTY_NUM); |
---|
| 74 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
| 75 | { |
---|
| 76 | active_edgemaps[i]=""; |
---|
| 77 | } |
---|
[53] | 78 | } |
---|
| 79 | |
---|
| 80 | MapStorage::~MapStorage() |
---|
| 81 | { |
---|
[201] | 82 | clear(); |
---|
[53] | 83 | } |
---|
[6] | 84 | |
---|
[201] | 85 | void MapStorage::createNodeMap(const std::string& name, MapValue::Type type, |
---|
| 86 | MapValue def_val) |
---|
[6] | 87 | { |
---|
[201] | 88 | NodeMapStore::const_iterator it = nodemaps.find(name); |
---|
| 89 | if (it != nodemaps.end()) |
---|
| 90 | throw Error("Node map " + name + " already exists."); |
---|
[108] | 91 | |
---|
[201] | 92 | switch (type) |
---|
| 93 | { |
---|
| 94 | case MapValue::NUMERIC: |
---|
| 95 | nodemaps[name] = new NumericNodeMapData(graph, def_val); |
---|
| 96 | break; |
---|
| 97 | case MapValue::STRING: |
---|
| 98 | nodemaps[name] = new StringNodeMapData(graph, def_val); |
---|
| 99 | break; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | nodemaps[name]->default_value = def_val; |
---|
| 103 | |
---|
| 104 | signal_node_map.emit(name, type); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void MapStorage::createEdgeMap(const std::string& name, MapValue::Type type, |
---|
| 108 | MapValue def_val) |
---|
| 109 | { |
---|
| 110 | EdgeMapStore::const_iterator it = edgemaps.find(name); |
---|
| 111 | if (it != edgemaps.end()) |
---|
| 112 | throw Error("Edge map " + name + " already exists."); |
---|
| 113 | |
---|
| 114 | switch (type) |
---|
| 115 | { |
---|
| 116 | case MapValue::NUMERIC: |
---|
| 117 | edgemaps[name] = new NumericEdgeMapData(graph, def_val); |
---|
| 118 | break; |
---|
| 119 | case MapValue::STRING: |
---|
| 120 | edgemaps[name] = new StringEdgeMapData(graph, def_val); |
---|
| 121 | break; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | edgemaps[name]->default_value = def_val; |
---|
| 125 | |
---|
| 126 | signal_edge_map.emit(name, type); |
---|
[6] | 127 | } |
---|
| 128 | |
---|
[94] | 129 | void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname) |
---|
| 130 | { |
---|
| 131 | if(itisedge) |
---|
| 132 | { |
---|
| 133 | active_edgemaps[prop]=mapname; |
---|
| 134 | } |
---|
| 135 | else |
---|
| 136 | { |
---|
| 137 | active_nodemaps[prop]=mapname; |
---|
| 138 | } |
---|
| 139 | signal_prop.emit(itisedge, prop); |
---|
| 140 | } |
---|
| 141 | |
---|
[172] | 142 | void MapStorage::broadcastActiveMaps() |
---|
| 143 | { |
---|
| 144 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
| 145 | { |
---|
| 146 | signal_map_win.emit(false, i, active_nodemaps[i]); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
| 150 | { |
---|
| 151 | signal_map_win.emit(true, i, active_edgemaps[i]); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[94] | 155 | std::string MapStorage::getActiveEdgeMap(int prop) |
---|
| 156 | { |
---|
| 157 | return active_edgemaps[prop]; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | std::string MapStorage::getActiveNodeMap(int prop) |
---|
| 161 | { |
---|
| 162 | return active_nodemaps[prop]; |
---|
| 163 | } |
---|
| 164 | |
---|
[201] | 165 | std::vector<std::string> MapStorage::getEdgeMapList(MapType type) |
---|
[94] | 166 | { |
---|
[201] | 167 | if (type == ALL) |
---|
| 168 | { |
---|
| 169 | std::vector<std::string> ret; |
---|
| 170 | for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
---|
| 171 | it != edgemaps.end(); ++it) |
---|
[94] | 172 | { |
---|
[201] | 173 | ret.push_back(it->first); |
---|
[94] | 174 | } |
---|
[201] | 175 | return ret; |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | std::vector<std::string> ret; |
---|
| 180 | for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
---|
| 181 | it != edgemaps.end(); ++it) |
---|
| 182 | { |
---|
| 183 | EdgeMapData* data = getEdgeMapData(it->first); |
---|
| 184 | MapValue::Type t = data->type(); |
---|
| 185 | if ((t == MapValue::NUMERIC && (type & NUM)) || |
---|
| 186 | (t == MapValue::STRING && (type & STR))) |
---|
| 187 | { |
---|
| 188 | ret.push_back(it->first); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | return ret; |
---|
| 192 | } |
---|
[94] | 193 | } |
---|
| 194 | |
---|
[201] | 195 | std::vector<std::string> MapStorage::getNodeMapList(MapType type) |
---|
[94] | 196 | { |
---|
[201] | 197 | if (type == ALL) |
---|
| 198 | { |
---|
| 199 | std::vector<std::string> ret; |
---|
| 200 | for (NodeMapStore::const_iterator it = nodemaps.begin(); |
---|
| 201 | it != nodemaps.end(); ++it) |
---|
[94] | 202 | { |
---|
[201] | 203 | ret.push_back(it->first); |
---|
[94] | 204 | } |
---|
[201] | 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 | } |
---|
[94] | 223 | } |
---|
| 224 | |
---|
[177] | 225 | sigc::signal<void, bool, int> MapStorage::signal_prop_ch() |
---|
[94] | 226 | { |
---|
| 227 | return signal_prop; |
---|
| 228 | } |
---|
| 229 | |
---|
[201] | 230 | int MapStorage::readFromFile(const std::string &filename) |
---|
[6] | 231 | { |
---|
[201] | 232 | using std::vector; |
---|
| 233 | using std::map; |
---|
| 234 | using std::string; |
---|
| 235 | |
---|
| 236 | // check whether the .conf file exists |
---|
| 237 | bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(), |
---|
| 238 | (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)); |
---|
| 239 | |
---|
| 240 | // check whether the .lgf file contains a gui section |
---|
| 241 | bool gui_data_in_lgf = false; |
---|
| 242 | { |
---|
| 243 | std::ifstream ifs(filename.c_str()); |
---|
| 244 | std::string line; |
---|
| 245 | while (getline(ifs, line)) |
---|
[46] | 246 | { |
---|
[201] | 247 | int pos = line.find("@gui"); |
---|
| 248 | if (pos != std::string::npos) |
---|
| 249 | { |
---|
| 250 | bool only_whitespace_before = true; |
---|
| 251 | for (int i = 0; i < pos; ++i) |
---|
| 252 | { |
---|
| 253 | if (!std::isspace(line[i])) |
---|
| 254 | { |
---|
| 255 | only_whitespace_before = false; |
---|
| 256 | break; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | if (only_whitespace_before) gui_data_in_lgf = true; |
---|
| 260 | } |
---|
[6] | 261 | } |
---|
| 262 | } |
---|
| 263 | |
---|
[201] | 264 | bool gui_data_found = gui_data_in_lgf || gui_data_in_conf; |
---|
| 265 | |
---|
| 266 | // ask for user input if both exist |
---|
| 267 | bool use_gui_data_in_lgf = false; |
---|
| 268 | if (gui_data_in_conf && gui_data_in_lgf) |
---|
[6] | 269 | { |
---|
[201] | 270 | Gtk::MessageDialog mdialog(_("<b>Found both ") + filename + |
---|
| 271 | _(".conf and a gui section in ") + filename + _(".</b>"), true, |
---|
| 272 | Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE); |
---|
| 273 | mdialog.add_button(_("Use the ._conf file"), 1); |
---|
| 274 | mdialog.add_button(_("Use the _gui section"), 2); |
---|
| 275 | switch (mdialog.run()) |
---|
[6] | 276 | { |
---|
[201] | 277 | case 1: |
---|
| 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; |
---|
[6] | 285 | } |
---|
| 286 | } |
---|
[201] | 287 | else |
---|
| 288 | { |
---|
| 289 | use_gui_data_in_lgf = gui_data_in_lgf; |
---|
| 290 | } |
---|
[6] | 291 | |
---|
[201] | 292 | if (gui_data_found) |
---|
| 293 | { |
---|
| 294 | GUISectData gui_data; |
---|
| 295 | if (use_gui_data_in_lgf) |
---|
[58] | 296 | { |
---|
[201] | 297 | // read the gui section from the .lgf file |
---|
| 298 | try |
---|
| 299 | { |
---|
| 300 | LemonReader lreader(filename); |
---|
| 301 | GuiReader gui_reader(lreader, this, gui_data); |
---|
| 302 | lreader.run(); |
---|
| 303 | gui_sect_save_dest = LGF_FILE; |
---|
| 304 | } |
---|
| 305 | catch (Exception& error) |
---|
| 306 | { |
---|
| 307 | clear(); |
---|
| 308 | return 1; |
---|
| 309 | } |
---|
[58] | 310 | } |
---|
[201] | 311 | else |
---|
[58] | 312 | { |
---|
[201] | 313 | // read the gui section from the .conf file |
---|
| 314 | try |
---|
| 315 | { |
---|
| 316 | LemonReader lreader(filename + ".conf"); |
---|
| 317 | GuiReader gui_reader(lreader, this, gui_data); |
---|
| 318 | lreader.run(); |
---|
| 319 | gui_sect_save_dest = CONF_FILE; |
---|
| 320 | } |
---|
| 321 | catch (Exception& error) |
---|
| 322 | { |
---|
| 323 | clear(); |
---|
| 324 | return 1; |
---|
| 325 | } |
---|
[58] | 326 | } |
---|
[201] | 327 | |
---|
| 328 | // read the graph and maps form the .lgf file |
---|
| 329 | try |
---|
[6] | 330 | { |
---|
[201] | 331 | std::string node_coord_xmap_name, node_coord_ymap_name; |
---|
| 332 | std::string arrow_coord_xmap_name, arrow_coord_ymap_name; |
---|
| 333 | |
---|
| 334 | if (gui_data.node_coords_save_dest == |
---|
| 335 | MapStorage::SpecMapSaveOpts::NESET_SECT) |
---|
| 336 | { |
---|
| 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); |
---|
[6] | 382 | } |
---|
[201] | 383 | catch (Exception& error) |
---|
[58] | 384 | { |
---|
[101] | 385 | clear(); |
---|
| 386 | return 1; |
---|
| 387 | } |
---|
| 388 | |
---|
[201] | 389 | // add the maps from the gui section |
---|
| 390 | for (vector<string>::const_iterator |
---|
| 391 | it = gui_data.gui_node_map_names.begin(); |
---|
| 392 | it != gui_data.gui_node_map_names.end(); ++it) |
---|
[101] | 393 | { |
---|
[201] | 394 | string map_name = *it; |
---|
| 395 | switch (gui_data.node_map_types[map_name]) |
---|
| 396 | { |
---|
| 397 | case MapValue::NUMERIC: |
---|
| 398 | { |
---|
| 399 | createNodeMap(map_name, MapValue::NUMERIC, double()); |
---|
| 400 | NumericNodeMap& dmap = getNumericNodeMap(map_name); |
---|
| 401 | map<int, double>& smap = *gui_data.numeric_node_maps[map_name]; |
---|
| 402 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
| 403 | { |
---|
| 404 | dmap[n] = smap[node_label[n]]; |
---|
| 405 | } |
---|
| 406 | break; |
---|
| 407 | } |
---|
| 408 | case MapValue::STRING: |
---|
| 409 | { |
---|
| 410 | createNodeMap(map_name, MapValue::STRING, string()); |
---|
| 411 | StringNodeMap& dmap = getStringNodeMap(map_name); |
---|
| 412 | map<int, string>& smap = *gui_data.string_node_maps[map_name]; |
---|
| 413 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
| 414 | { |
---|
| 415 | dmap[n] = smap[node_label[n]]; |
---|
| 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; |
---|
[101] | 453 | } |
---|
| 454 | |
---|
[201] | 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 | } |
---|
[53] | 493 | |
---|
[201] | 494 | if (content.nodeSetNum() < 1) |
---|
[53] | 495 | { |
---|
[201] | 496 | Gtk::MessageDialog mdialog("No nodeset found in file."); |
---|
| 497 | mdialog.run(); |
---|
| 498 | clear(); |
---|
| 499 | return 1; |
---|
[53] | 500 | } |
---|
[201] | 501 | |
---|
| 502 | if (content.edgeSetNum() < 1) |
---|
[53] | 503 | { |
---|
[201] | 504 | Gtk::MessageDialog mdialog("No edgeset found in file."); |
---|
| 505 | mdialog.run(); |
---|
| 506 | clear(); |
---|
| 507 | return 1; |
---|
[53] | 508 | } |
---|
[201] | 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()) |
---|
[53] | 516 | { |
---|
[201] | 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 | } |
---|
[53] | 686 | } |
---|
| 687 | else |
---|
| 688 | { |
---|
[201] | 689 | clear(); |
---|
| 690 | return 1; |
---|
[151] | 691 | } |
---|
[98] | 692 | } |
---|
| 693 | } |
---|
| 694 | |
---|
[201] | 695 | // set max_node_label |
---|
[63] | 696 | { |
---|
[201] | 697 | max_node_label = std::numeric_limits<int>::min(); |
---|
| 698 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
[63] | 699 | { |
---|
[201] | 700 | if (node_label[n] > max_node_label) |
---|
[64] | 701 | { |
---|
[201] | 702 | max_node_label = node_label[n]; |
---|
[64] | 703 | } |
---|
| 704 | } |
---|
[63] | 705 | } |
---|
[201] | 706 | // set max_edge_label |
---|
[63] | 707 | { |
---|
[201] | 708 | max_edge_label = std::numeric_limits<int>::min(); |
---|
| 709 | for (EdgeIt e(graph); e != INVALID; ++e) |
---|
[63] | 710 | { |
---|
[201] | 711 | if (edge_label[e] > max_edge_label) |
---|
[64] | 712 | { |
---|
[201] | 713 | max_edge_label = edge_label[e]; |
---|
[64] | 714 | } |
---|
| 715 | } |
---|
[63] | 716 | } |
---|
| 717 | |
---|
| 718 | return 0; |
---|
[53] | 719 | } |
---|
| 720 | |
---|
| 721 | void MapStorage::writeToFile(const std::string &filename) |
---|
| 722 | { |
---|
[201] | 723 | // relabel nodes and edges |
---|
| 724 | int i = 0; |
---|
| 725 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
| 726 | { |
---|
| 727 | node_label[n] = i++; |
---|
| 728 | } |
---|
| 729 | max_node_label = i-1; |
---|
| 730 | i = 0; |
---|
| 731 | for (EdgeIt e(graph); e != INVALID; ++e) |
---|
| 732 | { |
---|
| 733 | edge_label[e] = i++; |
---|
| 734 | } |
---|
| 735 | max_edge_label = i-1; |
---|
[53] | 736 | |
---|
[201] | 737 | // write .lgf file |
---|
[53] | 738 | { |
---|
[201] | 739 | GraphWriter<Graph> gwriter(filename, graph); |
---|
| 740 | |
---|
| 741 | gwriter.writeNodeMap("label", node_label); |
---|
| 742 | gwriter.writeEdgeMap("label", edge_label); |
---|
| 743 | |
---|
| 744 | // write node maps |
---|
| 745 | for (NodeMapStore::const_iterator it = nodemaps.begin(); |
---|
| 746 | it != nodemaps.end(); ++it) |
---|
[98] | 747 | { |
---|
[201] | 748 | if (it->second->save_dest == NESET_SECT) |
---|
| 749 | { |
---|
| 750 | switch (it->second->type()) |
---|
| 751 | { |
---|
| 752 | case MapValue::NUMERIC: |
---|
| 753 | gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first)); |
---|
| 754 | break; |
---|
| 755 | case MapValue::STRING: |
---|
| 756 | gwriter.writeNodeMap(it->first, getStringNodeMap(it->first)); |
---|
| 757 | break; |
---|
| 758 | } |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | // write edge maps |
---|
| 763 | for (EdgeMapStore::const_iterator it = edgemaps.begin(); |
---|
| 764 | it != edgemaps.end(); ++it) |
---|
| 765 | { |
---|
| 766 | if (it->second->save_dest == NESET_SECT) |
---|
| 767 | { |
---|
| 768 | switch (it->second->type()) |
---|
| 769 | { |
---|
| 770 | case MapValue::NUMERIC: |
---|
| 771 | gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first)); |
---|
| 772 | break; |
---|
| 773 | case MapValue::STRING: |
---|
| 774 | gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first)); |
---|
| 775 | break; |
---|
| 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(); |
---|
| 832 | } |
---|
| 833 | else |
---|
| 834 | { |
---|
| 835 | gwriter.run(); |
---|
[98] | 836 | } |
---|
[53] | 837 | } |
---|
[98] | 838 | |
---|
[201] | 839 | // write .conf file |
---|
| 840 | if (gui_sect_save_dest == CONF_FILE) |
---|
| 841 | { |
---|
| 842 | LemonWriter lwriter(filename + ".conf"); |
---|
| 843 | GuiWriter gui_writer(lwriter, this); |
---|
| 844 | lwriter.run(); |
---|
| 845 | } |
---|
[53] | 846 | } |
---|
| 847 | |
---|
| 848 | void MapStorage::clear() |
---|
| 849 | { |
---|
[201] | 850 | for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) |
---|
[53] | 851 | { |
---|
[201] | 852 | delete it->second; |
---|
| 853 | nodemaps.erase(it); |
---|
[53] | 854 | } |
---|
[201] | 855 | for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it) |
---|
[53] | 856 | { |
---|
[201] | 857 | delete it->second; |
---|
| 858 | edgemaps.erase(it); |
---|
[63] | 859 | } |
---|
[53] | 860 | graph.clear(); |
---|
| 861 | file_name = ""; |
---|
| 862 | modified = false; |
---|
[201] | 863 | max_node_label = 0; |
---|
| 864 | max_edge_label = 0; |
---|
| 865 | background_set = false; |
---|
[172] | 866 | |
---|
[201] | 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 | |
---|
[172] | 877 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
| 878 | { |
---|
| 879 | changeActiveMap(false, i, ""); |
---|
| 880 | signal_map_win.emit(false, i, ""); |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
| 884 | { |
---|
| 885 | changeActiveMap(true, i, ""); |
---|
| 886 | signal_map_win.emit(true, i, ""); |
---|
| 887 | } |
---|
[177] | 888 | |
---|
| 889 | attraction=a_d; |
---|
| 890 | propulsation=p_d; |
---|
| 891 | iterations=i_d; |
---|
| 892 | |
---|
| 893 | signal_design_win.emit(attraction, propulsation, iterations); |
---|
[53] | 894 | } |
---|
[98] | 895 | |
---|
[111] | 896 | void MapStorage::mapChanged(bool itisedge, std::string mapname) |
---|
| 897 | { |
---|
| 898 | if(itisedge) |
---|
[201] | 899 | { |
---|
| 900 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
[111] | 901 | { |
---|
[201] | 902 | if(active_edgemaps[i]==mapname) |
---|
| 903 | { |
---|
| 904 | signal_prop.emit(itisedge, i); |
---|
| 905 | } |
---|
[111] | 906 | } |
---|
[201] | 907 | } |
---|
[111] | 908 | else |
---|
[201] | 909 | { |
---|
| 910 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
[111] | 911 | { |
---|
[201] | 912 | if(active_nodemaps[i]==mapname) |
---|
| 913 | { |
---|
| 914 | signal_prop.emit(itisedge, i); |
---|
| 915 | } |
---|
[111] | 916 | } |
---|
[201] | 917 | } |
---|
[111] | 918 | } |
---|
[177] | 919 | |
---|
| 920 | void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p) |
---|
| 921 | { |
---|
| 922 | attraction_p=attraction; |
---|
| 923 | propulsation_p=propulsation; |
---|
| 924 | iterations_p=iterations; |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | void MapStorage::set_attraction(double attraction_p) |
---|
| 928 | { |
---|
| 929 | attraction=attraction_p; |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | void MapStorage::set_propulsation(double propulsation_p) |
---|
| 933 | { |
---|
| 934 | propulsation=propulsation_p; |
---|
| 935 | } |
---|
| 936 | |
---|
| 937 | void MapStorage::set_iteration(int iterations_p) |
---|
| 938 | { |
---|
| 939 | iterations=iterations_p; |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | void MapStorage::redesign_data_changed() |
---|
| 943 | { |
---|
| 944 | signal_design_win.emit(attraction, propulsation, iterations); |
---|
| 945 | } |
---|
[184] | 946 | |
---|
[201] | 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(); |
---|
| 1418 | } |
---|
| 1419 | |
---|
[184] | 1420 | void MapStorage::setBackground(const std::string& file_name) |
---|
| 1421 | { |
---|
| 1422 | if (file_name == background_file_name) return; |
---|
| 1423 | if (file_name == "") |
---|
| 1424 | { |
---|
| 1425 | background_file_name = ""; |
---|
| 1426 | background_set = false; |
---|
| 1427 | } |
---|
| 1428 | else |
---|
| 1429 | { |
---|
| 1430 | background_file_name = file_name; |
---|
| 1431 | background_set = true; |
---|
| 1432 | } |
---|
[195] | 1433 | signal_background.emit(); |
---|
[184] | 1434 | } |
---|
| 1435 | |
---|
| 1436 | const std::string& MapStorage::getBackgroundFilename() |
---|
| 1437 | { |
---|
| 1438 | return background_file_name; |
---|
| 1439 | } |
---|
| 1440 | |
---|
| 1441 | bool MapStorage::isBackgroundSet() |
---|
| 1442 | { |
---|
| 1443 | return background_set; |
---|
| 1444 | } |
---|
| 1445 | |
---|
| 1446 | double MapStorage::getBackgroundScaling() |
---|
| 1447 | { |
---|
| 1448 | return background_scaling; |
---|
| 1449 | } |
---|
| 1450 | |
---|
| 1451 | void MapStorage::setBackgroundScaling(double scaling) |
---|
| 1452 | { |
---|
| 1453 | background_scaling = scaling; |
---|
| 1454 | } |
---|
[191] | 1455 | |
---|
[198] | 1456 | void MapStorage::exportGraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap) |
---|
[191] | 1457 | { |
---|
[198] | 1458 | Graph::NodeMap<int> _shapes(graph, 0); |
---|
[191] | 1459 | Graph::NodeMap<int> _nodeColors(graph, 0); |
---|
| 1460 | Graph::EdgeMap<int> _edgeColors(graph, 0); |
---|
| 1461 | Graph::NodeMap<double> _nodeSizes(graph, 6.0); |
---|
| 1462 | Graph::EdgeMap<double> _edgeWidths(graph, 1.0); |
---|
| 1463 | bool _drawArrows=options[ARROWS]; |
---|
| 1464 | bool _enableParallel=options[PAR]; |
---|
| 1465 | |
---|
| 1466 | std::string emptyString=""; |
---|
| 1467 | Graph::NodeMap<std::string> _nodeTextMap(graph,emptyString); |
---|
| 1468 | |
---|
| 1469 | //_nodeTextMap=(Graph::NodeMap<void> *)&emptyStringMap; |
---|
| 1470 | |
---|
| 1471 | if(options[N_MAPS]) |
---|
| 1472 | { |
---|
| 1473 | if(active_nodemaps[N_RADIUS]!="") |
---|
| 1474 | { |
---|
[201] | 1475 | _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]); |
---|
[191] | 1476 | } |
---|
| 1477 | if(active_nodemaps[N_COLOR]!="") |
---|
| 1478 | { |
---|
| 1479 | for(NodeIt ni(graph);ni!=INVALID;++ni) |
---|
| 1480 | { |
---|
[201] | 1481 | _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni); |
---|
[191] | 1482 | } |
---|
| 1483 | } |
---|
| 1484 | if(active_nodemaps[N_TEXT]!="") |
---|
| 1485 | { |
---|
| 1486 | for(NodeIt ni(graph);ni!=INVALID;++ni) |
---|
| 1487 | { |
---|
| 1488 | std::ostringstream o; |
---|
[201] | 1489 | o << get(active_nodemaps[N_TEXT], ni); |
---|
[191] | 1490 | _nodeTextMap[ni]=o.str(); |
---|
| 1491 | } |
---|
| 1492 | } |
---|
| 1493 | } |
---|
| 1494 | if(options[E_MAPS]) |
---|
| 1495 | { |
---|
| 1496 | if(active_edgemaps[E_WIDTH]!="") |
---|
| 1497 | { |
---|
[201] | 1498 | _edgeWidths=getNumericEdgeMap(active_edgemaps[E_WIDTH]); |
---|
[191] | 1499 | } |
---|
| 1500 | if(active_edgemaps[E_COLOR]!="") |
---|
| 1501 | { |
---|
| 1502 | for(EdgeIt ei(graph);ei!=INVALID;++ei) |
---|
| 1503 | { |
---|
[201] | 1504 | _edgeColors[ei]=(int)get(active_edgemaps[E_COLOR], ei); |
---|
[191] | 1505 | } |
---|
| 1506 | } |
---|
| 1507 | } |
---|
[199] | 1508 | if(shapemap!="Default values") |
---|
[198] | 1509 | { |
---|
[201] | 1510 | double min = std::numeric_limits<double>::max(); |
---|
| 1511 | double max = std::numeric_limits<double>::min(); |
---|
| 1512 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
| 1513 | { |
---|
| 1514 | double v = static_cast<double>(get(shapemap, n)); |
---|
| 1515 | if (v < min) min = v; |
---|
| 1516 | if (v > max) max = v; |
---|
| 1517 | } |
---|
| 1518 | if((min>=0)&&(max<=4)) |
---|
[198] | 1519 | { |
---|
[201] | 1520 | NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map; |
---|
| 1521 | for (NodeIt n(graph); n != INVALID; ++n) |
---|
| 1522 | { |
---|
| 1523 | _shapes[n] = static_cast<int>(map[n]); |
---|
| 1524 | } |
---|
[198] | 1525 | } |
---|
| 1526 | } |
---|
[191] | 1527 | |
---|
| 1528 | Palette palette; |
---|
| 1529 | Palette paletteW(true); |
---|
| 1530 | |
---|
| 1531 | graphToEps(graph,filename). |
---|
| 1532 | title("Sample .eps figure (fits to A4)"). |
---|
| 1533 | copyright("(C) 2006 LEMON Project"). |
---|
| 1534 | absoluteNodeSizes().absoluteEdgeWidths(). |
---|
| 1535 | nodeScale(2).nodeSizes(_nodeSizes). |
---|
[201] | 1536 | coords(node_coords). |
---|
[198] | 1537 | nodeShapes(_shapes). |
---|
[191] | 1538 | nodeColors(composeMap(paletteW,_nodeColors)). |
---|
| 1539 | edgeColors(composeMap(palette,_edgeColors)). |
---|
| 1540 | edgeWidthScale(0.3).edgeWidths(_edgeWidths). |
---|
| 1541 | nodeTexts(_nodeTextMap).nodeTextSize(7). |
---|
[198] | 1542 | enableParallel(_enableParallel).parEdgeDist(5). |
---|
[191] | 1543 | drawArrows(_drawArrows).arrowWidth(7).arrowLength(7). |
---|
| 1544 | run(); |
---|
| 1545 | |
---|
| 1546 | } |
---|