Issue a custom error message when Lemon is not found.
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>
32 #include <lemon/lgf_reader.h>
33 #include <lemon/lgf_writer.h>
36 const double a_d=0.05;
37 const double p_d=40000;
39 MapStorage::MapStorage() :
40 gui_sect_save_dest(LGF_FILE),
41 node_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
42 arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
47 node_coords_one_map_name("coord"),
48 node_coords_two_maps_1_name("coord_x"),
49 node_coords_two_maps_2_name("coord_y"),
50 arrow_coords_one_map_name("arrow"),
51 arrow_coords_two_maps_1_name("arrow_x"),
52 arrow_coords_two_maps_2_name("arrow_y"),
56 node_coords_x(digraph),
57 node_coords_y(digraph),
58 arrow_coords_x(digraph),
59 arrow_coords_y(digraph),
64 node_coords.setXMap(node_coords_x);
65 node_coords.setYMap(node_coords_y);
66 arrow_coords.setXMap(arrow_coords_x);
67 arrow_coords.setYMap(arrow_coords_y);
69 active_nodemaps.resize(NODE_PROPERTY_NUM);
70 for(int i=0;i<NODE_PROPERTY_NUM;i++)
72 active_nodemaps[i]="";
75 active_arcmaps.resize(EDGE_PROPERTY_NUM);
76 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
82 MapStorage::~MapStorage()
87 void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
90 NodeMapStore::const_iterator it = nodemaps.find(name);
91 if (it != nodemaps.end())
92 throw Error("Node map " + name + " already exists.");
96 case MapValue::NUMERIC:
97 nodemaps[name] = new NumericNodeMapData(digraph, def_val);
99 case MapValue::STRING:
100 nodemaps[name] = new StringNodeMapData(digraph, def_val);
104 nodemaps[name]->default_value = def_val;
106 signal_node_map.emit(name, type);
109 void MapStorage::createArcMap(const std::string& name, MapValue::Type type,
112 ArcMapStore::const_iterator it = arcmaps.find(name);
113 if (it != arcmaps.end())
114 throw Error("Arc map " + name + " already exists.");
118 case MapValue::NUMERIC:
119 arcmaps[name] = new NumericArcMapData(digraph, def_val);
121 case MapValue::STRING:
122 arcmaps[name] = new StringArcMapData(digraph, def_val);
126 arcmaps[name]->default_value = def_val;
128 signal_arc_map.emit(name, type);
131 void MapStorage::changeActiveMap(bool itisarc, int prop, std::string mapname)
135 active_arcmaps[prop]=mapname;
139 active_nodemaps[prop]=mapname;
141 signal_prop.emit(itisarc, prop);
144 void MapStorage::broadcastActiveMaps()
146 for(int i=0;i<NODE_PROPERTY_NUM;i++)
148 signal_map_win.emit(false, i, active_nodemaps[i]);
151 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
153 signal_map_win.emit(true, i, active_arcmaps[i]);
157 std::string MapStorage::getActiveArcMap(int prop)
159 return active_arcmaps[prop];
162 std::string MapStorage::getActiveNodeMap(int prop)
164 return active_nodemaps[prop];
167 std::vector<std::string> MapStorage::getArcMapList(MapType type)
171 std::vector<std::string> ret;
172 for (ArcMapStore::const_iterator it = arcmaps.begin();
173 it != arcmaps.end(); ++it)
175 ret.push_back(it->first);
181 std::vector<std::string> ret;
182 for (ArcMapStore::const_iterator it = arcmaps.begin();
183 it != arcmaps.end(); ++it)
185 ArcMapData* data = getArcMapData(it->first);
186 MapValue::Type t = data->type();
187 if ((t == MapValue::NUMERIC && (type & NUM)) ||
188 (t == MapValue::STRING && (type & STR)))
190 ret.push_back(it->first);
197 std::vector<std::string> MapStorage::getNodeMapList(MapType type)
201 std::vector<std::string> ret;
202 for (NodeMapStore::const_iterator it = nodemaps.begin();
203 it != nodemaps.end(); ++it)
205 ret.push_back(it->first);
211 std::vector<std::string> ret;
212 for (NodeMapStore::const_iterator it = nodemaps.begin();
213 it != nodemaps.end(); ++it)
215 NodeMapData* data = getNodeMapData(it->first);
216 MapValue::Type t = data->type();
217 if ((t == MapValue::NUMERIC && (type & NUM)) ||
218 (t == MapValue::STRING && (type & STR)))
220 ret.push_back(it->first);
227 sigc::signal<void, bool, int> MapStorage::signal_prop_ch()
232 int MapStorage::readFromFile(const std::string &filename)
238 //reading content of file
239 LgfContents content(filename);
244 catch (Exception& error)
246 Gtk::MessageDialog mdialog(error.what());
252 // check whether the .conf file exists
253 bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(),
254 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
256 // check whether the .lgf file contains a gui section
257 bool gui_data_in_lgf = false;
259 for(int i=0;i<content.extraSectionNum();i++)
261 if(content.extraSection(i)=="gui")
263 gui_data_in_lgf = true;
268 bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
270 // ask for user input if both exist
271 bool use_gui_data_in_lgf = false;
272 if (gui_data_in_conf && gui_data_in_lgf)
274 Gtk::MessageDialog mdialog(_("<b>Found both ") + filename +
275 _(".conf and a gui section in ") + filename + _(".</b>"), true,
276 Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
277 mdialog.add_button(_("Use the ._conf file"), 1);
278 mdialog.add_button(_("Use the _gui section"), 2);
279 switch (mdialog.run())
282 use_gui_data_in_lgf = false;
285 use_gui_data_in_lgf = true;
287 case Gtk::RESPONSE_NONE:
293 use_gui_data_in_lgf = gui_data_in_lgf;
298 GUISectData gui_data;
299 if (use_gui_data_in_lgf)
301 // read the gui section from the .lgf file
304 sectionReader(filename).sectionStream("gui", GuiReader(this, gui_data)).run();
305 gui_sect_save_dest = LGF_FILE;
307 catch (Exception& error)
315 // read the gui section from the .conf file
318 sectionReader(filename + ".conf").sectionStream("gui", GuiReader(this, gui_data)).run();
319 gui_sect_save_dest = CONF_FILE;
321 catch (Exception& error)
328 // read the digraph 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_arc_map_names,
379 gui_data.node_map_types, gui_data.arc_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(digraph); 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(digraph); 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_arc_map_names.begin();
424 it != gui_data.gui_arc_map_names.end(); ++it)
426 string map_name = *it;
427 switch (gui_data.arc_map_types[map_name])
429 case MapValue::NUMERIC:
431 createArcMap(map_name, MapValue::NUMERIC, double());
432 NumericArcMap& dmap = getNumericArcMap(map_name);
433 map<int, double>& smap = *gui_data.numeric_arc_maps[map_name];
434 for (ArcIt e(digraph); e != INVALID; ++e)
436 dmap[e] = smap[arc_label[e]];
440 case MapValue::STRING:
442 createArcMap(map_name, MapValue::STRING, string());
443 StringArcMap& dmap = getStringArcMap(map_name);
444 map<int, string>& smap = *gui_data.string_arc_maps[map_name];
445 for (ArcIt e(digraph); e != INVALID; ++e)
447 dmap[e] = smap[arc_label[e]];
452 getArcMapData(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(digraph); 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 (ArcIt e(digraph); e != INVALID; ++e)
471 arrow_coords.set(e, gui_data.arrow_coord_map[arc_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 if (content.nodeSectionNum() < 1)
482 Gtk::MessageDialog mdialog("No nodeset found in file.");
488 if (content.arcSectionNum() < 1)
490 Gtk::MessageDialog mdialog("No arcset found in file.");
496 std::vector<std::string> nodeMapNames = content.nodeMapNames(0);
497 std::vector<std::string> arcMapNames = content.arcMapNames(0);
499 bool read_arc_label = true;
500 if (std::find(arcMapNames.begin(), arcMapNames.end(), "label") ==
503 read_arc_label = false;
507 std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"),
511 std::remove(arcMapNames.begin(), arcMapNames.end(), "label"),
514 FileImportDialog::ImportData data(nodeMapNames, arcMapNames);
515 FileImportDialog fidialog(&data);
516 int response = fidialog.run();
517 if (response == Gtk::RESPONSE_OK)
521 std::string node_coord_xmap_name, node_coord_ymap_name;
522 std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
523 bool gen_node_coords = false;
524 bool gen_arrow_coords = false;
526 switch (data.node_coord_load_from)
528 case FileImportDialog::ImportData::ONE_MAP:
529 node_coord_xmap_name = data.node_coord_one_map_name + ":x";
530 node_coord_ymap_name = data.node_coord_one_map_name + ":y";
531 node_coords_one_map_name = data.node_coord_one_map_name;
533 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
534 node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
536 case FileImportDialog::ImportData::TWO_MAPS:
537 node_coord_xmap_name = data.node_coord_two_maps_1_name;
538 node_coord_ymap_name = data.node_coord_two_maps_2_name;
539 node_coords_two_maps_1_name = data.node_coord_two_maps_1_name;
540 node_coords_two_maps_2_name = data.node_coord_two_maps_2_name;
542 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
543 node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
545 case FileImportDialog::ImportData::DONT_READ:
546 node_coord_xmap_name = "";
547 node_coord_ymap_name = "";
549 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
550 gen_node_coords = true;
554 switch (data.arrow_coord_load_from)
556 case FileImportDialog::ImportData::ONE_MAP:
557 arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x";
558 arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y";
559 arrow_coords_one_map_name = data.arrow_coord_one_map_name;
561 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
562 arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
564 case FileImportDialog::ImportData::TWO_MAPS:
565 arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name;
566 arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name;
567 arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name;
568 arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name;
570 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
571 arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
573 case FileImportDialog::ImportData::DONT_READ:
574 arrow_coord_xmap_name = "";
575 arrow_coord_ymap_name = "";
577 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
578 gen_arrow_coords = true;
582 // read arc and node maps
583 std::vector<std::string> node_map_names;
584 std::vector<std::string> arc_map_names;
585 std::map<std::string, MapValue::Type> node_map_types;
586 std::map<std::string, MapValue::Type> arc_map_types;
587 for (std::vector<std::string>::const_iterator it =
588 data.numeric_node_map_names.begin();
589 it != data.numeric_node_map_names.end(); ++it)
591 node_map_names.push_back(*it);
592 node_map_types[*it] = MapValue::NUMERIC;
594 for (std::vector<std::string>::const_iterator it =
595 data.string_node_map_names.begin();
596 it != data.string_node_map_names.end(); ++it)
598 node_map_names.push_back(*it);
599 node_map_types[*it] = MapValue::STRING;
601 for (std::vector<std::string>::const_iterator it =
602 data.numeric_arc_map_names.begin();
603 it != data.numeric_arc_map_names.end(); ++it)
605 arc_map_names.push_back(*it);
606 arc_map_types[*it] = MapValue::NUMERIC;
608 for (std::vector<std::string>::const_iterator it =
609 data.string_arc_map_names.begin();
610 it != data.string_arc_map_names.end(); ++it)
612 arc_map_names.push_back(*it);
613 arc_map_types[*it] = MapValue::STRING;
616 readLGF(filename, read_arc_label,
617 node_map_names, arc_map_names,
618 node_map_types, arc_map_types,
619 node_coord_xmap_name, node_coord_ymap_name,
620 arrow_coord_xmap_name, arrow_coord_ymap_name);
622 // generate arc labels
626 for (ArcIt e(digraph); e != INVALID; ++e)
634 // generate node coordinates
636 for (NodeIt n(digraph); n != INVALID; ++n) { node_num++; }
637 const double pi = 3.142;
638 double step = 2 * pi / (double) node_num;
640 for (NodeIt n(digraph); n != INVALID; ++n)
643 XY(250.0 * std::cos(i * step),
644 250.0 * std::sin(i * step)));
648 if (gen_arrow_coords)
650 // generate arrow coordinates
651 for (ArcIt e(digraph); e != INVALID; ++e)
653 if (digraph.source(e) == digraph.target(e))
656 getNodeCoords(digraph.source(e)) + XY(0.0, 80.0));
661 (getNodeCoords(digraph.source(e)) +
662 getNodeCoords(digraph.target(e))) / 2.0);
667 catch (Exception& error)
681 // set max_node_label
683 max_node_label = std::numeric_limits<int>::min();
684 for (NodeIt n(digraph); n != INVALID; ++n)
686 if (node_label[n] > max_node_label)
688 max_node_label = node_label[n];
694 max_arc_label = std::numeric_limits<int>::min();
695 for (ArcIt e(digraph); e != INVALID; ++e)
697 if (arc_label[e] > max_arc_label)
699 max_arc_label = arc_label[e];
707 void MapStorage::writeToFile(const std::string &filename)
709 // relabel nodes and arcs
711 for (NodeIt n(digraph); n != INVALID; ++n)
715 max_node_label = i-1;
717 for (ArcIt e(digraph); e != INVALID; ++e)
725 DigraphWriter<Digraph> gwriter(filename, digraph);
727 gwriter.nodeMap("label", node_label);
728 gwriter.arcMap("label", arc_label);
731 for (NodeMapStore::const_iterator it = nodemaps.begin();
732 it != nodemaps.end(); ++it)
734 if (it->second->save_dest == NESET_SECT)
736 switch (it->second->type())
738 case MapValue::NUMERIC:
739 gwriter.nodeMap(it->first, getNumericNodeMap(it->first));
741 case MapValue::STRING:
742 gwriter.nodeMap(it->first, getStringNodeMap(it->first));
749 for (ArcMapStore::const_iterator it = arcmaps.begin();
750 it != arcmaps.end(); ++it)
752 if (it->second->save_dest == NESET_SECT)
754 switch (it->second->type())
756 case MapValue::NUMERIC:
757 gwriter.arcMap(it->first, getNumericArcMap(it->first));
759 case MapValue::STRING:
760 gwriter.arcMap(it->first, getStringArcMap(it->first));
766 // write node coordinates
767 switch (getNodeCoordsSaveDest())
769 case MapStorage::SpecMapSaveOpts::GUI_SECT:
771 case MapStorage::SpecMapSaveOpts::NESET_SECT:
772 switch (getNodeCoordsSaveMapNum())
774 case MapStorage::SpecMapSaveOpts::ONE_MAP:
775 gwriter.nodeMap(node_coords_one_map_name + ":x",
777 gwriter.nodeMap(node_coords_one_map_name + ":y",
780 case MapStorage::SpecMapSaveOpts::TWO_MAPS:
781 gwriter.nodeMap(node_coords_two_maps_1_name,
783 gwriter.nodeMap(node_coords_two_maps_2_name,
790 // write arrow coordinates
791 switch (getArrowCoordsSaveDest())
793 case MapStorage::SpecMapSaveOpts::GUI_SECT:
795 case MapStorage::SpecMapSaveOpts::NESET_SECT:
796 switch (getArrowCoordsSaveMapNum())
798 case MapStorage::SpecMapSaveOpts::ONE_MAP:
799 gwriter.arcMap(arrow_coords_one_map_name + ":x",
801 gwriter.arcMap(arrow_coords_one_map_name + ":y",
804 case MapStorage::SpecMapSaveOpts::TWO_MAPS:
805 gwriter.arcMap(arrow_coords_two_maps_1_name,
807 gwriter.arcMap(arrow_coords_two_maps_2_name,
814 if (gui_sect_save_dest == LGF_FILE)
816 GuiWriter gui_writer(this);
817 gui_writer.write(gwriter.ostream());
827 if (gui_sect_save_dest == CONF_FILE)
829 DigraphWriter<Digraph> lwriter(filename + ".conf", digraph);
830 GuiWriter gui_writer(this);
831 gui_writer.write(lwriter.ostream());
836 void MapStorage::clear()
838 for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
843 for (ArcMapStore::iterator it = arcmaps.begin(); it != arcmaps.end(); ++it)
853 background_set = false;
855 gui_sect_save_dest = LGF_FILE;
856 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
857 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
858 node_coords_one_map_name = "coord";
859 node_coords_two_maps_1_name = "coord_x";
860 node_coords_two_maps_2_name = "coord_y";
861 arrow_coords_one_map_name = "arrow";
862 arrow_coords_two_maps_1_name = "arrow_x";
863 arrow_coords_two_maps_2_name = "arrow_y";
865 for(int i=0;i<NODE_PROPERTY_NUM;i++)
867 changeActiveMap(false, i, "");
868 signal_map_win.emit(false, i, "");
871 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
873 changeActiveMap(true, i, "");
874 signal_map_win.emit(true, i, "");
881 signal_design_win.emit(attraction, propulsation, iterations);
884 void MapStorage::mapChanged(bool itisarc, std::string mapname)
888 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
890 if(active_arcmaps[i]==mapname)
892 signal_prop.emit(itisarc, i);
898 for(int i=0;i<NODE_PROPERTY_NUM;i++)
900 if(active_nodemaps[i]==mapname)
902 signal_prop.emit(itisarc, i);
908 void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
910 attraction_p=attraction;
911 propulsation_p=propulsation;
912 iterations_p=iterations;
915 void MapStorage::set_attraction(double attraction_p)
917 attraction=attraction_p;
920 void MapStorage::set_propulsation(double propulsation_p)
922 propulsation=propulsation_p;
925 void MapStorage::set_iteration(int iterations_p)
927 iterations=iterations_p;
930 void MapStorage::redesign_data_changed()
932 signal_design_win.emit(attraction, propulsation, iterations);
935 XY MapStorage::getNodeCoords(Node n) const
937 return node_coords[n];
940 void MapStorage::setNodeCoords(Node n, XY c)
942 node_coords.set(n, c);
945 XY MapStorage::getArrowCoords(Arc e) const
947 return arrow_coords[e];
950 void MapStorage::setArrowCoords(Arc e, XY c)
952 arrow_coords.set(e, c);
955 MapValue MapStorage::get(const std::string& name, Node node) const
957 NodeMapData* data = getNodeMapData(name);
958 return data->get(node);
961 void MapStorage::set(const std::string& name, Node node, MapValue val)
963 NodeMapData* data = getNodeMapData(name);
964 data->set(node, val);
967 MapValue MapStorage::get(const std::string& name, Arc arc) const
969 ArcMapData* data = getArcMapData(name);
970 return data->get(arc);
973 void MapStorage::set(const std::string& name, Arc arc, MapValue val)
975 ArcMapData* data = getArcMapData(name);
979 const std::string& MapStorage::getFileName() const
984 void MapStorage::setFileName(const std::string& fn)
989 bool MapStorage::getModified() const
994 void MapStorage::setModified(bool m)
999 Node MapStorage::addNode(XY coords)
1001 Node node = digraph.addNode();
1003 setNodeCoords(node, coords);
1007 node_label[node] = max_node_label;
1009 std::vector<std::string> node_maps = getNodeMapList();
1010 for (std::vector<std::string>::const_iterator it = node_maps.begin();
1011 it != node_maps.end(); ++it)
1013 NodeMapData* data = getNodeMapData(*it);
1014 set(*it, node, data->default_value);
1020 Arc MapStorage::addArc(Node from, Node to)
1022 Arc arc = digraph.addArc(from, to);
1026 setArrowCoords(arc, getNodeCoords(from) + XY(0.0, 80.0));
1030 setArrowCoords(arc, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
1035 arc_label[arc] = max_arc_label;
1037 std::vector<std::string> arc_maps = getArcMapList();
1038 for (std::vector<std::string>::const_iterator it = arc_maps.begin();
1039 it != arc_maps.end(); ++it)
1041 ArcMapData* data = getArcMapData(*it);
1042 set(*it, arc, data->default_value);
1047 MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
1049 NodeMapData* data = getNodeMapData(name);
1050 if (data->type() != MapValue::NUMERIC)
1051 throw Error("Numeric node map " + name + " does not exists.");
1052 return static_cast<NumericNodeMapData*>(data)->map;
1055 MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
1057 NodeMapData* data = getNodeMapData(name);
1058 if (data->type() != MapValue::STRING)
1059 throw Error("String node map " + name + " does not exists.");
1060 return static_cast<StringNodeMapData*>(data)->map;
1063 MapStorage::NumericArcMap& MapStorage::getNumericArcMap(const std::string& name)
1065 ArcMapData* data = getArcMapData(name);
1066 if (data->type() != MapValue::NUMERIC)
1067 throw Error("Numeric arc map " + name + " does not exists.");
1068 return static_cast<NumericArcMapData*>(data)->map;
1071 MapStorage::StringArcMap& MapStorage::getStringArcMap(const std::string& name)
1073 ArcMapData* data = getArcMapData(name);
1074 if (data->type() != MapValue::STRING)
1075 throw Error("String arc map " + name + " does not exists.");
1076 return static_cast<StringArcMapData*>(data)->map;
1079 MapValueArcMap MapStorage::getArcMap(const std::string& name)
1081 return MapValueArcMap(name, this);
1084 MapValueNodeMap MapStorage::getNodeMap(const std::string& name)
1086 return MapValueNodeMap(name, this);
1089 int MapStorage::getLabel(Node n) const
1091 return node_label[n];
1094 int MapStorage::getLabel(Arc e) const
1096 return arc_label[e];
1099 MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation()
1101 return gui_sect_save_dest;
1104 void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest)
1106 gui_sect_save_dest = dest;
1109 MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const
1111 NodeMapData *data = getNodeMapData(name);
1112 return data->save_dest;
1115 MapStorage::MapSaveDest MapStorage::getArcMapSaveDest(std::string name) const
1117 ArcMapData *data = getArcMapData(name);
1118 return data->save_dest;
1121 void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
1123 NodeMapData *data = getNodeMapData(name);
1124 data->save_dest = dest;
1127 void MapStorage::setArcMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
1129 ArcMapData *data = getArcMapData(name);
1130 data->save_dest = dest;
1133 MapStorage::ArcMapData* MapStorage::getArcMapData(std::string name) const
1135 ArcMapStore::const_iterator it = arcmaps.find(name);
1136 if (it != arcmaps.end())
1139 throw Error("Arc map " + name + " does not exists.");
1142 MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
1144 NodeMapStore::const_iterator it = nodemaps.find(name);
1145 if (it != nodemaps.end())
1148 throw Error("Node map " + name + " does not exists.");
1151 MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
1153 NodeMapData *data = getNodeMapData(name);
1154 return data->type();
1157 MapValue::Type MapStorage::getArcMapElementType(std::string name) const
1159 ArcMapData *data = getArcMapData(name);
1160 return data->type();
1163 const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
1168 const MapStorage::ArcLabelMap& MapStorage::getArcLabelMap()
1173 const Digraph& MapStorage::getDigraph()
1178 bool MapStorage::nodeMapExists(std::string name)
1180 NodeMapStore::const_iterator it = nodemaps.find(name);
1181 if (it == nodemaps.end())
1187 bool MapStorage::arcMapExists(std::string name)
1189 ArcMapStore::const_iterator it = arcmaps.find(name);
1190 if (it == arcmaps.end())
1196 std::vector<std::string> MapStorage::getArcMaps(MapType type)
1198 std::vector<std::string> maps;
1199 for (ArcMapStore::const_iterator it = arcmaps.begin(); it != arcmaps.end(); ++it)
1201 if (it->second->type() & type)
1203 maps.push_back(it->first);
1209 std::vector<std::string> MapStorage::getNodeMaps(MapType type)
1211 std::vector<std::string> maps;
1212 for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
1214 if (it->second->type() & type)
1216 maps.push_back(it->first);
1222 MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
1227 MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
1229 return arrow_coords;
1232 MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest()
1234 return node_coords_save_dest;
1237 MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest()
1239 return arrow_coords_save_dest;
1242 void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
1244 node_coords_save_dest = dest;
1247 void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
1249 arrow_coords_save_dest = dest;
1252 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum()
1254 return node_coords_save_map_num;
1257 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum()
1259 return arrow_coords_save_map_num;
1262 void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
1264 node_coords_save_map_num = num;
1267 void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
1269 arrow_coords_save_map_num = num;
1272 const std::string& MapStorage::getNodeCoordsOneMapName()
1274 return node_coords_one_map_name;
1276 const std::string& MapStorage::getNodeCoordsTwoMaps1Name()
1278 return node_coords_two_maps_1_name;
1280 const std::string& MapStorage::getNodeCoordsTwoMaps2Name()
1282 return node_coords_two_maps_2_name;
1285 void MapStorage::setNodeCoordsOneMapName(const std::string& name)
1287 node_coords_one_map_name = name;
1289 void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name)
1291 node_coords_two_maps_1_name = name;
1293 void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name)
1295 node_coords_two_maps_2_name = name;
1298 const std::string& MapStorage::getArrowCoordsOneMapName()
1300 return arrow_coords_one_map_name;
1302 const std::string& MapStorage::getArrowCoordsTwoMaps1Name()
1304 return arrow_coords_two_maps_1_name;
1306 const std::string& MapStorage::getArrowCoordsTwoMaps2Name()
1308 return arrow_coords_two_maps_2_name;
1311 void MapStorage::setArrowCoordsOneMapName(const std::string& name)
1313 arrow_coords_one_map_name = name;
1315 void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name)
1317 arrow_coords_two_maps_1_name = name;
1319 void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name)
1321 arrow_coords_two_maps_2_name = name;
1324 void MapStorage::readLGF(
1325 const std::string& filename,
1326 bool read_arc_label,
1327 const std::vector<std::string>& node_map_names,
1328 const std::vector<std::string>& arc_map_names,
1329 const std::map<std::string, MapValue::Type>& node_map_types,
1330 const std::map<std::string, MapValue::Type>& arc_map_types,
1331 const std::string& node_coord_xmap_name,
1332 const std::string& node_coord_ymap_name,
1333 const std::string& arrow_coord_xmap_name,
1334 const std::string& arrow_coord_ymap_name)
1340 DigraphReader<Digraph> greader(filename, digraph);
1342 // read the label maps
1343 greader.nodeMap("label", node_label);
1345 greader.arcMap("label", arc_label);
1347 // read the node maps
1348 for (vector<string>::const_iterator
1349 it = node_map_names.begin();
1350 it != node_map_names.end(); ++it)
1352 switch (node_map_types.find(*it)->second)
1354 case MapValue::NUMERIC:
1356 createNodeMap(*it, MapValue::NUMERIC, double());
1357 greader.nodeMap(*it, getNumericNodeMap(*it));
1360 case MapValue::STRING:
1362 createNodeMap(*it, MapValue::STRING, string());
1363 greader.nodeMap(*it, getStringNodeMap(*it));
1367 getNodeMapData(*it)->save_dest = NESET_SECT;
1370 // read the arc maps
1371 for (vector<string>::const_iterator
1372 it = arc_map_names.begin();
1373 it != arc_map_names.end(); ++it)
1375 switch (arc_map_types.find(*it)->second)
1377 case MapValue::NUMERIC:
1379 createArcMap(*it, MapValue::NUMERIC, double());
1380 greader.arcMap(*it, getNumericArcMap(*it));
1383 case MapValue::STRING:
1385 createArcMap(*it, MapValue::STRING, string());
1386 greader.arcMap(*it, getStringArcMap(*it));
1390 getArcMapData(*it)->save_dest = NESET_SECT;
1393 // read the node coordinate maps
1394 if (node_coord_xmap_name != "")
1395 greader.nodeMap(node_coord_xmap_name, node_coords_x);
1396 if (node_coord_ymap_name != "")
1397 greader.nodeMap(node_coord_ymap_name, node_coords_y);
1399 // read the arrow coordinate maps
1400 if (arrow_coord_xmap_name != "")
1401 greader.arcMap(arrow_coord_xmap_name, arrow_coords_x);
1402 if (arrow_coord_ymap_name != "")
1403 greader.arcMap(arrow_coord_ymap_name, arrow_coords_y);
1408 void MapStorage::setBackground(const std::string& file_name)
1410 if (file_name == background_file_name) return;
1411 if (file_name == "")
1413 background_file_name = "";
1414 background_set = false;
1418 background_file_name = file_name;
1419 background_set = true;
1421 signal_background.emit();
1424 const std::string& MapStorage::getBackgroundFilename()
1426 return background_file_name;
1429 bool MapStorage::isBackgroundSet()
1431 return background_set;
1434 double MapStorage::getBackgroundScaling()
1436 return background_scaling;
1439 void MapStorage::setBackgroundScaling(double scaling)
1441 background_scaling = scaling;
1444 void MapStorage::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
1446 Digraph::NodeMap<int> _shapes(digraph, 0);
1447 Digraph::NodeMap<int> _nodeColors(digraph, 0);
1448 Digraph::ArcMap<int> _arcColors(digraph, 0);
1449 Digraph::NodeMap<double> _nodeSizes(digraph, 6.0);
1450 Digraph::ArcMap<double> _arcWidths(digraph, 1.0);
1451 bool _drawArrows=options[ARROWS];
1452 bool _enableParallel=options[PAR];
1454 std::string emptyString="";
1455 Digraph::NodeMap<std::string> _nodeTextMap(digraph,emptyString);
1457 //_nodeTextMap=(Digraph::NodeMap<void> *)&emptyStringMap;
1461 if(active_nodemaps[N_RADIUS]!="")
1463 _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]);
1465 if(active_nodemaps[N_COLOR]!="")
1467 for(NodeIt ni(digraph);ni!=INVALID;++ni)
1469 _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni);
1472 if(active_nodemaps[N_TEXT]!="")
1474 for(NodeIt ni(digraph);ni!=INVALID;++ni)
1476 std::ostringstream o;
1477 o << get(active_nodemaps[N_TEXT], ni);
1478 _nodeTextMap[ni]=o.str();
1484 if(active_arcmaps[E_WIDTH]!="")
1486 _arcWidths=getNumericArcMap(active_arcmaps[E_WIDTH]);
1488 if(active_arcmaps[E_COLOR]!="")
1490 for(ArcIt ei(digraph);ei!=INVALID;++ei)
1492 _arcColors[ei]=(int)get(active_arcmaps[E_COLOR], ei);
1496 if(shapemap!="Default values")
1498 double min = std::numeric_limits<double>::max();
1499 double max = std::numeric_limits<double>::min();
1500 for (NodeIt n(digraph); n != INVALID; ++n)
1502 double v = static_cast<double>(get(shapemap, n));
1503 if (v < min) min = v;
1504 if (v > max) max = v;
1506 if((min>=0)&&(max<=4))
1508 NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map;
1509 for (NodeIt n(digraph); n != INVALID; ++n)
1511 _shapes[n] = static_cast<int>(map[n]);
1517 Palette paletteW(true);
1519 graphToEps(digraph,filename).
1520 title("Sample .eps figure (fits to A4)").
1521 copyright("(C) 2006 LEMON Project").
1522 absoluteNodeSizes().absoluteArcWidths().
1523 nodeScale(2).nodeSizes(_nodeSizes).
1524 coords(node_coords).
1525 nodeShapes(_shapes).
1526 nodeColors(composeMap(paletteW,_nodeColors)).
1527 arcColors(composeMap(palette,_arcColors)).
1528 arcWidthScale(0.3).arcWidths(_arcWidths).
1529 nodeTexts(_nodeTextMap).nodeTextSize(7).
1530 enableParallel(_enableParallel).parArcDist(5).
1531 drawArrows(_drawArrows).arrowWidth(7).arrowLength(7).