Added missing include.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all cop ies. For
11 * precise terms see the accompanying LICENSE file.
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
27 #include "file_import_dialog.h"
28 #include <mapstorage.h>
29 #include <gui_writer.h>
30 #include <gui_reader.h>
31 #include <lemon/graph_to_eps.h>
34 const double a_d=0.05;
35 const double p_d=40000;
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),
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"),
56 arrow_coords_x(graph),
57 arrow_coords_y(graph),
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);
67 active_nodemaps.resize(NODE_PROPERTY_NUM);
68 for(int i=0;i<NODE_PROPERTY_NUM;i++)
70 active_nodemaps[i]="";
73 active_edgemaps.resize(EDGE_PROPERTY_NUM);
74 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
76 active_edgemaps[i]="";
80 MapStorage::~MapStorage()
85 void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
88 NodeMapStore::const_iterator it = nodemaps.find(name);
89 if (it != nodemaps.end())
90 throw Error("Node map " + name + " already exists.");
94 case MapValue::NUMERIC:
95 nodemaps[name] = new NumericNodeMapData(graph, def_val);
97 case MapValue::STRING:
98 nodemaps[name] = new StringNodeMapData(graph, def_val);
102 nodemaps[name]->default_value = def_val;
104 signal_node_map.emit(name, type);
107 void MapStorage::createEdgeMap(const std::string& name, MapValue::Type type,
110 EdgeMapStore::const_iterator it = edgemaps.find(name);
111 if (it != edgemaps.end())
112 throw Error("Edge map " + name + " already exists.");
116 case MapValue::NUMERIC:
117 edgemaps[name] = new NumericEdgeMapData(graph, def_val);
119 case MapValue::STRING:
120 edgemaps[name] = new StringEdgeMapData(graph, def_val);
124 edgemaps[name]->default_value = def_val;
126 signal_edge_map.emit(name, type);
129 void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname)
133 active_edgemaps[prop]=mapname;
137 active_nodemaps[prop]=mapname;
139 signal_prop.emit(itisedge, prop);
142 void MapStorage::broadcastActiveMaps()
144 for(int i=0;i<NODE_PROPERTY_NUM;i++)
146 signal_map_win.emit(false, i, active_nodemaps[i]);
149 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
151 signal_map_win.emit(true, i, active_edgemaps[i]);
155 std::string MapStorage::getActiveEdgeMap(int prop)
157 return active_edgemaps[prop];
160 std::string MapStorage::getActiveNodeMap(int prop)
162 return active_nodemaps[prop];
165 std::vector<std::string> MapStorage::getEdgeMapList(MapType type)
169 std::vector<std::string> ret;
170 for (EdgeMapStore::const_iterator it = edgemaps.begin();
171 it != edgemaps.end(); ++it)
173 ret.push_back(it->first);
179 std::vector<std::string> ret;
180 for (EdgeMapStore::const_iterator it = edgemaps.begin();
181 it != edgemaps.end(); ++it)
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)))
188 ret.push_back(it->first);
195 std::vector<std::string> MapStorage::getNodeMapList(MapType type)
199 std::vector<std::string> ret;
200 for (NodeMapStore::const_iterator it = nodemaps.begin();
201 it != nodemaps.end(); ++it)
203 ret.push_back(it->first);
209 std::vector<std::string> ret;
210 for (NodeMapStore::const_iterator it = nodemaps.begin();
211 it != nodemaps.end(); ++it)
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)))
218 ret.push_back(it->first);
225 sigc::signal<void, bool, int> MapStorage::signal_prop_ch()
230 int MapStorage::readFromFile(const std::string &filename)
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));
240 // check whether the .lgf file contains a gui section
241 bool gui_data_in_lgf = false;
243 std::ifstream ifs(filename.c_str());
245 while (getline(ifs, line))
247 int pos = line.find("@gui");
248 if (pos != std::string::npos)
250 bool only_whitespace_before = true;
251 for (int i = 0; i < pos; ++i)
253 if (!std::isspace(line[i]))
255 only_whitespace_before = false;
259 if (only_whitespace_before) gui_data_in_lgf = true;
264 bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
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)
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())
278 use_gui_data_in_lgf = false;
281 use_gui_data_in_lgf = true;
283 case Gtk::RESPONSE_NONE:
289 use_gui_data_in_lgf = gui_data_in_lgf;
294 GUISectData gui_data;
295 if (use_gui_data_in_lgf)
297 // read the gui section from the .lgf file
300 LemonReader lreader(filename);
301 GuiReader gui_reader(lreader, this, gui_data);
303 gui_sect_save_dest = LGF_FILE;
305 catch (Exception& error)
313 // read the gui section from the .conf file
316 LemonReader lreader(filename + ".conf");
317 GuiReader gui_reader(lreader, this, gui_data);
319 gui_sect_save_dest = CONF_FILE;
321 catch (Exception& error)
328 // read the graph and maps form the .lgf file
331 std::string node_coord_xmap_name, node_coord_ymap_name;
332 std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
334 if (gui_data.node_coords_save_dest ==
335 MapStorage::SpecMapSaveOpts::NESET_SECT)
337 switch (gui_data.node_coords_save_map_num)
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;
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;
351 node_coords_save_dest = gui_data.node_coords_save_dest;
352 node_coords_save_map_num = gui_data.node_coords_save_map_num;
355 if (gui_data.arrow_coords_save_dest ==
356 MapStorage::SpecMapSaveOpts::NESET_SECT)
358 switch (gui_data.arrow_coords_save_map_num)
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;
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;
374 arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
375 arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num;
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);
383 catch (Exception& error)
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)
394 string map_name = *it;
395 switch (gui_data.node_map_types[map_name])
397 case MapValue::NUMERIC:
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)
404 dmap[n] = smap[node_label[n]];
408 case MapValue::STRING:
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)
415 dmap[n] = smap[node_label[n]];
420 getNodeMapData(map_name)->save_dest = GUI_SECT;
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)
426 string map_name = *it;
427 switch (gui_data.edge_map_types[map_name])
429 case MapValue::NUMERIC:
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)
436 dmap[e] = smap[edge_label[e]];
440 case MapValue::STRING:
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)
447 dmap[e] = smap[edge_label[e]];
452 getEdgeMapData(map_name)->save_dest = GUI_SECT;
455 // restore the node coordinate maps
456 if (gui_data.node_coords_save_dest ==
457 MapStorage::SpecMapSaveOpts::GUI_SECT)
459 for (NodeIt n(graph); n != INVALID; ++n)
461 node_coords.set(n, gui_data.node_coord_map[node_label[n]]);
463 node_coords_save_dest = gui_data.node_coords_save_dest;
465 // restore the arrow coordinate maps
466 if (gui_data.arrow_coords_save_dest ==
467 MapStorage::SpecMapSaveOpts::GUI_SECT)
469 for (EdgeIt e(graph); e != INVALID; ++e)
471 arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]);
473 arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
478 // there is no gui section neither in the .lgf file nor in the .conf file
480 LemonReader lreader(filename);
481 ContentReader content(lreader);
486 catch (Exception& error)
488 Gtk::MessageDialog mdialog(error.what());
494 if (content.nodeSetNum() < 1)
496 Gtk::MessageDialog mdialog("No nodeset found in file.");
502 if (content.edgeSetNum() < 1)
504 Gtk::MessageDialog mdialog("No edgeset found in file.");
510 std::vector<std::string> nodeMapNames = content.nodeSetMaps(0);
511 std::vector<std::string> edgeMapNames = content.edgeSetMaps(0);
513 bool read_edge_label = true;
514 if (std::find(edgeMapNames.begin(), edgeMapNames.end(), "label") ==
517 read_edge_label = false;
521 std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"),
525 std::remove(edgeMapNames.begin(), edgeMapNames.end(), "label"),
528 FileImportDialog::ImportData data(nodeMapNames, edgeMapNames);
529 FileImportDialog fidialog(&data);
530 int response = fidialog.run();
531 if (response == Gtk::RESPONSE_OK)
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;
540 switch (data.node_coord_load_from)
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;
547 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
548 node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
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;
556 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
557 node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
559 case FileImportDialog::ImportData::DONT_READ:
560 node_coord_xmap_name = "";
561 node_coord_ymap_name = "";
563 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
564 gen_node_coords = true;
568 switch (data.arrow_coord_load_from)
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;
575 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
576 arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
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;
584 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
585 arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
587 case FileImportDialog::ImportData::DONT_READ:
588 arrow_coord_xmap_name = "";
589 arrow_coord_ymap_name = "";
591 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
592 gen_arrow_coords = true;
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)
605 node_map_names.push_back(*it);
606 node_map_types[*it] = MapValue::NUMERIC;
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)
612 node_map_names.push_back(*it);
613 node_map_types[*it] = MapValue::STRING;
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)
619 edge_map_names.push_back(*it);
620 edge_map_types[*it] = MapValue::NUMERIC;
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)
626 edge_map_names.push_back(*it);
627 edge_map_types[*it] = MapValue::STRING;
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);
636 // generate edge labels
637 if (!read_edge_label)
640 for (EdgeIt e(graph); e != INVALID; ++e)
648 // generate node coordinates
650 for (NodeIt n(graph); n != INVALID; ++n) { node_num++; }
651 const double pi = 3.142;
652 double step = 2 * pi / (double) node_num;
654 for (NodeIt n(graph); n != INVALID; ++n)
657 XY(250.0 * std::cos(i * step),
658 250.0 * std::sin(i * step)));
662 if (gen_arrow_coords)
664 // generate arrow coordinates
665 for (EdgeIt e(graph); e != INVALID; ++e)
667 if (graph.source(e) == graph.target(e))
670 getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
675 (getNodeCoords(graph.source(e)) +
676 getNodeCoords(graph.target(e))) / 2.0);
681 catch (Exception& error)
695 // set max_node_label
697 max_node_label = std::numeric_limits<int>::min();
698 for (NodeIt n(graph); n != INVALID; ++n)
700 if (node_label[n] > max_node_label)
702 max_node_label = node_label[n];
706 // set max_edge_label
708 max_edge_label = std::numeric_limits<int>::min();
709 for (EdgeIt e(graph); e != INVALID; ++e)
711 if (edge_label[e] > max_edge_label)
713 max_edge_label = edge_label[e];
721 void MapStorage::writeToFile(const std::string &filename)
723 // relabel nodes and edges
725 for (NodeIt n(graph); n != INVALID; ++n)
729 max_node_label = i-1;
731 for (EdgeIt e(graph); e != INVALID; ++e)
735 max_edge_label = i-1;
739 GraphWriter<Graph> gwriter(filename, graph);
741 gwriter.writeNodeMap("label", node_label);
742 gwriter.writeEdgeMap("label", edge_label);
745 for (NodeMapStore::const_iterator it = nodemaps.begin();
746 it != nodemaps.end(); ++it)
748 if (it->second->save_dest == NESET_SECT)
750 switch (it->second->type())
752 case MapValue::NUMERIC:
753 gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first));
755 case MapValue::STRING:
756 gwriter.writeNodeMap(it->first, getStringNodeMap(it->first));
763 for (EdgeMapStore::const_iterator it = edgemaps.begin();
764 it != edgemaps.end(); ++it)
766 if (it->second->save_dest == NESET_SECT)
768 switch (it->second->type())
770 case MapValue::NUMERIC:
771 gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first));
773 case MapValue::STRING:
774 gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first));
780 // write node coordinates
781 switch (getNodeCoordsSaveDest())
783 case MapStorage::SpecMapSaveOpts::GUI_SECT:
785 case MapStorage::SpecMapSaveOpts::NESET_SECT:
786 switch (getNodeCoordsSaveMapNum())
788 case MapStorage::SpecMapSaveOpts::ONE_MAP:
789 gwriter.writeNodeMap(node_coords_one_map_name + ":x",
791 gwriter.writeNodeMap(node_coords_one_map_name + ":y",
794 case MapStorage::SpecMapSaveOpts::TWO_MAPS:
795 gwriter.writeNodeMap(node_coords_two_maps_1_name,
797 gwriter.writeNodeMap(node_coords_two_maps_2_name,
804 // write arrow coordinates
805 switch (getArrowCoordsSaveDest())
807 case MapStorage::SpecMapSaveOpts::GUI_SECT:
809 case MapStorage::SpecMapSaveOpts::NESET_SECT:
810 switch (getArrowCoordsSaveMapNum())
812 case MapStorage::SpecMapSaveOpts::ONE_MAP:
813 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x",
815 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y",
818 case MapStorage::SpecMapSaveOpts::TWO_MAPS:
819 gwriter.writeEdgeMap(arrow_coords_two_maps_1_name,
821 gwriter.writeEdgeMap(arrow_coords_two_maps_2_name,
828 if (gui_sect_save_dest == LGF_FILE)
830 GuiWriter gui_writer(gwriter, this);
840 if (gui_sect_save_dest == CONF_FILE)
842 LemonWriter lwriter(filename + ".conf");
843 GuiWriter gui_writer(lwriter, this);
848 void MapStorage::clear()
850 for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
855 for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
865 background_set = false;
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";
877 for(int i=0;i<NODE_PROPERTY_NUM;i++)
879 changeActiveMap(false, i, "");
880 signal_map_win.emit(false, i, "");
883 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
885 changeActiveMap(true, i, "");
886 signal_map_win.emit(true, i, "");
893 signal_design_win.emit(attraction, propulsation, iterations);
896 void MapStorage::mapChanged(bool itisedge, std::string mapname)
900 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
902 if(active_edgemaps[i]==mapname)
904 signal_prop.emit(itisedge, i);
910 for(int i=0;i<NODE_PROPERTY_NUM;i++)
912 if(active_nodemaps[i]==mapname)
914 signal_prop.emit(itisedge, i);
920 void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
922 attraction_p=attraction;
923 propulsation_p=propulsation;
924 iterations_p=iterations;
927 void MapStorage::set_attraction(double attraction_p)
929 attraction=attraction_p;
932 void MapStorage::set_propulsation(double propulsation_p)
934 propulsation=propulsation_p;
937 void MapStorage::set_iteration(int iterations_p)
939 iterations=iterations_p;
942 void MapStorage::redesign_data_changed()
944 signal_design_win.emit(attraction, propulsation, iterations);
947 XY MapStorage::getNodeCoords(Node n) const
949 return node_coords[n];
952 void MapStorage::setNodeCoords(Node n, XY c)
954 node_coords.set(n, c);
957 XY MapStorage::getArrowCoords(Edge e) const
959 return arrow_coords[e];
962 void MapStorage::setArrowCoords(Edge e, XY c)
964 arrow_coords.set(e, c);
967 MapValue MapStorage::get(const std::string& name, Node node) const
969 NodeMapData* data = getNodeMapData(name);
970 return data->get(node);
973 void MapStorage::set(const std::string& name, Node node, MapValue val)
975 NodeMapData* data = getNodeMapData(name);
976 data->set(node, val);
979 MapValue MapStorage::get(const std::string& name, Edge edge) const
981 EdgeMapData* data = getEdgeMapData(name);
982 return data->get(edge);
985 void MapStorage::set(const std::string& name, Edge edge, MapValue val)
987 EdgeMapData* data = getEdgeMapData(name);
988 data->set(edge, val);
991 const std::string& MapStorage::getFileName() const
996 void MapStorage::setFileName(const std::string& fn)
1001 bool MapStorage::getModified() const
1006 void MapStorage::setModified(bool m)
1011 Node MapStorage::addNode(XY coords)
1013 Node node = graph.addNode();
1015 setNodeCoords(node, coords);
1019 node_label[node] = max_node_label;
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)
1025 NodeMapData* data = getNodeMapData(*it);
1026 set(*it, node, data->default_value);
1032 Edge MapStorage::addEdge(Node from, Node to)
1034 Edge edge = graph.addEdge(from, to);
1038 setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0));
1042 setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
1047 edge_label[edge] = max_edge_label;
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)
1053 EdgeMapData* data = getEdgeMapData(*it);
1054 set(*it, edge, data->default_value);
1059 MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
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;
1067 MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
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;
1075 MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name)
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;
1083 MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
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;
1091 MapValueEdgeMap MapStorage::getEdgeMap(const std::string& name)
1093 return MapValueEdgeMap(name, this);
1096 MapValueNodeMap MapStorage::getNodeMap(const std::string& name)
1098 return MapValueNodeMap(name, this);
1101 int MapStorage::getLabel(Node n) const
1103 return node_label[n];
1106 int MapStorage::getLabel(Edge e) const
1108 return edge_label[e];
1111 MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation()
1113 return gui_sect_save_dest;
1116 void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest)
1118 gui_sect_save_dest = dest;
1121 MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const
1123 NodeMapData *data = getNodeMapData(name);
1124 return data->save_dest;
1127 MapStorage::MapSaveDest MapStorage::getEdgeMapSaveDest(std::string name) const
1129 EdgeMapData *data = getEdgeMapData(name);
1130 return data->save_dest;
1133 void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
1135 NodeMapData *data = getNodeMapData(name);
1136 data->save_dest = dest;
1139 void MapStorage::setEdgeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
1141 EdgeMapData *data = getEdgeMapData(name);
1142 data->save_dest = dest;
1145 MapStorage::EdgeMapData* MapStorage::getEdgeMapData(std::string name) const
1147 EdgeMapStore::const_iterator it = edgemaps.find(name);
1148 if (it != edgemaps.end())
1151 throw Error("Edge map " + name + " does not exists.");
1154 MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
1156 NodeMapStore::const_iterator it = nodemaps.find(name);
1157 if (it != nodemaps.end())
1160 throw Error("Node map " + name + " does not exists.");
1163 MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
1165 NodeMapData *data = getNodeMapData(name);
1166 return data->type();
1169 MapValue::Type MapStorage::getEdgeMapElementType(std::string name) const
1171 EdgeMapData *data = getEdgeMapData(name);
1172 return data->type();
1175 const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
1180 const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap()
1185 const Graph& MapStorage::getGraph()
1190 bool MapStorage::nodeMapExists(std::string name)
1192 NodeMapStore::const_iterator it = nodemaps.find(name);
1193 if (it == nodemaps.end())
1199 bool MapStorage::edgeMapExists(std::string name)
1201 EdgeMapStore::const_iterator it = edgemaps.find(name);
1202 if (it == edgemaps.end())
1208 std::vector<std::string> MapStorage::getEdgeMaps(MapType type)
1210 std::vector<std::string> maps;
1211 for (EdgeMapStore::const_iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
1213 if (it->second->type() & type)
1215 maps.push_back(it->first);
1221 std::vector<std::string> MapStorage::getNodeMaps(MapType type)
1223 std::vector<std::string> maps;
1224 for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
1226 if (it->second->type() & type)
1228 maps.push_back(it->first);
1234 MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
1239 MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
1241 return arrow_coords;
1244 MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest()
1246 return node_coords_save_dest;
1249 MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest()
1251 return arrow_coords_save_dest;
1254 void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
1256 node_coords_save_dest = dest;
1259 void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
1261 arrow_coords_save_dest = dest;
1264 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum()
1266 return node_coords_save_map_num;
1269 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum()
1271 return arrow_coords_save_map_num;
1274 void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
1276 node_coords_save_map_num = num;
1279 void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
1281 arrow_coords_save_map_num = num;
1284 const std::string& MapStorage::getNodeCoordsOneMapName()
1286 return node_coords_one_map_name;
1288 const std::string& MapStorage::getNodeCoordsTwoMaps1Name()
1290 return node_coords_two_maps_1_name;
1292 const std::string& MapStorage::getNodeCoordsTwoMaps2Name()
1294 return node_coords_two_maps_2_name;
1297 void MapStorage::setNodeCoordsOneMapName(const std::string& name)
1299 node_coords_one_map_name = name;
1301 void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name)
1303 node_coords_two_maps_1_name = name;
1305 void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name)
1307 node_coords_two_maps_2_name = name;
1310 const std::string& MapStorage::getArrowCoordsOneMapName()
1312 return arrow_coords_one_map_name;
1314 const std::string& MapStorage::getArrowCoordsTwoMaps1Name()
1316 return arrow_coords_two_maps_1_name;
1318 const std::string& MapStorage::getArrowCoordsTwoMaps2Name()
1320 return arrow_coords_two_maps_2_name;
1323 void MapStorage::setArrowCoordsOneMapName(const std::string& name)
1325 arrow_coords_one_map_name = name;
1327 void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name)
1329 arrow_coords_two_maps_1_name = name;
1331 void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name)
1333 arrow_coords_two_maps_2_name = name;
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)
1352 GraphReader<Graph> greader(filename, graph);
1354 // read the label maps
1355 greader.readNodeMap("label", node_label);
1356 if (read_edge_label)
1357 greader.readEdgeMap("label", edge_label);
1359 // read the node maps
1360 for (vector<string>::const_iterator
1361 it = node_map_names.begin();
1362 it != node_map_names.end(); ++it)
1364 switch (node_map_types.find(*it)->second)
1366 case MapValue::NUMERIC:
1368 createNodeMap(*it, MapValue::NUMERIC, double());
1369 greader.readNodeMap(*it, getNumericNodeMap(*it));
1372 case MapValue::STRING:
1374 createNodeMap(*it, MapValue::STRING, string());
1375 greader.readNodeMap(*it, getStringNodeMap(*it));
1379 getNodeMapData(*it)->save_dest = NESET_SECT;
1382 // read the edge maps
1383 for (vector<string>::const_iterator
1384 it = edge_map_names.begin();
1385 it != edge_map_names.end(); ++it)
1387 switch (edge_map_types.find(*it)->second)
1389 case MapValue::NUMERIC:
1391 createEdgeMap(*it, MapValue::NUMERIC, double());
1392 greader.readEdgeMap(*it, getNumericEdgeMap(*it));
1395 case MapValue::STRING:
1397 createEdgeMap(*it, MapValue::STRING, string());
1398 greader.readEdgeMap(*it, getStringEdgeMap(*it));
1402 getEdgeMapData(*it)->save_dest = NESET_SECT;
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);
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);
1420 void MapStorage::setBackground(const std::string& file_name)
1422 if (file_name == background_file_name) return;
1423 if (file_name == "")
1425 background_file_name = "";
1426 background_set = false;
1430 background_file_name = file_name;
1431 background_set = true;
1433 signal_background.emit();
1436 const std::string& MapStorage::getBackgroundFilename()
1438 return background_file_name;
1441 bool MapStorage::isBackgroundSet()
1443 return background_set;
1446 double MapStorage::getBackgroundScaling()
1448 return background_scaling;
1451 void MapStorage::setBackgroundScaling(double scaling)
1453 background_scaling = scaling;
1456 void MapStorage::exportGraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
1458 Graph::NodeMap<int> _shapes(graph, 0);
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];
1466 std::string emptyString="";
1467 Graph::NodeMap<std::string> _nodeTextMap(graph,emptyString);
1469 //_nodeTextMap=(Graph::NodeMap<void> *)&emptyStringMap;
1473 if(active_nodemaps[N_RADIUS]!="")
1475 _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]);
1477 if(active_nodemaps[N_COLOR]!="")
1479 for(NodeIt ni(graph);ni!=INVALID;++ni)
1481 _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni);
1484 if(active_nodemaps[N_TEXT]!="")
1486 for(NodeIt ni(graph);ni!=INVALID;++ni)
1488 std::ostringstream o;
1489 o << get(active_nodemaps[N_TEXT], ni);
1490 _nodeTextMap[ni]=o.str();
1496 if(active_edgemaps[E_WIDTH]!="")
1498 _edgeWidths=getNumericEdgeMap(active_edgemaps[E_WIDTH]);
1500 if(active_edgemaps[E_COLOR]!="")
1502 for(EdgeIt ei(graph);ei!=INVALID;++ei)
1504 _edgeColors[ei]=(int)get(active_edgemaps[E_COLOR], ei);
1508 if(shapemap!="Default values")
1510 double min = std::numeric_limits<double>::max();
1511 double max = std::numeric_limits<double>::min();
1512 for (NodeIt n(graph); n != INVALID; ++n)
1514 double v = static_cast<double>(get(shapemap, n));
1515 if (v < min) min = v;
1516 if (v > max) max = v;
1518 if((min>=0)&&(max<=4))
1520 NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map;
1521 for (NodeIt n(graph); n != INVALID; ++n)
1523 _shapes[n] = static_cast<int>(map[n]);
1529 Palette paletteW(true);
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).
1536 coords(node_coords).
1537 nodeShapes(_shapes).
1538 nodeColors(composeMap(paletteW,_nodeColors)).
1539 edgeColors(composeMap(palette,_edgeColors)).
1540 edgeWidthScale(0.3).edgeWidths(_edgeWidths).
1541 nodeTexts(_nodeTextMap).nodeTextSize(7).
1542 enableParallel(_enableParallel).parEdgeDist(5).
1543 drawArrows(_drawArrows).arrowWidth(7).arrowLength(7).