hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all cop ies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include "i18n.h" hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include "file_import_dialog.h" hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: const int i_d=20; hegyi@1: const double a_d=0.05; hegyi@1: const double p_d=40000; hegyi@1: hegyi@1: MapStorage::MapStorage() : hegyi@1: gui_sect_save_dest(LGF_FILE), hegyi@1: node_coords_save_dest(SpecMapSaveOpts::GUI_SECT), hegyi@1: arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT), hegyi@1: modified(false), hegyi@1: file_name(""), hegyi@1: max_node_label(0), hegyi@1: max_arc_label(0), hegyi@1: node_coords_one_map_name("coord"), hegyi@1: node_coords_two_maps_1_name("coord_x"), hegyi@1: node_coords_two_maps_2_name("coord_y"), hegyi@1: arrow_coords_one_map_name("arrow"), hegyi@1: arrow_coords_two_maps_1_name("arrow_x"), hegyi@1: arrow_coords_two_maps_2_name("arrow_y"), hegyi@1: iterations(i_d), hegyi@1: attraction(a_d), hegyi@1: propulsation(p_d), hegyi@1: node_coords_x(digraph), hegyi@1: node_coords_y(digraph), hegyi@1: arrow_coords_x(digraph), hegyi@1: arrow_coords_y(digraph), hegyi@1: node_label(digraph), hegyi@1: arc_label(digraph), hegyi@1: background_set(false) hegyi@1: { hegyi@1: node_coords.setXMap(node_coords_x); hegyi@1: node_coords.setYMap(node_coords_y); hegyi@1: arrow_coords.setXMap(arrow_coords_x); hegyi@1: arrow_coords.setYMap(arrow_coords_y); hegyi@1: hegyi@1: active_nodemaps.resize(NODE_PROPERTY_NUM); hegyi@1: for(int i=0;idefault_value = def_val; hegyi@1: hegyi@1: signal_node_map.emit(name, type); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::createArcMap(const std::string& name, MapValue::Type type, hegyi@1: MapValue def_val) hegyi@1: { hegyi@1: ArcMapStore::const_iterator it = arcmaps.find(name); hegyi@1: if (it != arcmaps.end()) hegyi@1: throw Error("Arc map " + name + " already exists."); hegyi@1: hegyi@1: switch (type) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: arcmaps[name] = new NumericArcMapData(digraph, def_val); hegyi@1: break; hegyi@1: case MapValue::STRING: hegyi@1: arcmaps[name] = new StringArcMapData(digraph, def_val); hegyi@1: break; hegyi@1: } hegyi@1: hegyi@1: arcmaps[name]->default_value = def_val; hegyi@1: hegyi@1: signal_arc_map.emit(name, type); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::changeActiveMap(bool itisarc, int prop, std::string mapname) hegyi@1: { hegyi@1: if(itisarc) hegyi@1: { hegyi@1: active_arcmaps[prop]=mapname; hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: active_nodemaps[prop]=mapname; hegyi@1: } hegyi@1: signal_prop.emit(itisarc, prop); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::broadcastActiveMaps() hegyi@1: { hegyi@1: for(int i=0;i MapStorage::getArcMapList(MapType type) hegyi@1: { hegyi@1: if (type == ALL) hegyi@1: { hegyi@1: std::vector ret; hegyi@1: for (ArcMapStore::const_iterator it = arcmaps.begin(); hegyi@1: it != arcmaps.end(); ++it) hegyi@1: { hegyi@1: ret.push_back(it->first); hegyi@1: } hegyi@1: return ret; hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: std::vector ret; hegyi@1: for (ArcMapStore::const_iterator it = arcmaps.begin(); hegyi@1: it != arcmaps.end(); ++it) hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(it->first); hegyi@1: MapValue::Type t = data->type(); hegyi@1: if ((t == MapValue::NUMERIC && (type & NUM)) || hegyi@1: (t == MapValue::STRING && (type & STR))) hegyi@1: { hegyi@1: ret.push_back(it->first); hegyi@1: } hegyi@1: } hegyi@1: return ret; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: std::vector MapStorage::getNodeMapList(MapType type) hegyi@1: { hegyi@1: if (type == ALL) hegyi@1: { hegyi@1: std::vector ret; hegyi@1: for (NodeMapStore::const_iterator it = nodemaps.begin(); hegyi@1: it != nodemaps.end(); ++it) hegyi@1: { hegyi@1: ret.push_back(it->first); hegyi@1: } hegyi@1: return ret; hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: std::vector ret; hegyi@1: for (NodeMapStore::const_iterator it = nodemaps.begin(); hegyi@1: it != nodemaps.end(); ++it) hegyi@1: { hegyi@1: NodeMapData* data = getNodeMapData(it->first); hegyi@1: MapValue::Type t = data->type(); hegyi@1: if ((t == MapValue::NUMERIC && (type & NUM)) || hegyi@1: (t == MapValue::STRING && (type & STR))) hegyi@1: { hegyi@1: ret.push_back(it->first); hegyi@1: } hegyi@1: } hegyi@1: return ret; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: sigc::signal MapStorage::signal_prop_ch() hegyi@1: { hegyi@1: return signal_prop; hegyi@1: } hegyi@1: hegyi@1: int MapStorage::readFromFile(const std::string &filename) hegyi@1: { hegyi@1: using std::vector; hegyi@1: using std::map; hegyi@1: using std::string; hegyi@1: hegyi@1: //reading content of file hegyi@1: LgfContents content(filename); hegyi@1: try hegyi@1: { hegyi@1: content.run(); hegyi@1: } hegyi@1: catch (Exception& error) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog(error.what()); hegyi@1: mdialog.run(); hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: hegyi@1: // check whether the .conf file exists hegyi@1: bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(), hegyi@1: (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)); hegyi@1: hegyi@1: // check whether the .lgf file contains a gui section hegyi@1: bool gui_data_in_lgf = false; hegyi@1: { hegyi@1: for(int i=0;iFound both ") + filename + hegyi@1: _(".conf and a gui section in ") + filename + _("."), true, hegyi@1: Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE); hegyi@1: mdialog.add_button(_("Use the ._conf file"), 1); hegyi@1: mdialog.add_button(_("Use the _gui section"), 2); hegyi@1: switch (mdialog.run()) hegyi@1: { hegyi@1: case 1: hegyi@1: use_gui_data_in_lgf = false; hegyi@1: break; hegyi@1: case 2: hegyi@1: use_gui_data_in_lgf = true; hegyi@1: break; hegyi@1: case Gtk::RESPONSE_NONE: hegyi@1: return 1; hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: use_gui_data_in_lgf = gui_data_in_lgf; hegyi@1: } hegyi@1: hegyi@1: if (gui_data_found) hegyi@1: { hegyi@1: GUISectData gui_data; hegyi@1: if (use_gui_data_in_lgf) hegyi@1: { hegyi@1: // read the gui section from the .lgf file hegyi@1: try hegyi@1: { hegyi@1: sectionReader(filename).sectionStream("gui", GuiReader(this, gui_data)).run(); hegyi@1: gui_sect_save_dest = LGF_FILE; hegyi@1: } hegyi@1: catch (Exception& error) hegyi@1: { hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: // read the gui section from the .conf file hegyi@1: try hegyi@1: { hegyi@1: sectionReader(filename + ".conf").sectionStream("gui", GuiReader(this, gui_data)).run(); hegyi@1: gui_sect_save_dest = CONF_FILE; hegyi@1: } hegyi@1: catch (Exception& error) hegyi@1: { hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // read the digraph and maps form the .lgf file hegyi@1: try hegyi@1: { hegyi@1: std::string node_coord_xmap_name, node_coord_ymap_name; hegyi@1: std::string arrow_coord_xmap_name, arrow_coord_ymap_name; hegyi@1: hegyi@1: if (gui_data.node_coords_save_dest == hegyi@1: MapStorage::SpecMapSaveOpts::NESET_SECT) hegyi@1: { hegyi@1: switch (gui_data.node_coords_save_map_num) hegyi@1: { hegyi@1: case SpecMapSaveOpts::ONE_MAP: hegyi@1: node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x"; hegyi@1: node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y"; hegyi@1: node_coords_one_map_name = gui_data.node_coords_one_map_name; hegyi@1: break; hegyi@1: case SpecMapSaveOpts::TWO_MAPS: hegyi@1: node_coord_xmap_name = gui_data.node_coords_two_maps_1_name; hegyi@1: node_coord_ymap_name = gui_data.node_coords_two_maps_2_name; hegyi@1: node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name; hegyi@1: node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name; hegyi@1: break; hegyi@1: } hegyi@1: node_coords_save_dest = gui_data.node_coords_save_dest; hegyi@1: node_coords_save_map_num = gui_data.node_coords_save_map_num; hegyi@1: } hegyi@1: hegyi@1: if (gui_data.arrow_coords_save_dest == hegyi@1: MapStorage::SpecMapSaveOpts::NESET_SECT) hegyi@1: { hegyi@1: switch (gui_data.arrow_coords_save_map_num) hegyi@1: { hegyi@1: case SpecMapSaveOpts::ONE_MAP: hegyi@1: arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x"; hegyi@1: arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y"; hegyi@1: arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name; hegyi@1: break; hegyi@1: case SpecMapSaveOpts::TWO_MAPS: hegyi@1: arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name; hegyi@1: arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name; hegyi@1: arrow_coords_two_maps_1_name = hegyi@1: gui_data.arrow_coords_two_maps_1_name; hegyi@1: arrow_coords_two_maps_2_name = hegyi@1: gui_data.arrow_coords_two_maps_2_name; hegyi@1: break; hegyi@1: } hegyi@1: arrow_coords_save_dest = gui_data.arrow_coords_save_dest; hegyi@1: arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num; hegyi@1: } hegyi@1: readLGF(filename, true, hegyi@1: gui_data.main_node_map_names, gui_data.main_arc_map_names, hegyi@1: gui_data.node_map_types, gui_data.arc_map_types, hegyi@1: node_coord_xmap_name, node_coord_ymap_name, hegyi@1: arrow_coord_xmap_name, arrow_coord_ymap_name); hegyi@1: } hegyi@1: catch (Exception& error) hegyi@1: { hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: hegyi@1: // add the maps from the gui section hegyi@1: for (vector::const_iterator hegyi@1: it = gui_data.gui_node_map_names.begin(); hegyi@1: it != gui_data.gui_node_map_names.end(); ++it) hegyi@1: { hegyi@1: string map_name = *it; hegyi@1: switch (gui_data.node_map_types[map_name]) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: createNodeMap(map_name, MapValue::NUMERIC, double()); hegyi@1: NumericNodeMap& dmap = getNumericNodeMap(map_name); hegyi@1: map& smap = *gui_data.numeric_node_maps[map_name]; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: dmap[n] = smap[node_label[n]]; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: createNodeMap(map_name, MapValue::STRING, string()); hegyi@1: StringNodeMap& dmap = getStringNodeMap(map_name); hegyi@1: map& smap = *gui_data.string_node_maps[map_name]; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: dmap[n] = smap[node_label[n]]; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: getNodeMapData(map_name)->save_dest = GUI_SECT; hegyi@1: } hegyi@1: for (vector::const_iterator hegyi@1: it = gui_data.gui_arc_map_names.begin(); hegyi@1: it != gui_data.gui_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: string map_name = *it; hegyi@1: switch (gui_data.arc_map_types[map_name]) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: createArcMap(map_name, MapValue::NUMERIC, double()); hegyi@1: NumericArcMap& dmap = getNumericArcMap(map_name); hegyi@1: map& smap = *gui_data.numeric_arc_maps[map_name]; hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: dmap[e] = smap[arc_label[e]]; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: createArcMap(map_name, MapValue::STRING, string()); hegyi@1: StringArcMap& dmap = getStringArcMap(map_name); hegyi@1: map& smap = *gui_data.string_arc_maps[map_name]; hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: dmap[e] = smap[arc_label[e]]; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: getArcMapData(map_name)->save_dest = GUI_SECT; hegyi@1: } hegyi@1: hegyi@1: // restore the node coordinate maps hegyi@1: if (gui_data.node_coords_save_dest == hegyi@1: MapStorage::SpecMapSaveOpts::GUI_SECT) hegyi@1: { hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: node_coords.set(n, gui_data.node_coord_map[node_label[n]]); hegyi@1: } hegyi@1: node_coords_save_dest = gui_data.node_coords_save_dest; hegyi@1: } hegyi@1: // restore the arrow coordinate maps hegyi@1: if (gui_data.arrow_coords_save_dest == hegyi@1: MapStorage::SpecMapSaveOpts::GUI_SECT) hegyi@1: { hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: arrow_coords.set(e, gui_data.arrow_coord_map[arc_label[e]]); hegyi@1: } hegyi@1: arrow_coords_save_dest = gui_data.arrow_coords_save_dest; hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: // there is no gui section neither in the .lgf file nor in the .conf file hegyi@1: { hegyi@1: if (content.nodeSectionNum() < 1) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog("No nodeset found in file."); hegyi@1: mdialog.run(); hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: hegyi@1: if (content.arcSectionNum() < 1) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog("No arcset found in file."); hegyi@1: mdialog.run(); hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: hegyi@1: std::vector nodeMapNames = content.nodeMapNames(0); hegyi@1: std::vector arcMapNames = content.arcMapNames(0); hegyi@1: hegyi@1: bool read_arc_label = true; hegyi@1: if (std::find(arcMapNames.begin(), arcMapNames.end(), "label") == hegyi@1: arcMapNames.end()) hegyi@1: { hegyi@1: read_arc_label = false; hegyi@1: } hegyi@1: hegyi@1: nodeMapNames.erase( hegyi@1: std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"), hegyi@1: nodeMapNames.end()); hegyi@1: hegyi@1: arcMapNames.erase( hegyi@1: std::remove(arcMapNames.begin(), arcMapNames.end(), "label"), hegyi@1: arcMapNames.end()); hegyi@1: hegyi@1: FileImportDialog::ImportData data(nodeMapNames, arcMapNames); hegyi@1: FileImportDialog fidialog(&data); hegyi@1: int response = fidialog.run(); hegyi@1: if (response == Gtk::RESPONSE_OK) hegyi@1: { hegyi@1: try hegyi@1: { hegyi@1: std::string node_coord_xmap_name, node_coord_ymap_name; hegyi@1: std::string arrow_coord_xmap_name, arrow_coord_ymap_name; hegyi@1: bool gen_node_coords = false; hegyi@1: bool gen_arrow_coords = false; hegyi@1: hegyi@1: switch (data.node_coord_load_from) hegyi@1: { hegyi@1: case FileImportDialog::ImportData::ONE_MAP: hegyi@1: node_coord_xmap_name = data.node_coord_one_map_name + ":x"; hegyi@1: node_coord_ymap_name = data.node_coord_one_map_name + ":y"; hegyi@1: node_coords_one_map_name = data.node_coord_one_map_name; hegyi@1: hegyi@1: node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; hegyi@1: node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; hegyi@1: break; hegyi@1: case FileImportDialog::ImportData::TWO_MAPS: hegyi@1: node_coord_xmap_name = data.node_coord_two_maps_1_name; hegyi@1: node_coord_ymap_name = data.node_coord_two_maps_2_name; hegyi@1: node_coords_two_maps_1_name = data.node_coord_two_maps_1_name; hegyi@1: node_coords_two_maps_2_name = data.node_coord_two_maps_2_name; hegyi@1: hegyi@1: node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; hegyi@1: node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; hegyi@1: break; hegyi@1: case FileImportDialog::ImportData::DONT_READ: hegyi@1: node_coord_xmap_name = ""; hegyi@1: node_coord_ymap_name = ""; hegyi@1: hegyi@1: node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; hegyi@1: gen_node_coords = true; hegyi@1: break; hegyi@1: } hegyi@1: hegyi@1: switch (data.arrow_coord_load_from) hegyi@1: { hegyi@1: case FileImportDialog::ImportData::ONE_MAP: hegyi@1: arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x"; hegyi@1: arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y"; hegyi@1: arrow_coords_one_map_name = data.arrow_coord_one_map_name; hegyi@1: hegyi@1: arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; hegyi@1: arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; hegyi@1: break; hegyi@1: case FileImportDialog::ImportData::TWO_MAPS: hegyi@1: arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name; hegyi@1: arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name; hegyi@1: arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name; hegyi@1: arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name; hegyi@1: hegyi@1: arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; hegyi@1: arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; hegyi@1: break; hegyi@1: case FileImportDialog::ImportData::DONT_READ: hegyi@1: arrow_coord_xmap_name = ""; hegyi@1: arrow_coord_ymap_name = ""; hegyi@1: hegyi@1: arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; hegyi@1: gen_arrow_coords = true; hegyi@1: break; hegyi@1: } hegyi@1: hegyi@1: // read arc and node maps hegyi@1: std::vector node_map_names; hegyi@1: std::vector arc_map_names; hegyi@1: std::map node_map_types; hegyi@1: std::map arc_map_types; hegyi@1: for (std::vector::const_iterator it = hegyi@1: data.numeric_node_map_names.begin(); hegyi@1: it != data.numeric_node_map_names.end(); ++it) hegyi@1: { hegyi@1: node_map_names.push_back(*it); hegyi@1: node_map_types[*it] = MapValue::NUMERIC; hegyi@1: } hegyi@1: for (std::vector::const_iterator it = hegyi@1: data.string_node_map_names.begin(); hegyi@1: it != data.string_node_map_names.end(); ++it) hegyi@1: { hegyi@1: node_map_names.push_back(*it); hegyi@1: node_map_types[*it] = MapValue::STRING; hegyi@1: } hegyi@1: for (std::vector::const_iterator it = hegyi@1: data.numeric_arc_map_names.begin(); hegyi@1: it != data.numeric_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: arc_map_names.push_back(*it); hegyi@1: arc_map_types[*it] = MapValue::NUMERIC; hegyi@1: } hegyi@1: for (std::vector::const_iterator it = hegyi@1: data.string_arc_map_names.begin(); hegyi@1: it != data.string_arc_map_names.end(); ++it) hegyi@1: { hegyi@1: arc_map_names.push_back(*it); hegyi@1: arc_map_types[*it] = MapValue::STRING; hegyi@1: } hegyi@1: hegyi@1: readLGF(filename, read_arc_label, hegyi@1: node_map_names, arc_map_names, hegyi@1: node_map_types, arc_map_types, hegyi@1: node_coord_xmap_name, node_coord_ymap_name, hegyi@1: arrow_coord_xmap_name, arrow_coord_ymap_name); hegyi@1: hegyi@1: // generate arc labels hegyi@1: if (!read_arc_label) hegyi@1: { hegyi@1: int l = 0; hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: arc_label[e] = l++; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: if (gen_node_coords) hegyi@1: { hegyi@1: // generate node coordinates hegyi@1: int node_num = 0; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) { node_num++; } hegyi@1: const double pi = 3.142; hegyi@1: double step = 2 * pi / (double) node_num; hegyi@1: int i = 0; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: setNodeCoords(n, hegyi@1: XY(250.0 * std::cos(i * step), hegyi@1: 250.0 * std::sin(i * step))); hegyi@1: i++; hegyi@1: } hegyi@1: } hegyi@1: if (gen_arrow_coords) hegyi@1: { hegyi@1: // generate arrow coordinates hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: if (digraph.source(e) == digraph.target(e)) hegyi@1: { hegyi@1: setArrowCoords(e, hegyi@1: getNodeCoords(digraph.source(e)) + XY(0.0, 80.0)); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: setArrowCoords(e, hegyi@1: (getNodeCoords(digraph.source(e)) + hegyi@1: getNodeCoords(digraph.target(e))) / 2.0); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: catch (Exception& error) hegyi@1: { hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: clear(); hegyi@1: return 1; hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // set max_node_label hegyi@1: { hegyi@1: max_node_label = std::numeric_limits::min(); hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: if (node_label[n] > max_node_label) hegyi@1: { hegyi@1: max_node_label = node_label[n]; hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: // set max_arc_label hegyi@1: { hegyi@1: max_arc_label = std::numeric_limits::min(); hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: if (arc_label[e] > max_arc_label) hegyi@1: { hegyi@1: max_arc_label = arc_label[e]; hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: return 0; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::writeToFile(const std::string &filename) hegyi@1: { hegyi@1: // relabel nodes and arcs hegyi@1: int i = 0; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: node_label[n] = i++; hegyi@1: } hegyi@1: max_node_label = i-1; hegyi@1: i = 0; hegyi@1: for (ArcIt e(digraph); e != INVALID; ++e) hegyi@1: { hegyi@1: arc_label[e] = i++; hegyi@1: } hegyi@1: max_arc_label = i-1; hegyi@1: hegyi@1: // write .lgf file hegyi@1: { hegyi@1: DigraphWriter gwriter(filename, digraph); hegyi@1: hegyi@1: gwriter.nodeMap("label", node_label); hegyi@1: gwriter.arcMap("label", arc_label); hegyi@1: hegyi@1: // write node maps hegyi@1: for (NodeMapStore::const_iterator it = nodemaps.begin(); hegyi@1: it != nodemaps.end(); ++it) hegyi@1: { hegyi@1: if (it->second->save_dest == NESET_SECT) hegyi@1: { hegyi@1: switch (it->second->type()) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: gwriter.nodeMap(it->first, getNumericNodeMap(it->first)); hegyi@1: break; hegyi@1: case MapValue::STRING: hegyi@1: gwriter.nodeMap(it->first, getStringNodeMap(it->first)); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // write arc maps hegyi@1: for (ArcMapStore::const_iterator it = arcmaps.begin(); hegyi@1: it != arcmaps.end(); ++it) hegyi@1: { hegyi@1: if (it->second->save_dest == NESET_SECT) hegyi@1: { hegyi@1: switch (it->second->type()) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: gwriter.arcMap(it->first, getNumericArcMap(it->first)); hegyi@1: break; hegyi@1: case MapValue::STRING: hegyi@1: gwriter.arcMap(it->first, getStringArcMap(it->first)); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // write node coordinates hegyi@1: switch (getNodeCoordsSaveDest()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::GUI_SECT: hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::NESET_SECT: hegyi@1: switch (getNodeCoordsSaveMapNum()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::ONE_MAP: hegyi@1: gwriter.nodeMap(node_coords_one_map_name + ":x", hegyi@1: node_coords_x); hegyi@1: gwriter.nodeMap(node_coords_one_map_name + ":y", hegyi@1: node_coords_y); hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::TWO_MAPS: hegyi@1: gwriter.nodeMap(node_coords_two_maps_1_name, hegyi@1: node_coords_x); hegyi@1: gwriter.nodeMap(node_coords_two_maps_2_name, hegyi@1: node_coords_y); hegyi@1: break; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: hegyi@1: // write arrow coordinates hegyi@1: switch (getArrowCoordsSaveDest()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::GUI_SECT: hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::NESET_SECT: hegyi@1: switch (getArrowCoordsSaveMapNum()) hegyi@1: { hegyi@1: case MapStorage::SpecMapSaveOpts::ONE_MAP: hegyi@1: gwriter.arcMap(arrow_coords_one_map_name + ":x", hegyi@1: arrow_coords_x); hegyi@1: gwriter.arcMap(arrow_coords_one_map_name + ":y", hegyi@1: arrow_coords_y); hegyi@1: break; hegyi@1: case MapStorage::SpecMapSaveOpts::TWO_MAPS: hegyi@1: gwriter.arcMap(arrow_coords_two_maps_1_name, hegyi@1: arrow_coords_x); hegyi@1: gwriter.arcMap(arrow_coords_two_maps_2_name, hegyi@1: arrow_coords_y); hegyi@1: break; hegyi@1: } hegyi@1: break; hegyi@1: } hegyi@1: hegyi@1: if (gui_sect_save_dest == LGF_FILE) hegyi@1: { hegyi@1: GuiWriter gui_writer(this); hegyi@1: gui_writer.write(gwriter.ostream()); hegyi@1: gwriter.run(); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: gwriter.run(); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: // write .conf file hegyi@1: if (gui_sect_save_dest == CONF_FILE) hegyi@1: { hegyi@1: DigraphWriter lwriter(filename + ".conf", digraph); hegyi@1: GuiWriter gui_writer(this); hegyi@1: gui_writer.write(lwriter.ostream()); hegyi@1: lwriter.run(); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void MapStorage::clear() hegyi@1: { hegyi@1: for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: nodemaps.erase(it); hegyi@1: } hegyi@1: for (ArcMapStore::iterator it = arcmaps.begin(); it != arcmaps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: arcmaps.erase(it); hegyi@1: } hegyi@1: digraph.clear(); hegyi@1: file_name = ""; hegyi@1: modified = false; hegyi@1: max_node_label = 0; hegyi@1: max_arc_label = 0; hegyi@1: background_set = false; hegyi@1: hegyi@1: gui_sect_save_dest = LGF_FILE; hegyi@1: node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; hegyi@1: arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; hegyi@1: node_coords_one_map_name = "coord"; hegyi@1: node_coords_two_maps_1_name = "coord_x"; hegyi@1: node_coords_two_maps_2_name = "coord_y"; hegyi@1: arrow_coords_one_map_name = "arrow"; hegyi@1: arrow_coords_two_maps_1_name = "arrow_x"; hegyi@1: arrow_coords_two_maps_2_name = "arrow_y"; hegyi@1: hegyi@1: for(int i=0;iget(node); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::set(const std::string& name, Node node, MapValue val) hegyi@1: { hegyi@1: NodeMapData* data = getNodeMapData(name); hegyi@1: data->set(node, val); hegyi@1: } hegyi@1: hegyi@1: MapValue MapStorage::get(const std::string& name, Arc arc) const hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(name); hegyi@1: return data->get(arc); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::set(const std::string& name, Arc arc, MapValue val) hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(name); hegyi@1: data->set(arc, val); hegyi@1: } hegyi@1: hegyi@1: const std::string& MapStorage::getFileName() const hegyi@1: { hegyi@1: return file_name; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setFileName(const std::string& fn) hegyi@1: { hegyi@1: file_name = fn; hegyi@1: } hegyi@1: hegyi@1: bool MapStorage::getModified() const hegyi@1: { hegyi@1: return modified; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setModified(bool m) hegyi@1: { hegyi@1: modified = m; hegyi@1: } hegyi@1: hegyi@1: Node MapStorage::addNode(XY coords) hegyi@1: { hegyi@1: Node node = digraph.addNode(); hegyi@1: hegyi@1: setNodeCoords(node, coords); hegyi@1: hegyi@1: max_node_label++; hegyi@1: hegyi@1: node_label[node] = max_node_label; hegyi@1: hegyi@1: std::vector node_maps = getNodeMapList(); hegyi@1: for (std::vector::const_iterator it = node_maps.begin(); hegyi@1: it != node_maps.end(); ++it) hegyi@1: { hegyi@1: NodeMapData* data = getNodeMapData(*it); hegyi@1: set(*it, node, data->default_value); hegyi@1: } hegyi@1: hegyi@1: return node; hegyi@1: } hegyi@1: hegyi@1: Arc MapStorage::addArc(Node from, Node to) hegyi@1: { hegyi@1: Arc arc = digraph.addArc(from, to); hegyi@1: hegyi@1: if (from == to) hegyi@1: { hegyi@1: setArrowCoords(arc, getNodeCoords(from) + XY(0.0, 80.0)); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: setArrowCoords(arc, (getNodeCoords(from) + getNodeCoords(to)) / 2.0); hegyi@1: } hegyi@1: hegyi@1: max_arc_label++; hegyi@1: hegyi@1: arc_label[arc] = max_arc_label; hegyi@1: hegyi@1: std::vector arc_maps = getArcMapList(); hegyi@1: for (std::vector::const_iterator it = arc_maps.begin(); hegyi@1: it != arc_maps.end(); ++it) hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(*it); hegyi@1: set(*it, arc, data->default_value); hegyi@1: } hegyi@1: return arc; hegyi@1: } hegyi@1: hegyi@1: MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name) hegyi@1: { hegyi@1: NodeMapData* data = getNodeMapData(name); hegyi@1: if (data->type() != MapValue::NUMERIC) hegyi@1: throw Error("Numeric node map " + name + " does not exists."); hegyi@1: return static_cast(data)->map; hegyi@1: } hegyi@1: hegyi@1: MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name) hegyi@1: { hegyi@1: NodeMapData* data = getNodeMapData(name); hegyi@1: if (data->type() != MapValue::STRING) hegyi@1: throw Error("String node map " + name + " does not exists."); hegyi@1: return static_cast(data)->map; hegyi@1: } hegyi@1: hegyi@1: MapStorage::NumericArcMap& MapStorage::getNumericArcMap(const std::string& name) hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(name); hegyi@1: if (data->type() != MapValue::NUMERIC) hegyi@1: throw Error("Numeric arc map " + name + " does not exists."); hegyi@1: return static_cast(data)->map; hegyi@1: } hegyi@1: hegyi@1: MapStorage::StringArcMap& MapStorage::getStringArcMap(const std::string& name) hegyi@1: { hegyi@1: ArcMapData* data = getArcMapData(name); hegyi@1: if (data->type() != MapValue::STRING) hegyi@1: throw Error("String arc map " + name + " does not exists."); hegyi@1: return static_cast(data)->map; hegyi@1: } hegyi@1: hegyi@1: MapValueArcMap MapStorage::getArcMap(const std::string& name) hegyi@1: { hegyi@1: return MapValueArcMap(name, this); hegyi@1: } hegyi@1: hegyi@1: MapValueNodeMap MapStorage::getNodeMap(const std::string& name) hegyi@1: { hegyi@1: return MapValueNodeMap(name, this); hegyi@1: } hegyi@1: hegyi@1: int MapStorage::getLabel(Node n) const hegyi@1: { hegyi@1: return node_label[n]; hegyi@1: } hegyi@1: hegyi@1: int MapStorage::getLabel(Arc e) const hegyi@1: { hegyi@1: return arc_label[e]; hegyi@1: } hegyi@1: hegyi@1: MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation() hegyi@1: { hegyi@1: return gui_sect_save_dest; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest) hegyi@1: { hegyi@1: gui_sect_save_dest = dest; hegyi@1: } hegyi@1: hegyi@1: MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const hegyi@1: { hegyi@1: NodeMapData *data = getNodeMapData(name); hegyi@1: return data->save_dest; hegyi@1: } hegyi@1: hegyi@1: MapStorage::MapSaveDest MapStorage::getArcMapSaveDest(std::string name) const hegyi@1: { hegyi@1: ArcMapData *data = getArcMapData(name); hegyi@1: return data->save_dest; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest) hegyi@1: { hegyi@1: NodeMapData *data = getNodeMapData(name); hegyi@1: data->save_dest = dest; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setArcMapSaveDest(std::string name, MapStorage::MapSaveDest dest) hegyi@1: { hegyi@1: ArcMapData *data = getArcMapData(name); hegyi@1: data->save_dest = dest; hegyi@1: } hegyi@1: hegyi@1: MapStorage::ArcMapData* MapStorage::getArcMapData(std::string name) const hegyi@1: { hegyi@1: ArcMapStore::const_iterator it = arcmaps.find(name); hegyi@1: if (it != arcmaps.end()) hegyi@1: return it->second; hegyi@1: else hegyi@1: throw Error("Arc map " + name + " does not exists."); hegyi@1: } hegyi@1: hegyi@1: MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const hegyi@1: { hegyi@1: NodeMapStore::const_iterator it = nodemaps.find(name); hegyi@1: if (it != nodemaps.end()) hegyi@1: return it->second; hegyi@1: else hegyi@1: throw Error("Node map " + name + " does not exists."); hegyi@1: } hegyi@1: hegyi@1: MapValue::Type MapStorage::getNodeMapElementType(std::string name) const hegyi@1: { hegyi@1: NodeMapData *data = getNodeMapData(name); hegyi@1: return data->type(); hegyi@1: } hegyi@1: hegyi@1: MapValue::Type MapStorage::getArcMapElementType(std::string name) const hegyi@1: { hegyi@1: ArcMapData *data = getArcMapData(name); hegyi@1: return data->type(); hegyi@1: } hegyi@1: hegyi@1: const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap() hegyi@1: { hegyi@1: return node_label; hegyi@1: } hegyi@1: hegyi@1: const MapStorage::ArcLabelMap& MapStorage::getArcLabelMap() hegyi@1: { hegyi@1: return arc_label; hegyi@1: } hegyi@1: hegyi@1: const Digraph& MapStorage::getDigraph() hegyi@1: { hegyi@1: return digraph; hegyi@1: } hegyi@1: hegyi@1: bool MapStorage::nodeMapExists(std::string name) hegyi@1: { hegyi@1: NodeMapStore::const_iterator it = nodemaps.find(name); hegyi@1: if (it == nodemaps.end()) hegyi@1: return false; hegyi@1: else hegyi@1: return true; hegyi@1: } hegyi@1: hegyi@1: bool MapStorage::arcMapExists(std::string name) hegyi@1: { hegyi@1: ArcMapStore::const_iterator it = arcmaps.find(name); hegyi@1: if (it == arcmaps.end()) hegyi@1: return false; hegyi@1: else hegyi@1: return true; hegyi@1: } hegyi@1: hegyi@1: std::vector MapStorage::getArcMaps(MapType type) hegyi@1: { hegyi@1: std::vector maps; hegyi@1: for (ArcMapStore::const_iterator it = arcmaps.begin(); it != arcmaps.end(); ++it) hegyi@1: { hegyi@1: if (it->second->type() & type) hegyi@1: { hegyi@1: maps.push_back(it->first); hegyi@1: } hegyi@1: } hegyi@1: return maps; hegyi@1: } hegyi@1: hegyi@1: std::vector MapStorage::getNodeMaps(MapType type) hegyi@1: { hegyi@1: std::vector maps; hegyi@1: for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) hegyi@1: { hegyi@1: if (it->second->type() & type) hegyi@1: { hegyi@1: maps.push_back(it->first); hegyi@1: } hegyi@1: } hegyi@1: return maps; hegyi@1: } hegyi@1: hegyi@1: MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap() hegyi@1: { hegyi@1: return node_coords; hegyi@1: } hegyi@1: hegyi@1: MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap() hegyi@1: { hegyi@1: return arrow_coords; hegyi@1: } hegyi@1: hegyi@1: MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest() hegyi@1: { hegyi@1: return node_coords_save_dest; hegyi@1: } hegyi@1: hegyi@1: MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest() hegyi@1: { hegyi@1: return arrow_coords_save_dest; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) hegyi@1: { hegyi@1: node_coords_save_dest = dest; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) hegyi@1: { hegyi@1: arrow_coords_save_dest = dest; hegyi@1: } hegyi@1: hegyi@1: MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum() hegyi@1: { hegyi@1: return node_coords_save_map_num; hegyi@1: } hegyi@1: hegyi@1: MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum() hegyi@1: { hegyi@1: return arrow_coords_save_map_num; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) hegyi@1: { hegyi@1: node_coords_save_map_num = num; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) hegyi@1: { hegyi@1: arrow_coords_save_map_num = num; hegyi@1: } hegyi@1: hegyi@1: const std::string& MapStorage::getNodeCoordsOneMapName() hegyi@1: { hegyi@1: return node_coords_one_map_name; hegyi@1: } hegyi@1: const std::string& MapStorage::getNodeCoordsTwoMaps1Name() hegyi@1: { hegyi@1: return node_coords_two_maps_1_name; hegyi@1: } hegyi@1: const std::string& MapStorage::getNodeCoordsTwoMaps2Name() hegyi@1: { hegyi@1: return node_coords_two_maps_2_name; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setNodeCoordsOneMapName(const std::string& name) hegyi@1: { hegyi@1: node_coords_one_map_name = name; hegyi@1: } hegyi@1: void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name) hegyi@1: { hegyi@1: node_coords_two_maps_1_name = name; hegyi@1: } hegyi@1: void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name) hegyi@1: { hegyi@1: node_coords_two_maps_2_name = name; hegyi@1: } hegyi@1: hegyi@1: const std::string& MapStorage::getArrowCoordsOneMapName() hegyi@1: { hegyi@1: return arrow_coords_one_map_name; hegyi@1: } hegyi@1: const std::string& MapStorage::getArrowCoordsTwoMaps1Name() hegyi@1: { hegyi@1: return arrow_coords_two_maps_1_name; hegyi@1: } hegyi@1: const std::string& MapStorage::getArrowCoordsTwoMaps2Name() hegyi@1: { hegyi@1: return arrow_coords_two_maps_2_name; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setArrowCoordsOneMapName(const std::string& name) hegyi@1: { hegyi@1: arrow_coords_one_map_name = name; hegyi@1: } hegyi@1: void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name) hegyi@1: { hegyi@1: arrow_coords_two_maps_1_name = name; hegyi@1: } hegyi@1: void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name) hegyi@1: { hegyi@1: arrow_coords_two_maps_2_name = name; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::readLGF( hegyi@1: const std::string& filename, hegyi@1: bool read_arc_label, hegyi@1: const std::vector& node_map_names, hegyi@1: const std::vector& arc_map_names, hegyi@1: const std::map& node_map_types, hegyi@1: const std::map& arc_map_types, hegyi@1: const std::string& node_coord_xmap_name, hegyi@1: const std::string& node_coord_ymap_name, hegyi@1: const std::string& arrow_coord_xmap_name, hegyi@1: const std::string& arrow_coord_ymap_name) hegyi@1: { hegyi@1: using std::vector; hegyi@1: using std::map; hegyi@1: using std::string; hegyi@1: hegyi@1: DigraphReader greader(filename, digraph); hegyi@1: hegyi@1: // read the label maps hegyi@1: greader.nodeMap("label", node_label); hegyi@1: if (read_arc_label) hegyi@1: greader.arcMap("label", arc_label); hegyi@1: hegyi@1: // read the node maps hegyi@1: for (vector::const_iterator hegyi@1: it = node_map_names.begin(); hegyi@1: it != node_map_names.end(); ++it) hegyi@1: { hegyi@1: switch (node_map_types.find(*it)->second) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: createNodeMap(*it, MapValue::NUMERIC, double()); hegyi@1: greader.nodeMap(*it, getNumericNodeMap(*it)); hegyi@1: break; hegyi@1: } hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: createNodeMap(*it, MapValue::STRING, string()); hegyi@1: greader.nodeMap(*it, getStringNodeMap(*it)); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: getNodeMapData(*it)->save_dest = NESET_SECT; hegyi@1: } hegyi@1: hegyi@1: // read the arc maps hegyi@1: for (vector::const_iterator hegyi@1: it = arc_map_names.begin(); hegyi@1: it != arc_map_names.end(); ++it) hegyi@1: { hegyi@1: switch (arc_map_types.find(*it)->second) hegyi@1: { hegyi@1: case MapValue::NUMERIC: hegyi@1: { hegyi@1: createArcMap(*it, MapValue::NUMERIC, double()); hegyi@1: greader.arcMap(*it, getNumericArcMap(*it)); hegyi@1: break; hegyi@1: } hegyi@1: case MapValue::STRING: hegyi@1: { hegyi@1: createArcMap(*it, MapValue::STRING, string()); hegyi@1: greader.arcMap(*it, getStringArcMap(*it)); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: getArcMapData(*it)->save_dest = NESET_SECT; hegyi@1: } hegyi@1: hegyi@1: // read the node coordinate maps hegyi@1: if (node_coord_xmap_name != "") hegyi@1: greader.nodeMap(node_coord_xmap_name, node_coords_x); hegyi@1: if (node_coord_ymap_name != "") hegyi@1: greader.nodeMap(node_coord_ymap_name, node_coords_y); hegyi@1: hegyi@1: // read the arrow coordinate maps hegyi@1: if (arrow_coord_xmap_name != "") hegyi@1: greader.arcMap(arrow_coord_xmap_name, arrow_coords_x); hegyi@1: if (arrow_coord_ymap_name != "") hegyi@1: greader.arcMap(arrow_coord_ymap_name, arrow_coords_y); hegyi@1: hegyi@1: greader.run(); hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setBackground(const std::string& file_name) hegyi@1: { hegyi@1: if (file_name == background_file_name) return; hegyi@1: if (file_name == "") hegyi@1: { hegyi@1: background_file_name = ""; hegyi@1: background_set = false; hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: background_file_name = file_name; hegyi@1: background_set = true; hegyi@1: } hegyi@1: signal_background.emit(); hegyi@1: } hegyi@1: hegyi@1: const std::string& MapStorage::getBackgroundFilename() hegyi@1: { hegyi@1: return background_file_name; hegyi@1: } hegyi@1: hegyi@1: bool MapStorage::isBackgroundSet() hegyi@1: { hegyi@1: return background_set; hegyi@1: } hegyi@1: hegyi@1: double MapStorage::getBackgroundScaling() hegyi@1: { hegyi@1: return background_scaling; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::setBackgroundScaling(double scaling) hegyi@1: { hegyi@1: background_scaling = scaling; hegyi@1: } hegyi@1: hegyi@1: void MapStorage::exportDigraphToEPS(std::vector options, std::string filename, std::string shapemap) hegyi@1: { hegyi@1: Digraph::NodeMap _shapes(digraph, 0); hegyi@1: Digraph::NodeMap _nodeColors(digraph, 0); hegyi@1: Digraph::ArcMap _arcColors(digraph, 0); hegyi@1: Digraph::NodeMap _nodeSizes(digraph, 6.0); hegyi@1: Digraph::ArcMap _arcWidths(digraph, 1.0); hegyi@1: bool _drawArrows=options[ARROWS]; hegyi@1: bool _enableParallel=options[PAR]; hegyi@1: hegyi@1: std::string emptyString=""; hegyi@1: Digraph::NodeMap _nodeTextMap(digraph,emptyString); hegyi@1: hegyi@1: //_nodeTextMap=(Digraph::NodeMap *)&emptyStringMap; hegyi@1: hegyi@1: if(options[N_MAPS]) hegyi@1: { hegyi@1: if(active_nodemaps[N_RADIUS]!="") hegyi@1: { hegyi@1: _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]); hegyi@1: } hegyi@1: if(active_nodemaps[N_COLOR]!="") hegyi@1: { hegyi@1: for(NodeIt ni(digraph);ni!=INVALID;++ni) hegyi@1: { hegyi@1: _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni); hegyi@1: } hegyi@1: } hegyi@1: if(active_nodemaps[N_TEXT]!="") hegyi@1: { hegyi@1: for(NodeIt ni(digraph);ni!=INVALID;++ni) hegyi@1: { hegyi@1: std::ostringstream o; hegyi@1: o << get(active_nodemaps[N_TEXT], ni); hegyi@1: _nodeTextMap[ni]=o.str(); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: if(options[E_MAPS]) hegyi@1: { hegyi@1: if(active_arcmaps[E_WIDTH]!="") hegyi@1: { hegyi@1: _arcWidths=getNumericArcMap(active_arcmaps[E_WIDTH]); hegyi@1: } hegyi@1: if(active_arcmaps[E_COLOR]!="") hegyi@1: { hegyi@1: for(ArcIt ei(digraph);ei!=INVALID;++ei) hegyi@1: { hegyi@1: _arcColors[ei]=(int)get(active_arcmaps[E_COLOR], ei); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: if(shapemap!="Default values") hegyi@1: { hegyi@1: double min = std::numeric_limits::max(); hegyi@1: double max = std::numeric_limits::min(); hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: double v = static_cast(get(shapemap, n)); hegyi@1: if (v < min) min = v; hegyi@1: if (v > max) max = v; hegyi@1: } hegyi@1: if((min>=0)&&(max<=4)) hegyi@1: { hegyi@1: NumericNodeMap& map = static_cast(getNodeMapData(shapemap))->map; hegyi@1: for (NodeIt n(digraph); n != INVALID; ++n) hegyi@1: { hegyi@1: _shapes[n] = static_cast(map[n]); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: Palette palette; hegyi@1: Palette paletteW(true); hegyi@1: hegyi@1: graphToEps(digraph,filename). hegyi@1: title("Sample .eps figure (fits to A4)"). hegyi@1: copyright("(C) 2006 LEMON Project"). hegyi@1: absoluteNodeSizes().absoluteArcWidths(). hegyi@1: nodeScale(2).nodeSizes(_nodeSizes). hegyi@1: coords(node_coords). hegyi@1: nodeShapes(_shapes). hegyi@1: nodeColors(composeMap(paletteW,_nodeColors)). hegyi@1: arcColors(composeMap(palette,_arcColors)). hegyi@1: arcWidthScale(0.3).arcWidths(_arcWidths). hegyi@1: nodeTexts(_nodeTextMap).nodeTextSize(7). hegyi@1: enableParallel(_enableParallel).parArcDist(5). hegyi@1: drawArrows(_drawArrows).arrowWidth(7).arrowLength(7). hegyi@1: run(); hegyi@1: hegyi@1: }