mapstorage.cc
changeset 1 67188bd752db
child 7 f227a74db59d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mapstorage.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,1534 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all cop	ies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include "i18n.h"
    1.23 +#include <limits>
    1.24 +#include <cmath>
    1.25 +#include <iostream>
    1.26 +#include <fstream>
    1.27 +#include <string>
    1.28 +#include <algorithm>
    1.29 +#include <gtkmm.h>
    1.30 +#include "file_import_dialog.h"
    1.31 +#include <mapstorage.h>
    1.32 +#include <gui_writer.h>
    1.33 +#include <gui_reader.h>
    1.34 +#include <lemon/graph_to_eps.h>
    1.35 +#include <lemon/lgf_reader.h>
    1.36 +#include <lemon/lgf_writer.h>
    1.37 +
    1.38 +const int i_d=20;
    1.39 +const double a_d=0.05;
    1.40 +const double p_d=40000;
    1.41 +
    1.42 +MapStorage::MapStorage() :
    1.43 +  gui_sect_save_dest(LGF_FILE),
    1.44 +  node_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
    1.45 +  arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
    1.46 +  modified(false),
    1.47 +  file_name(""),
    1.48 +  max_node_label(0),
    1.49 +  max_arc_label(0),
    1.50 +  node_coords_one_map_name("coord"),
    1.51 +  node_coords_two_maps_1_name("coord_x"),
    1.52 +  node_coords_two_maps_2_name("coord_y"),
    1.53 +  arrow_coords_one_map_name("arrow"),
    1.54 +  arrow_coords_two_maps_1_name("arrow_x"),
    1.55 +  arrow_coords_two_maps_2_name("arrow_y"),
    1.56 +  iterations(i_d),
    1.57 +  attraction(a_d),
    1.58 +  propulsation(p_d),
    1.59 +  node_coords_x(digraph),
    1.60 +  node_coords_y(digraph),
    1.61 +  arrow_coords_x(digraph),
    1.62 +  arrow_coords_y(digraph),
    1.63 +  node_label(digraph),
    1.64 +  arc_label(digraph),
    1.65 +  background_set(false)
    1.66 +{
    1.67 +  node_coords.setXMap(node_coords_x);
    1.68 +  node_coords.setYMap(node_coords_y);
    1.69 +  arrow_coords.setXMap(arrow_coords_x);
    1.70 +  arrow_coords.setYMap(arrow_coords_y);
    1.71 +
    1.72 +  active_nodemaps.resize(NODE_PROPERTY_NUM);
    1.73 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    1.74 +    {
    1.75 +      active_nodemaps[i]="";
    1.76 +    }
    1.77 +
    1.78 +  active_arcmaps.resize(EDGE_PROPERTY_NUM);
    1.79 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    1.80 +    {
    1.81 +      active_arcmaps[i]="";
    1.82 +    }
    1.83 +}
    1.84 +
    1.85 +MapStorage::~MapStorage()
    1.86 +{
    1.87 +  clear();
    1.88 +}
    1.89 +
    1.90 +void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
    1.91 +    MapValue def_val)
    1.92 +{
    1.93 +  NodeMapStore::const_iterator it = nodemaps.find(name);
    1.94 +  if (it != nodemaps.end())
    1.95 +    throw Error("Node map " + name + " already exists.");
    1.96 +
    1.97 +  switch (type)
    1.98 +  {
    1.99 +    case MapValue::NUMERIC:
   1.100 +      nodemaps[name] = new NumericNodeMapData(digraph, def_val);
   1.101 +      break;
   1.102 +    case MapValue::STRING:
   1.103 +      nodemaps[name] = new StringNodeMapData(digraph, def_val);
   1.104 +      break;
   1.105 +  }
   1.106 +
   1.107 +  nodemaps[name]->default_value = def_val;
   1.108 +
   1.109 +  signal_node_map.emit(name, type);
   1.110 +}
   1.111 +
   1.112 +void MapStorage::createArcMap(const std::string& name, MapValue::Type type,
   1.113 +    MapValue def_val)
   1.114 +{
   1.115 +  ArcMapStore::const_iterator it = arcmaps.find(name);
   1.116 +  if (it != arcmaps.end())
   1.117 +    throw Error("Arc map " + name + " already exists.");
   1.118 +
   1.119 +  switch (type)
   1.120 +  {
   1.121 +    case MapValue::NUMERIC:
   1.122 +      arcmaps[name] = new NumericArcMapData(digraph, def_val);
   1.123 +      break;
   1.124 +    case MapValue::STRING:
   1.125 +      arcmaps[name] = new StringArcMapData(digraph, def_val);
   1.126 +      break;
   1.127 +  }
   1.128 +
   1.129 +  arcmaps[name]->default_value = def_val;
   1.130 +
   1.131 +  signal_arc_map.emit(name, type);
   1.132 +}
   1.133 +
   1.134 +void MapStorage::changeActiveMap(bool itisarc, int prop, std::string mapname)
   1.135 +{
   1.136 +  if(itisarc)
   1.137 +    {
   1.138 +      active_arcmaps[prop]=mapname;
   1.139 +    }
   1.140 +  else
   1.141 +    {
   1.142 +      active_nodemaps[prop]=mapname;
   1.143 +    }
   1.144 +  signal_prop.emit(itisarc, prop);
   1.145 +}
   1.146 +
   1.147 +void MapStorage::broadcastActiveMaps()
   1.148 +{
   1.149 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.150 +    {
   1.151 +      signal_map_win.emit(false, i, active_nodemaps[i]);
   1.152 +    }
   1.153 +  
   1.154 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.155 +    {
   1.156 +      signal_map_win.emit(true, i, active_arcmaps[i]);
   1.157 +    }
   1.158 +}
   1.159 +
   1.160 +std::string MapStorage::getActiveArcMap(int prop)
   1.161 +{
   1.162 +  return active_arcmaps[prop];
   1.163 +}
   1.164 +
   1.165 +std::string MapStorage::getActiveNodeMap(int prop)
   1.166 +{
   1.167 +  return active_nodemaps[prop];
   1.168 +}
   1.169 +
   1.170 +std::vector<std::string> MapStorage::getArcMapList(MapType type)
   1.171 +{
   1.172 +  if (type == ALL)
   1.173 +  {
   1.174 +    std::vector<std::string> ret;
   1.175 +    for (ArcMapStore::const_iterator it = arcmaps.begin();
   1.176 +        it != arcmaps.end(); ++it)
   1.177 +    {
   1.178 +      ret.push_back(it->first);
   1.179 +    }
   1.180 +    return ret;
   1.181 +  }
   1.182 +  else
   1.183 +  {
   1.184 +    std::vector<std::string> ret;
   1.185 +    for (ArcMapStore::const_iterator it = arcmaps.begin();
   1.186 +        it != arcmaps.end(); ++it)
   1.187 +    {
   1.188 +      ArcMapData* data = getArcMapData(it->first);
   1.189 +      MapValue::Type t = data->type();
   1.190 +      if ((t == MapValue::NUMERIC && (type & NUM)) ||
   1.191 +          (t == MapValue::STRING && (type & STR)))
   1.192 +      {
   1.193 +        ret.push_back(it->first);
   1.194 +      }
   1.195 +    }
   1.196 +    return ret;
   1.197 +  }
   1.198 +}
   1.199 +
   1.200 +std::vector<std::string> MapStorage::getNodeMapList(MapType type)
   1.201 +{
   1.202 +  if (type == ALL)
   1.203 +  {
   1.204 +    std::vector<std::string> ret;
   1.205 +    for (NodeMapStore::const_iterator it = nodemaps.begin();
   1.206 +        it != nodemaps.end(); ++it)
   1.207 +    {
   1.208 +      ret.push_back(it->first);
   1.209 +    }
   1.210 +    return ret;
   1.211 +  }
   1.212 +  else
   1.213 +  {
   1.214 +    std::vector<std::string> ret;
   1.215 +    for (NodeMapStore::const_iterator it = nodemaps.begin();
   1.216 +        it != nodemaps.end(); ++it)
   1.217 +    {
   1.218 +      NodeMapData* data = getNodeMapData(it->first);
   1.219 +      MapValue::Type t = data->type();
   1.220 +      if ((t == MapValue::NUMERIC && (type & NUM)) ||
   1.221 +          (t == MapValue::STRING && (type & STR)))
   1.222 +      {
   1.223 +        ret.push_back(it->first);
   1.224 +      }
   1.225 +    }
   1.226 +    return ret;
   1.227 +  }
   1.228 +}
   1.229 +
   1.230 +sigc::signal<void, bool, int> MapStorage::signal_prop_ch()
   1.231 +{
   1.232 +  return signal_prop;
   1.233 +}
   1.234 +
   1.235 +int MapStorage::readFromFile(const std::string &filename)
   1.236 +{
   1.237 +  using std::vector;
   1.238 +  using std::map;
   1.239 +  using std::string;
   1.240 +
   1.241 +  //reading content of file
   1.242 +  LgfContents content(filename);
   1.243 +  try
   1.244 +    {
   1.245 +      content.run();
   1.246 +    }
   1.247 +  catch (Exception& error)
   1.248 +    {
   1.249 +      Gtk::MessageDialog mdialog(error.what());
   1.250 +      mdialog.run();
   1.251 +      clear();
   1.252 +      return 1;
   1.253 +    }
   1.254 +
   1.255 +  // check whether the .conf file exists
   1.256 +  bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(),
   1.257 +      (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
   1.258 +
   1.259 +  // check whether the .lgf file contains a gui section
   1.260 +  bool gui_data_in_lgf = false;
   1.261 +  {
   1.262 +    for(int i=0;i<content.extraSectionNum();i++)
   1.263 +      {
   1.264 +	if(content.extraSection(i)=="gui")
   1.265 +	  {
   1.266 +	    gui_data_in_lgf = true;
   1.267 +	  }
   1.268 +      }
   1.269 +  }
   1.270 +
   1.271 +  bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
   1.272 +
   1.273 +  // ask for user input if both exist
   1.274 +  bool use_gui_data_in_lgf = false;
   1.275 +  if (gui_data_in_conf && gui_data_in_lgf)
   1.276 +  {
   1.277 +    Gtk::MessageDialog mdialog(_("<b>Found both ") + filename +
   1.278 +        _(".conf and a gui section in ") + filename + _(".</b>"), true,
   1.279 +        Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
   1.280 +	  mdialog.add_button(_("Use the ._conf file"), 1);
   1.281 +	  mdialog.add_button(_("Use the _gui section"), 2);
   1.282 +    switch (mdialog.run())
   1.283 +    {
   1.284 +      case 1:
   1.285 +        use_gui_data_in_lgf = false;
   1.286 +        break;
   1.287 +      case 2:
   1.288 +        use_gui_data_in_lgf = true;
   1.289 +        break;
   1.290 +      case Gtk::RESPONSE_NONE:
   1.291 +        return 1;
   1.292 +    }
   1.293 +  }
   1.294 +  else
   1.295 +  {
   1.296 +    use_gui_data_in_lgf = gui_data_in_lgf;
   1.297 +  }
   1.298 +
   1.299 +  if (gui_data_found)
   1.300 +  {
   1.301 +    GUISectData gui_data;
   1.302 +    if (use_gui_data_in_lgf)
   1.303 +    {
   1.304 +      // read the gui section from the .lgf file
   1.305 +      try
   1.306 +      {
   1.307 +	sectionReader(filename).sectionStream("gui", GuiReader(this, gui_data)).run();
   1.308 +        gui_sect_save_dest = LGF_FILE;
   1.309 +      }
   1.310 +      catch (Exception& error)
   1.311 +      {
   1.312 +        clear();
   1.313 +        return 1;
   1.314 +      }
   1.315 +    }
   1.316 +    else
   1.317 +    {
   1.318 +      // read the gui section from the .conf file
   1.319 +      try
   1.320 +      {
   1.321 +	sectionReader(filename + ".conf").sectionStream("gui", GuiReader(this, gui_data)).run();
   1.322 +        gui_sect_save_dest = CONF_FILE;
   1.323 +      }
   1.324 +      catch (Exception& error)
   1.325 +      {
   1.326 +        clear();
   1.327 +        return 1;
   1.328 +      }
   1.329 +    }
   1.330 +
   1.331 +    // read the digraph and maps form the .lgf file
   1.332 +    try
   1.333 +    {
   1.334 +      std::string node_coord_xmap_name, node_coord_ymap_name;
   1.335 +      std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
   1.336 +
   1.337 +      if (gui_data.node_coords_save_dest ==
   1.338 +          MapStorage::SpecMapSaveOpts::NESET_SECT)
   1.339 +      {
   1.340 +        switch (gui_data.node_coords_save_map_num)
   1.341 +        {
   1.342 +          case SpecMapSaveOpts::ONE_MAP:
   1.343 +            node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x";
   1.344 +            node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y";
   1.345 +            node_coords_one_map_name = gui_data.node_coords_one_map_name;
   1.346 +            break;
   1.347 +          case SpecMapSaveOpts::TWO_MAPS:
   1.348 +            node_coord_xmap_name = gui_data.node_coords_two_maps_1_name;
   1.349 +            node_coord_ymap_name = gui_data.node_coords_two_maps_2_name;
   1.350 +            node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name;
   1.351 +            node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name;
   1.352 +            break;
   1.353 +        }
   1.354 +        node_coords_save_dest = gui_data.node_coords_save_dest;
   1.355 +        node_coords_save_map_num = gui_data.node_coords_save_map_num;
   1.356 +      }
   1.357 +
   1.358 +      if (gui_data.arrow_coords_save_dest ==
   1.359 +          MapStorage::SpecMapSaveOpts::NESET_SECT)
   1.360 +      {
   1.361 +        switch (gui_data.arrow_coords_save_map_num)
   1.362 +        {
   1.363 +          case SpecMapSaveOpts::ONE_MAP:
   1.364 +            arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x";
   1.365 +            arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y";
   1.366 +            arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name;
   1.367 +            break;
   1.368 +          case SpecMapSaveOpts::TWO_MAPS:
   1.369 +            arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name;
   1.370 +            arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name;
   1.371 +            arrow_coords_two_maps_1_name =
   1.372 +              gui_data.arrow_coords_two_maps_1_name;
   1.373 +            arrow_coords_two_maps_2_name =
   1.374 +              gui_data.arrow_coords_two_maps_2_name;
   1.375 +            break;
   1.376 +        }
   1.377 +        arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
   1.378 +        arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num;
   1.379 +      }
   1.380 +      readLGF(filename, true,
   1.381 +          gui_data.main_node_map_names, gui_data.main_arc_map_names,
   1.382 +          gui_data.node_map_types, gui_data.arc_map_types,
   1.383 +          node_coord_xmap_name, node_coord_ymap_name,
   1.384 +          arrow_coord_xmap_name, arrow_coord_ymap_name);
   1.385 +    }
   1.386 +    catch (Exception& error)
   1.387 +    {
   1.388 +      clear();
   1.389 +      return 1;
   1.390 +    }
   1.391 +
   1.392 +    // add the maps from the gui section
   1.393 +    for (vector<string>::const_iterator
   1.394 +        it = gui_data.gui_node_map_names.begin();
   1.395 +        it != gui_data.gui_node_map_names.end(); ++it)
   1.396 +    {
   1.397 +      string map_name = *it;
   1.398 +      switch (gui_data.node_map_types[map_name])
   1.399 +      {
   1.400 +        case MapValue::NUMERIC:
   1.401 +          {
   1.402 +            createNodeMap(map_name, MapValue::NUMERIC, double());
   1.403 +            NumericNodeMap& dmap = getNumericNodeMap(map_name);
   1.404 +            map<int, double>& smap = *gui_data.numeric_node_maps[map_name];
   1.405 +            for (NodeIt n(digraph); n != INVALID; ++n)
   1.406 +            {
   1.407 +              dmap[n] = smap[node_label[n]];
   1.408 +            }
   1.409 +            break;
   1.410 +          }
   1.411 +        case MapValue::STRING:
   1.412 +          {
   1.413 +            createNodeMap(map_name, MapValue::STRING, string());
   1.414 +            StringNodeMap& dmap = getStringNodeMap(map_name);
   1.415 +            map<int, string>& smap = *gui_data.string_node_maps[map_name];
   1.416 +            for (NodeIt n(digraph); n != INVALID; ++n)
   1.417 +            {
   1.418 +              dmap[n] = smap[node_label[n]];
   1.419 +            }
   1.420 +            break;
   1.421 +          }
   1.422 +      }
   1.423 +      getNodeMapData(map_name)->save_dest = GUI_SECT;
   1.424 +    }
   1.425 +    for (vector<string>::const_iterator
   1.426 +        it = gui_data.gui_arc_map_names.begin();
   1.427 +        it != gui_data.gui_arc_map_names.end(); ++it)
   1.428 +    {
   1.429 +      string map_name = *it;
   1.430 +      switch (gui_data.arc_map_types[map_name])
   1.431 +      {
   1.432 +        case MapValue::NUMERIC:
   1.433 +          {
   1.434 +            createArcMap(map_name, MapValue::NUMERIC, double());
   1.435 +            NumericArcMap& dmap = getNumericArcMap(map_name);
   1.436 +            map<int, double>& smap = *gui_data.numeric_arc_maps[map_name];
   1.437 +            for (ArcIt e(digraph); e != INVALID; ++e)
   1.438 +            {
   1.439 +              dmap[e] = smap[arc_label[e]];
   1.440 +            }
   1.441 +            break;
   1.442 +          }
   1.443 +        case MapValue::STRING:
   1.444 +          {
   1.445 +            createArcMap(map_name, MapValue::STRING, string());
   1.446 +            StringArcMap& dmap = getStringArcMap(map_name);
   1.447 +            map<int, string>& smap = *gui_data.string_arc_maps[map_name];
   1.448 +            for (ArcIt e(digraph); e != INVALID; ++e)
   1.449 +            {
   1.450 +              dmap[e] = smap[arc_label[e]];
   1.451 +            }
   1.452 +            break;
   1.453 +          }
   1.454 +      }
   1.455 +      getArcMapData(map_name)->save_dest = GUI_SECT;
   1.456 +    }
   1.457 +
   1.458 +    // restore the node coordinate maps
   1.459 +    if (gui_data.node_coords_save_dest ==
   1.460 +        MapStorage::SpecMapSaveOpts::GUI_SECT)
   1.461 +    {
   1.462 +      for (NodeIt n(digraph); n != INVALID; ++n)
   1.463 +      {
   1.464 +        node_coords.set(n, gui_data.node_coord_map[node_label[n]]);
   1.465 +      }
   1.466 +      node_coords_save_dest = gui_data.node_coords_save_dest;
   1.467 +    }
   1.468 +    // restore the arrow coordinate maps
   1.469 +    if (gui_data.arrow_coords_save_dest ==
   1.470 +        MapStorage::SpecMapSaveOpts::GUI_SECT)
   1.471 +    {
   1.472 +      for (ArcIt e(digraph); e != INVALID; ++e)
   1.473 +      {
   1.474 +        arrow_coords.set(e, gui_data.arrow_coord_map[arc_label[e]]);
   1.475 +      }
   1.476 +      arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
   1.477 +    }
   1.478 +  }
   1.479 +  else
   1.480 +  {
   1.481 +    // there is no gui section neither in the .lgf file nor in the .conf file
   1.482 +    {
   1.483 +      if (content.nodeSectionNum() < 1)
   1.484 +      {
   1.485 +        Gtk::MessageDialog mdialog("No nodeset found in file.");
   1.486 +        mdialog.run();
   1.487 +        clear();
   1.488 +        return 1;
   1.489 +      }
   1.490 +
   1.491 +      if (content.arcSectionNum() < 1)
   1.492 +      {
   1.493 +        Gtk::MessageDialog mdialog("No arcset found in file.");
   1.494 +        mdialog.run();
   1.495 +        clear();
   1.496 +        return 1;
   1.497 +      }
   1.498 +
   1.499 +      std::vector<std::string> nodeMapNames = content.nodeMapNames(0);
   1.500 +      std::vector<std::string> arcMapNames = content.arcMapNames(0);
   1.501 +      
   1.502 +      bool read_arc_label = true;
   1.503 +      if (std::find(arcMapNames.begin(), arcMapNames.end(), "label") ==
   1.504 +          arcMapNames.end())
   1.505 +      {
   1.506 +        read_arc_label = false;
   1.507 +      }
   1.508 +
   1.509 +      nodeMapNames.erase(
   1.510 +          std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"),
   1.511 +          nodeMapNames.end());
   1.512 +
   1.513 +      arcMapNames.erase(
   1.514 +          std::remove(arcMapNames.begin(), arcMapNames.end(), "label"),
   1.515 +          arcMapNames.end());
   1.516 +
   1.517 +      FileImportDialog::ImportData data(nodeMapNames, arcMapNames);
   1.518 +      FileImportDialog fidialog(&data);
   1.519 +      int response = fidialog.run();
   1.520 +      if (response == Gtk::RESPONSE_OK)
   1.521 +      {
   1.522 +        try
   1.523 +        {
   1.524 +          std::string node_coord_xmap_name, node_coord_ymap_name;
   1.525 +          std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
   1.526 +          bool gen_node_coords = false;
   1.527 +          bool gen_arrow_coords = false;
   1.528 +
   1.529 +          switch (data.node_coord_load_from)
   1.530 +          {
   1.531 +            case FileImportDialog::ImportData::ONE_MAP:
   1.532 +              node_coord_xmap_name = data.node_coord_one_map_name + ":x";
   1.533 +              node_coord_ymap_name = data.node_coord_one_map_name + ":y";
   1.534 +              node_coords_one_map_name = data.node_coord_one_map_name;
   1.535 +
   1.536 +              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
   1.537 +              node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
   1.538 +              break;
   1.539 +            case FileImportDialog::ImportData::TWO_MAPS:
   1.540 +              node_coord_xmap_name = data.node_coord_two_maps_1_name;
   1.541 +              node_coord_ymap_name = data.node_coord_two_maps_2_name;
   1.542 +              node_coords_two_maps_1_name = data.node_coord_two_maps_1_name;
   1.543 +              node_coords_two_maps_2_name = data.node_coord_two_maps_2_name;
   1.544 +
   1.545 +              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
   1.546 +              node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
   1.547 +              break;
   1.548 +            case FileImportDialog::ImportData::DONT_READ:
   1.549 +              node_coord_xmap_name = "";
   1.550 +              node_coord_ymap_name = "";
   1.551 +
   1.552 +              node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
   1.553 +              gen_node_coords = true;
   1.554 +              break;
   1.555 +          }
   1.556 +
   1.557 +          switch (data.arrow_coord_load_from)
   1.558 +          {
   1.559 +            case FileImportDialog::ImportData::ONE_MAP:
   1.560 +              arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x";
   1.561 +              arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y";
   1.562 +              arrow_coords_one_map_name = data.arrow_coord_one_map_name;
   1.563 +
   1.564 +              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
   1.565 +              arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
   1.566 +              break;
   1.567 +            case FileImportDialog::ImportData::TWO_MAPS:
   1.568 +              arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name;
   1.569 +              arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name;
   1.570 +              arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name;
   1.571 +              arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name;
   1.572 +
   1.573 +              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
   1.574 +              arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
   1.575 +              break;
   1.576 +            case FileImportDialog::ImportData::DONT_READ:
   1.577 +              arrow_coord_xmap_name = "";
   1.578 +              arrow_coord_ymap_name = "";
   1.579 +
   1.580 +              arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
   1.581 +              gen_arrow_coords = true;
   1.582 +              break;
   1.583 +          }
   1.584 +
   1.585 +          // read arc and node maps
   1.586 +          std::vector<std::string> node_map_names;
   1.587 +          std::vector<std::string> arc_map_names;
   1.588 +          std::map<std::string, MapValue::Type> node_map_types;
   1.589 +          std::map<std::string, MapValue::Type> arc_map_types;
   1.590 +          for (std::vector<std::string>::const_iterator it =
   1.591 +              data.numeric_node_map_names.begin();
   1.592 +              it != data.numeric_node_map_names.end(); ++it)
   1.593 +          {
   1.594 +            node_map_names.push_back(*it);
   1.595 +            node_map_types[*it] = MapValue::NUMERIC;
   1.596 +          }
   1.597 +          for (std::vector<std::string>::const_iterator it =
   1.598 +              data.string_node_map_names.begin();
   1.599 +              it != data.string_node_map_names.end(); ++it)
   1.600 +          {
   1.601 +            node_map_names.push_back(*it);
   1.602 +            node_map_types[*it] = MapValue::STRING;
   1.603 +          }
   1.604 +          for (std::vector<std::string>::const_iterator it =
   1.605 +              data.numeric_arc_map_names.begin();
   1.606 +              it != data.numeric_arc_map_names.end(); ++it)
   1.607 +          {
   1.608 +            arc_map_names.push_back(*it);
   1.609 +            arc_map_types[*it] = MapValue::NUMERIC;
   1.610 +          }
   1.611 +          for (std::vector<std::string>::const_iterator it =
   1.612 +              data.string_arc_map_names.begin();
   1.613 +              it != data.string_arc_map_names.end(); ++it)
   1.614 +          {
   1.615 +            arc_map_names.push_back(*it);
   1.616 +            arc_map_types[*it] = MapValue::STRING;
   1.617 +          }
   1.618 +
   1.619 +          readLGF(filename, read_arc_label,
   1.620 +              node_map_names, arc_map_names,
   1.621 +              node_map_types, arc_map_types,
   1.622 +              node_coord_xmap_name, node_coord_ymap_name,
   1.623 +              arrow_coord_xmap_name, arrow_coord_ymap_name);
   1.624 +
   1.625 +          // generate arc labels
   1.626 +          if (!read_arc_label)
   1.627 +          {
   1.628 +            int l = 0;
   1.629 +            for (ArcIt e(digraph); e != INVALID; ++e)
   1.630 +            {
   1.631 +              arc_label[e] = l++;
   1.632 +            }
   1.633 +          }
   1.634 +
   1.635 +          if (gen_node_coords)
   1.636 +          {
   1.637 +            // generate node coordinates
   1.638 +            int node_num = 0;
   1.639 +            for (NodeIt n(digraph); n != INVALID; ++n) { node_num++; }
   1.640 +            const double pi = 3.142;
   1.641 +            double step = 2 * pi / (double) node_num;
   1.642 +            int i = 0;
   1.643 +            for (NodeIt n(digraph); n != INVALID; ++n)
   1.644 +            {
   1.645 +              setNodeCoords(n,
   1.646 +                  XY(250.0 * std::cos(i * step),
   1.647 +                    250.0 * std::sin(i * step)));
   1.648 +              i++;
   1.649 +            }
   1.650 +          }
   1.651 +          if (gen_arrow_coords)
   1.652 +          {
   1.653 +            // generate arrow coordinates
   1.654 +            for (ArcIt e(digraph); e != INVALID; ++e)
   1.655 +            {
   1.656 +              if (digraph.source(e) == digraph.target(e))
   1.657 +              {
   1.658 +                setArrowCoords(e,
   1.659 +                    getNodeCoords(digraph.source(e)) + XY(0.0, 80.0));
   1.660 +              }
   1.661 +              else
   1.662 +              {
   1.663 +                setArrowCoords(e,
   1.664 +                    (getNodeCoords(digraph.source(e)) +
   1.665 +                     getNodeCoords(digraph.target(e))) / 2.0);
   1.666 +              }
   1.667 +            }
   1.668 +          }
   1.669 +        }
   1.670 +        catch (Exception& error)
   1.671 +        {
   1.672 +          clear();
   1.673 +          return 1;
   1.674 +        }
   1.675 +      }
   1.676 +      else
   1.677 +      {
   1.678 +        clear();
   1.679 +        return 1;
   1.680 +      }
   1.681 +    }
   1.682 +  }
   1.683 +
   1.684 +  // set max_node_label
   1.685 +  {
   1.686 +    max_node_label = std::numeric_limits<int>::min();
   1.687 +    for (NodeIt n(digraph); n != INVALID; ++n)
   1.688 +    {
   1.689 +      if (node_label[n] > max_node_label)
   1.690 +      {
   1.691 +        max_node_label = node_label[n];
   1.692 +      }
   1.693 +    }
   1.694 +  }
   1.695 +  // set max_arc_label
   1.696 +  {
   1.697 +    max_arc_label = std::numeric_limits<int>::min();
   1.698 +    for (ArcIt e(digraph); e != INVALID; ++e)
   1.699 +    {
   1.700 +      if (arc_label[e] > max_arc_label)
   1.701 +      {
   1.702 +        max_arc_label = arc_label[e];
   1.703 +      }
   1.704 +    }
   1.705 +  }
   1.706 +
   1.707 +  return 0;
   1.708 +}
   1.709 +
   1.710 +void MapStorage::writeToFile(const std::string &filename)
   1.711 +{
   1.712 +  // relabel nodes and arcs
   1.713 +  int i = 0;
   1.714 +  for (NodeIt n(digraph); n != INVALID; ++n)
   1.715 +  {
   1.716 +    node_label[n] = i++;
   1.717 +  }
   1.718 +  max_node_label = i-1;
   1.719 +  i = 0;
   1.720 +  for (ArcIt e(digraph); e != INVALID; ++e)
   1.721 +  {
   1.722 +    arc_label[e] = i++;
   1.723 +  }
   1.724 +  max_arc_label = i-1;
   1.725 +
   1.726 +  // write .lgf file
   1.727 +  {
   1.728 +    DigraphWriter<Digraph> gwriter(filename, digraph);
   1.729 +
   1.730 +    gwriter.nodeMap("label", node_label);
   1.731 +    gwriter.arcMap("label", arc_label);
   1.732 +
   1.733 +    // write node maps
   1.734 +    for (NodeMapStore::const_iterator it = nodemaps.begin();
   1.735 +        it != nodemaps.end(); ++it)
   1.736 +    {
   1.737 +      if (it->second->save_dest == NESET_SECT)
   1.738 +      {
   1.739 +        switch (it->second->type())
   1.740 +        {
   1.741 +          case MapValue::NUMERIC:
   1.742 +            gwriter.nodeMap(it->first, getNumericNodeMap(it->first));
   1.743 +            break;
   1.744 +          case MapValue::STRING:
   1.745 +            gwriter.nodeMap(it->first, getStringNodeMap(it->first));
   1.746 +            break;
   1.747 +        }
   1.748 +      }
   1.749 +    }
   1.750 +
   1.751 +    // write arc maps
   1.752 +    for (ArcMapStore::const_iterator it = arcmaps.begin();
   1.753 +        it != arcmaps.end(); ++it)
   1.754 +    {
   1.755 +      if (it->second->save_dest == NESET_SECT)
   1.756 +      {
   1.757 +        switch (it->second->type())
   1.758 +        {
   1.759 +          case MapValue::NUMERIC:
   1.760 +            gwriter.arcMap(it->first, getNumericArcMap(it->first));
   1.761 +            break;
   1.762 +          case MapValue::STRING:
   1.763 +            gwriter.arcMap(it->first, getStringArcMap(it->first));
   1.764 +            break;
   1.765 +        }
   1.766 +      }
   1.767 +    }
   1.768 +
   1.769 +    // write node coordinates
   1.770 +    switch (getNodeCoordsSaveDest())
   1.771 +    {
   1.772 +      case MapStorage::SpecMapSaveOpts::GUI_SECT:
   1.773 +        break;
   1.774 +      case MapStorage::SpecMapSaveOpts::NESET_SECT:
   1.775 +        switch (getNodeCoordsSaveMapNum())
   1.776 +        {
   1.777 +          case MapStorage::SpecMapSaveOpts::ONE_MAP:
   1.778 +            gwriter.nodeMap(node_coords_one_map_name + ":x",
   1.779 +                node_coords_x);
   1.780 +            gwriter.nodeMap(node_coords_one_map_name + ":y",
   1.781 +                node_coords_y);
   1.782 +            break;
   1.783 +          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
   1.784 +            gwriter.nodeMap(node_coords_two_maps_1_name,
   1.785 +                node_coords_x);
   1.786 +            gwriter.nodeMap(node_coords_two_maps_2_name,
   1.787 +                node_coords_y);
   1.788 +            break;
   1.789 +        }
   1.790 +        break;
   1.791 +    }
   1.792 +
   1.793 +    // write arrow coordinates
   1.794 +    switch (getArrowCoordsSaveDest())
   1.795 +    {
   1.796 +      case MapStorage::SpecMapSaveOpts::GUI_SECT:
   1.797 +        break;
   1.798 +      case MapStorage::SpecMapSaveOpts::NESET_SECT:
   1.799 +        switch (getArrowCoordsSaveMapNum())
   1.800 +        {
   1.801 +          case MapStorage::SpecMapSaveOpts::ONE_MAP:
   1.802 +            gwriter.arcMap(arrow_coords_one_map_name + ":x",
   1.803 +                arrow_coords_x);
   1.804 +            gwriter.arcMap(arrow_coords_one_map_name + ":y",
   1.805 +                arrow_coords_y);
   1.806 +            break;
   1.807 +          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
   1.808 +            gwriter.arcMap(arrow_coords_two_maps_1_name,
   1.809 +                arrow_coords_x);
   1.810 +            gwriter.arcMap(arrow_coords_two_maps_2_name,
   1.811 +                arrow_coords_y);
   1.812 +            break;
   1.813 +        }
   1.814 +        break;
   1.815 +    }
   1.816 +
   1.817 +    if (gui_sect_save_dest == LGF_FILE)
   1.818 +    {
   1.819 +      GuiWriter gui_writer(this);
   1.820 +      gui_writer.write(gwriter.ostream());
   1.821 +      gwriter.run();
   1.822 +    }
   1.823 +    else
   1.824 +    {
   1.825 +      gwriter.run();
   1.826 +    }
   1.827 +  }
   1.828 +
   1.829 +  // write .conf file
   1.830 +  if (gui_sect_save_dest == CONF_FILE)
   1.831 +  {
   1.832 +    DigraphWriter<Digraph> lwriter(filename + ".conf", digraph);
   1.833 +    GuiWriter gui_writer(this);
   1.834 +    gui_writer.write(lwriter.ostream());
   1.835 +    lwriter.run();
   1.836 +  }
   1.837 +}
   1.838 +
   1.839 +void MapStorage::clear()
   1.840 +{
   1.841 +  for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
   1.842 +  {
   1.843 +    delete it->second;
   1.844 +    nodemaps.erase(it);
   1.845 +  }
   1.846 +  for (ArcMapStore::iterator it = arcmaps.begin(); it != arcmaps.end(); ++it)
   1.847 +  {
   1.848 +    delete it->second;
   1.849 +    arcmaps.erase(it);
   1.850 +  }
   1.851 +  digraph.clear();
   1.852 +  file_name = "";
   1.853 +  modified = false;
   1.854 +  max_node_label = 0;
   1.855 +  max_arc_label = 0;
   1.856 +  background_set = false;
   1.857 +
   1.858 +  gui_sect_save_dest = LGF_FILE;
   1.859 +  node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
   1.860 +  arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
   1.861 +  node_coords_one_map_name = "coord";
   1.862 +  node_coords_two_maps_1_name = "coord_x";
   1.863 +  node_coords_two_maps_2_name = "coord_y";
   1.864 +  arrow_coords_one_map_name = "arrow";
   1.865 +  arrow_coords_two_maps_1_name = "arrow_x";
   1.866 +  arrow_coords_two_maps_2_name = "arrow_y";
   1.867 +
   1.868 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.869 +    {
   1.870 +      changeActiveMap(false, i, "");
   1.871 +      signal_map_win.emit(false, i, "");
   1.872 +    }
   1.873 +  
   1.874 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.875 +    {
   1.876 +      changeActiveMap(true, i, "");
   1.877 +      signal_map_win.emit(true, i, "");
   1.878 +    }
   1.879 +
   1.880 +  attraction=a_d;
   1.881 +  propulsation=p_d;
   1.882 +  iterations=i_d;
   1.883 +
   1.884 +  signal_design_win.emit(attraction, propulsation, iterations);
   1.885 +}
   1.886 +
   1.887 +void MapStorage::mapChanged(bool itisarc, std::string mapname)
   1.888 +{
   1.889 +  if(itisarc)
   1.890 +  {
   1.891 +    for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.892 +    {
   1.893 +      if(active_arcmaps[i]==mapname)
   1.894 +      {
   1.895 +        signal_prop.emit(itisarc, i);
   1.896 +      }
   1.897 +    }
   1.898 +  }
   1.899 +  else
   1.900 +  {
   1.901 +    for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.902 +    {
   1.903 +      if(active_nodemaps[i]==mapname)
   1.904 +      {
   1.905 +        signal_prop.emit(itisarc, i);
   1.906 +      }
   1.907 +    }
   1.908 +  }
   1.909 +}
   1.910 +
   1.911 +void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
   1.912 +{
   1.913 +  attraction_p=attraction;
   1.914 +  propulsation_p=propulsation;
   1.915 +  iterations_p=iterations;
   1.916 +}
   1.917 +
   1.918 +void MapStorage::set_attraction(double attraction_p)
   1.919 +{
   1.920 +  attraction=attraction_p;
   1.921 +}
   1.922 +
   1.923 +void MapStorage::set_propulsation(double propulsation_p)
   1.924 +{
   1.925 +  propulsation=propulsation_p;
   1.926 +}
   1.927 +
   1.928 +void MapStorage::set_iteration(int iterations_p)
   1.929 +{
   1.930 +  iterations=iterations_p;
   1.931 +}
   1.932 +
   1.933 +void MapStorage::redesign_data_changed()
   1.934 +{
   1.935 +  signal_design_win.emit(attraction, propulsation, iterations);
   1.936 +}
   1.937 +
   1.938 +XY MapStorage::getNodeCoords(Node n) const
   1.939 +{
   1.940 +  return node_coords[n];
   1.941 +}
   1.942 +
   1.943 +void MapStorage::setNodeCoords(Node n, XY c)
   1.944 +{
   1.945 +  node_coords.set(n, c);
   1.946 +}
   1.947 +
   1.948 +XY MapStorage::getArrowCoords(Arc e) const
   1.949 +{
   1.950 +  return arrow_coords[e];
   1.951 +}
   1.952 +
   1.953 +void MapStorage::setArrowCoords(Arc e, XY c)
   1.954 +{
   1.955 +  arrow_coords.set(e, c);
   1.956 +}
   1.957 +
   1.958 +MapValue MapStorage::get(const std::string& name, Node node) const
   1.959 +{
   1.960 +  NodeMapData* data = getNodeMapData(name);
   1.961 +  return data->get(node);
   1.962 +}
   1.963 +
   1.964 +void MapStorage::set(const std::string& name, Node node, MapValue val)
   1.965 +{
   1.966 +  NodeMapData* data = getNodeMapData(name);
   1.967 +  data->set(node, val);
   1.968 +}
   1.969 +
   1.970 +MapValue MapStorage::get(const std::string& name, Arc arc) const
   1.971 +{
   1.972 +  ArcMapData* data = getArcMapData(name);
   1.973 +  return data->get(arc);
   1.974 +}
   1.975 +
   1.976 +void MapStorage::set(const std::string& name, Arc arc, MapValue val)
   1.977 +{
   1.978 +  ArcMapData* data = getArcMapData(name);
   1.979 +  data->set(arc, val);
   1.980 +}
   1.981 +
   1.982 +const std::string& MapStorage::getFileName() const
   1.983 +{
   1.984 +  return file_name;
   1.985 +}
   1.986 +
   1.987 +void MapStorage::setFileName(const std::string& fn)
   1.988 +{
   1.989 +  file_name = fn;
   1.990 +}
   1.991 +
   1.992 +bool MapStorage::getModified() const
   1.993 +{
   1.994 +  return modified;
   1.995 +}
   1.996 +
   1.997 +void MapStorage::setModified(bool m)
   1.998 +{
   1.999 +  modified = m;
  1.1000 +}
  1.1001 +
  1.1002 +Node MapStorage::addNode(XY coords)
  1.1003 +{
  1.1004 +  Node node = digraph.addNode();
  1.1005 +
  1.1006 +  setNodeCoords(node, coords);
  1.1007 +
  1.1008 +  max_node_label++;
  1.1009 +
  1.1010 +  node_label[node] = max_node_label;
  1.1011 +
  1.1012 +  std::vector<std::string> node_maps = getNodeMapList();
  1.1013 +  for (std::vector<std::string>::const_iterator it = node_maps.begin();
  1.1014 +      it != node_maps.end(); ++it)
  1.1015 +  {
  1.1016 +    NodeMapData* data = getNodeMapData(*it);
  1.1017 +    set(*it, node, data->default_value);
  1.1018 +  }
  1.1019 +
  1.1020 +  return node;
  1.1021 +}
  1.1022 +
  1.1023 +Arc MapStorage::addArc(Node from, Node to)
  1.1024 +{
  1.1025 +  Arc arc = digraph.addArc(from, to);
  1.1026 +
  1.1027 +  if (from == to)
  1.1028 +  {
  1.1029 +    setArrowCoords(arc, getNodeCoords(from) + XY(0.0, 80.0));
  1.1030 +  }
  1.1031 +  else
  1.1032 +  {
  1.1033 +    setArrowCoords(arc, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
  1.1034 +  }
  1.1035 +
  1.1036 +  max_arc_label++;
  1.1037 +
  1.1038 +  arc_label[arc] = max_arc_label;
  1.1039 +
  1.1040 +  std::vector<std::string> arc_maps = getArcMapList();
  1.1041 +  for (std::vector<std::string>::const_iterator it = arc_maps.begin();
  1.1042 +      it != arc_maps.end(); ++it)
  1.1043 +  {
  1.1044 +    ArcMapData* data = getArcMapData(*it);
  1.1045 +    set(*it, arc, data->default_value);
  1.1046 +  }
  1.1047 +  return arc;
  1.1048 +}
  1.1049 +
  1.1050 +MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
  1.1051 +{
  1.1052 +  NodeMapData* data = getNodeMapData(name);
  1.1053 +  if (data->type() != MapValue::NUMERIC)
  1.1054 +    throw Error("Numeric node map " + name + " does not exists.");
  1.1055 +  return static_cast<NumericNodeMapData*>(data)->map;
  1.1056 +}
  1.1057 +
  1.1058 +MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
  1.1059 +{
  1.1060 +  NodeMapData* data = getNodeMapData(name);
  1.1061 +  if (data->type() != MapValue::STRING)
  1.1062 +    throw Error("String node map " + name + " does not exists.");
  1.1063 +  return static_cast<StringNodeMapData*>(data)->map;
  1.1064 +}
  1.1065 +
  1.1066 +MapStorage::NumericArcMap& MapStorage::getNumericArcMap(const std::string& name)
  1.1067 +{
  1.1068 +  ArcMapData* data = getArcMapData(name);
  1.1069 +  if (data->type() != MapValue::NUMERIC)
  1.1070 +    throw Error("Numeric arc map " + name + " does not exists.");
  1.1071 +  return static_cast<NumericArcMapData*>(data)->map;
  1.1072 +}
  1.1073 +
  1.1074 +MapStorage::StringArcMap& MapStorage::getStringArcMap(const std::string& name)
  1.1075 +{
  1.1076 +  ArcMapData* data = getArcMapData(name);
  1.1077 +  if (data->type() != MapValue::STRING)
  1.1078 +    throw Error("String arc map " + name + " does not exists.");
  1.1079 +  return static_cast<StringArcMapData*>(data)->map;
  1.1080 +}
  1.1081 +
  1.1082 +MapValueArcMap MapStorage::getArcMap(const std::string& name)
  1.1083 +{
  1.1084 +  return MapValueArcMap(name, this);
  1.1085 +}
  1.1086 +
  1.1087 +MapValueNodeMap MapStorage::getNodeMap(const std::string& name)
  1.1088 +{
  1.1089 +  return MapValueNodeMap(name, this);
  1.1090 +}
  1.1091 +
  1.1092 +int MapStorage::getLabel(Node n) const
  1.1093 +{
  1.1094 +  return node_label[n];
  1.1095 +}
  1.1096 +
  1.1097 +int MapStorage::getLabel(Arc e) const
  1.1098 +{
  1.1099 +  return arc_label[e];
  1.1100 +}
  1.1101 +
  1.1102 +MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation()
  1.1103 +{
  1.1104 +  return gui_sect_save_dest;
  1.1105 +}
  1.1106 +
  1.1107 +void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest)
  1.1108 +{
  1.1109 +  gui_sect_save_dest = dest;
  1.1110 +}
  1.1111 +
  1.1112 +MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const
  1.1113 +{
  1.1114 +  NodeMapData *data = getNodeMapData(name);
  1.1115 +  return data->save_dest;
  1.1116 +}
  1.1117 +
  1.1118 +MapStorage::MapSaveDest MapStorage::getArcMapSaveDest(std::string name) const
  1.1119 +{
  1.1120 +  ArcMapData *data = getArcMapData(name);
  1.1121 +  return data->save_dest;
  1.1122 +}
  1.1123 +
  1.1124 +void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
  1.1125 +{
  1.1126 +  NodeMapData *data = getNodeMapData(name);
  1.1127 +  data->save_dest = dest;
  1.1128 +}
  1.1129 +
  1.1130 +void MapStorage::setArcMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
  1.1131 +{
  1.1132 +  ArcMapData *data = getArcMapData(name);
  1.1133 +  data->save_dest = dest;
  1.1134 +}
  1.1135 +
  1.1136 +MapStorage::ArcMapData* MapStorage::getArcMapData(std::string name) const
  1.1137 +{
  1.1138 +  ArcMapStore::const_iterator it = arcmaps.find(name);
  1.1139 +  if (it != arcmaps.end())
  1.1140 +    return it->second;
  1.1141 +  else
  1.1142 +    throw Error("Arc map " + name + " does not exists.");
  1.1143 +}
  1.1144 +
  1.1145 +MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
  1.1146 +{
  1.1147 +  NodeMapStore::const_iterator it = nodemaps.find(name);
  1.1148 +  if (it != nodemaps.end())
  1.1149 +    return it->second;
  1.1150 +  else
  1.1151 +    throw Error("Node map " + name + " does not exists.");
  1.1152 +}
  1.1153 +
  1.1154 +MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
  1.1155 +{
  1.1156 +  NodeMapData *data = getNodeMapData(name);
  1.1157 +  return data->type();
  1.1158 +}
  1.1159 +
  1.1160 +MapValue::Type MapStorage::getArcMapElementType(std::string name) const
  1.1161 +{
  1.1162 +  ArcMapData *data = getArcMapData(name);
  1.1163 +  return data->type();
  1.1164 +}
  1.1165 +
  1.1166 +const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
  1.1167 +{
  1.1168 +  return node_label;
  1.1169 +}
  1.1170 +
  1.1171 +const MapStorage::ArcLabelMap& MapStorage::getArcLabelMap()
  1.1172 +{
  1.1173 +  return arc_label;
  1.1174 +}
  1.1175 +
  1.1176 +const Digraph& MapStorage::getDigraph()
  1.1177 +{
  1.1178 +  return digraph;
  1.1179 +}
  1.1180 +
  1.1181 +bool MapStorage::nodeMapExists(std::string name)
  1.1182 +{
  1.1183 +  NodeMapStore::const_iterator it = nodemaps.find(name);
  1.1184 +  if (it == nodemaps.end())
  1.1185 +    return false;
  1.1186 +  else
  1.1187 +    return true;
  1.1188 +}
  1.1189 +
  1.1190 +bool MapStorage::arcMapExists(std::string name)
  1.1191 +{
  1.1192 +  ArcMapStore::const_iterator it = arcmaps.find(name);
  1.1193 +  if (it == arcmaps.end())
  1.1194 +    return false;
  1.1195 +  else
  1.1196 +    return true;
  1.1197 +}
  1.1198 +
  1.1199 +std::vector<std::string> MapStorage::getArcMaps(MapType type)
  1.1200 +{
  1.1201 +  std::vector<std::string> maps;
  1.1202 +  for (ArcMapStore::const_iterator it = arcmaps.begin(); it != arcmaps.end(); ++it)
  1.1203 +  {
  1.1204 +    if (it->second->type() & type)
  1.1205 +    {
  1.1206 +      maps.push_back(it->first);
  1.1207 +    }
  1.1208 +  }
  1.1209 +  return maps;
  1.1210 +}
  1.1211 +
  1.1212 +std::vector<std::string> MapStorage::getNodeMaps(MapType type)
  1.1213 +{
  1.1214 +  std::vector<std::string> maps;
  1.1215 +  for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
  1.1216 +  {
  1.1217 +    if (it->second->type() & type)
  1.1218 +    {
  1.1219 +      maps.push_back(it->first);
  1.1220 +    }
  1.1221 +  }
  1.1222 +  return maps;
  1.1223 +}
  1.1224 +
  1.1225 +MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
  1.1226 +{
  1.1227 +  return node_coords;
  1.1228 +}
  1.1229 +
  1.1230 +MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
  1.1231 +{
  1.1232 +  return arrow_coords;
  1.1233 +}
  1.1234 +
  1.1235 +MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest()
  1.1236 +{
  1.1237 +  return node_coords_save_dest;
  1.1238 +}
  1.1239 +
  1.1240 +MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest()
  1.1241 +{
  1.1242 +  return arrow_coords_save_dest;
  1.1243 +}
  1.1244 +
  1.1245 +void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
  1.1246 +{
  1.1247 +  node_coords_save_dest = dest;
  1.1248 +}
  1.1249 +
  1.1250 +void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
  1.1251 +{
  1.1252 +  arrow_coords_save_dest = dest;
  1.1253 +}
  1.1254 +
  1.1255 +MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum()
  1.1256 +{
  1.1257 +  return node_coords_save_map_num;
  1.1258 +}
  1.1259 +
  1.1260 +MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum()
  1.1261 +{
  1.1262 +  return arrow_coords_save_map_num;
  1.1263 +}
  1.1264 +
  1.1265 +void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
  1.1266 +{
  1.1267 +  node_coords_save_map_num = num;
  1.1268 +}
  1.1269 +
  1.1270 +void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
  1.1271 +{
  1.1272 +  arrow_coords_save_map_num = num;
  1.1273 +}
  1.1274 +
  1.1275 +const std::string& MapStorage::getNodeCoordsOneMapName()
  1.1276 +{
  1.1277 +  return node_coords_one_map_name;
  1.1278 +}
  1.1279 +const std::string& MapStorage::getNodeCoordsTwoMaps1Name()
  1.1280 +{
  1.1281 +  return node_coords_two_maps_1_name;
  1.1282 +}
  1.1283 +const std::string& MapStorage::getNodeCoordsTwoMaps2Name()
  1.1284 +{
  1.1285 +  return node_coords_two_maps_2_name;
  1.1286 +}
  1.1287 +
  1.1288 +void MapStorage::setNodeCoordsOneMapName(const std::string& name)
  1.1289 +{
  1.1290 +  node_coords_one_map_name = name;
  1.1291 +}
  1.1292 +void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name)
  1.1293 +{
  1.1294 +  node_coords_two_maps_1_name = name;
  1.1295 +}
  1.1296 +void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name)
  1.1297 +{
  1.1298 +  node_coords_two_maps_2_name = name;
  1.1299 +}
  1.1300 +
  1.1301 +const std::string& MapStorage::getArrowCoordsOneMapName()
  1.1302 +{
  1.1303 +  return arrow_coords_one_map_name;
  1.1304 +}
  1.1305 +const std::string& MapStorage::getArrowCoordsTwoMaps1Name()
  1.1306 +{
  1.1307 +  return arrow_coords_two_maps_1_name;
  1.1308 +}
  1.1309 +const std::string& MapStorage::getArrowCoordsTwoMaps2Name()
  1.1310 +{
  1.1311 +  return arrow_coords_two_maps_2_name;
  1.1312 +}
  1.1313 +
  1.1314 +void MapStorage::setArrowCoordsOneMapName(const std::string& name)
  1.1315 +{
  1.1316 +  arrow_coords_one_map_name = name;
  1.1317 +}
  1.1318 +void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name)
  1.1319 +{
  1.1320 +  arrow_coords_two_maps_1_name = name;
  1.1321 +}
  1.1322 +void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name)
  1.1323 +{
  1.1324 +  arrow_coords_two_maps_2_name = name;
  1.1325 +}
  1.1326 +
  1.1327 +void MapStorage::readLGF(
  1.1328 +    const std::string& filename,
  1.1329 +    bool read_arc_label,
  1.1330 +    const std::vector<std::string>& node_map_names,
  1.1331 +    const std::vector<std::string>& arc_map_names,
  1.1332 +    const std::map<std::string, MapValue::Type>& node_map_types,
  1.1333 +    const std::map<std::string, MapValue::Type>& arc_map_types,
  1.1334 +    const std::string& node_coord_xmap_name,
  1.1335 +    const std::string& node_coord_ymap_name,
  1.1336 +    const std::string& arrow_coord_xmap_name,
  1.1337 +    const std::string& arrow_coord_ymap_name)
  1.1338 +{
  1.1339 +  using std::vector;
  1.1340 +  using std::map;
  1.1341 +  using std::string;
  1.1342 +
  1.1343 +  DigraphReader<Digraph> greader(filename, digraph);
  1.1344 +
  1.1345 +  // read the label maps
  1.1346 +  greader.nodeMap("label", node_label);
  1.1347 +  if (read_arc_label)
  1.1348 +    greader.arcMap("label", arc_label);
  1.1349 +
  1.1350 +  // read the node maps
  1.1351 +  for (vector<string>::const_iterator
  1.1352 +      it = node_map_names.begin();
  1.1353 +      it != node_map_names.end(); ++it)
  1.1354 +  {
  1.1355 +    switch (node_map_types.find(*it)->second)
  1.1356 +    {
  1.1357 +      case MapValue::NUMERIC:
  1.1358 +        {
  1.1359 +          createNodeMap(*it, MapValue::NUMERIC, double());
  1.1360 +          greader.nodeMap(*it, getNumericNodeMap(*it));
  1.1361 +          break;
  1.1362 +        }
  1.1363 +      case MapValue::STRING:
  1.1364 +        {
  1.1365 +          createNodeMap(*it, MapValue::STRING, string());
  1.1366 +          greader.nodeMap(*it, getStringNodeMap(*it));
  1.1367 +          break;
  1.1368 +        }
  1.1369 +    }
  1.1370 +    getNodeMapData(*it)->save_dest = NESET_SECT;
  1.1371 +  }
  1.1372 +
  1.1373 +  // read the arc maps
  1.1374 +  for (vector<string>::const_iterator
  1.1375 +      it = arc_map_names.begin();
  1.1376 +      it != arc_map_names.end(); ++it)
  1.1377 +  {
  1.1378 +    switch (arc_map_types.find(*it)->second)
  1.1379 +    {
  1.1380 +      case MapValue::NUMERIC:
  1.1381 +        {
  1.1382 +          createArcMap(*it, MapValue::NUMERIC, double());
  1.1383 +          greader.arcMap(*it, getNumericArcMap(*it));
  1.1384 +          break;
  1.1385 +        }
  1.1386 +      case MapValue::STRING:
  1.1387 +        {
  1.1388 +          createArcMap(*it, MapValue::STRING, string());
  1.1389 +          greader.arcMap(*it, getStringArcMap(*it));
  1.1390 +          break;
  1.1391 +        }
  1.1392 +    }
  1.1393 +    getArcMapData(*it)->save_dest = NESET_SECT;
  1.1394 +  }
  1.1395 +
  1.1396 +  // read the node coordinate maps
  1.1397 +  if (node_coord_xmap_name != "")
  1.1398 +    greader.nodeMap(node_coord_xmap_name, node_coords_x);
  1.1399 +  if (node_coord_ymap_name != "")
  1.1400 +    greader.nodeMap(node_coord_ymap_name, node_coords_y);
  1.1401 +
  1.1402 +  // read the arrow coordinate maps
  1.1403 +  if (arrow_coord_xmap_name != "")
  1.1404 +    greader.arcMap(arrow_coord_xmap_name, arrow_coords_x);
  1.1405 +  if (arrow_coord_ymap_name != "")
  1.1406 +    greader.arcMap(arrow_coord_ymap_name, arrow_coords_y);
  1.1407 +
  1.1408 +  greader.run();
  1.1409 +}
  1.1410 +
  1.1411 +void MapStorage::setBackground(const std::string& file_name)
  1.1412 +{
  1.1413 +  if (file_name == background_file_name) return;
  1.1414 +  if (file_name == "")
  1.1415 +  {
  1.1416 +    background_file_name = "";
  1.1417 +    background_set = false;
  1.1418 +  }
  1.1419 +  else
  1.1420 +  {
  1.1421 +    background_file_name = file_name;
  1.1422 +    background_set = true;
  1.1423 +  }
  1.1424 +  signal_background.emit();
  1.1425 +}
  1.1426 +
  1.1427 +const std::string& MapStorage::getBackgroundFilename()
  1.1428 +{
  1.1429 +  return background_file_name;
  1.1430 +}
  1.1431 +
  1.1432 +bool MapStorage::isBackgroundSet()
  1.1433 +{
  1.1434 +  return background_set;
  1.1435 +}
  1.1436 +
  1.1437 +double MapStorage::getBackgroundScaling()
  1.1438 +{
  1.1439 +  return background_scaling;
  1.1440 +}
  1.1441 +
  1.1442 +void MapStorage::setBackgroundScaling(double scaling)
  1.1443 +{
  1.1444 +  background_scaling = scaling;
  1.1445 +}
  1.1446 +
  1.1447 +void MapStorage::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
  1.1448 +{
  1.1449 +  Digraph::NodeMap<int> _shapes(digraph, 0);
  1.1450 +  Digraph::NodeMap<int> _nodeColors(digraph, 0);
  1.1451 +  Digraph::ArcMap<int> _arcColors(digraph, 0);
  1.1452 +  Digraph::NodeMap<double> _nodeSizes(digraph, 6.0);
  1.1453 +  Digraph::ArcMap<double> _arcWidths(digraph, 1.0);
  1.1454 +  bool _drawArrows=options[ARROWS];
  1.1455 +  bool _enableParallel=options[PAR];
  1.1456 +
  1.1457 +  std::string emptyString="";
  1.1458 +  Digraph::NodeMap<std::string> _nodeTextMap(digraph,emptyString);
  1.1459 +
  1.1460 +  //_nodeTextMap=(Digraph::NodeMap<void> *)&emptyStringMap;
  1.1461 +
  1.1462 +  if(options[N_MAPS])
  1.1463 +    {
  1.1464 +      if(active_nodemaps[N_RADIUS]!="")
  1.1465 +	{
  1.1466 +	  _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]);
  1.1467 +	}
  1.1468 +      if(active_nodemaps[N_COLOR]!="")
  1.1469 +	{
  1.1470 +	  for(NodeIt ni(digraph);ni!=INVALID;++ni)
  1.1471 +	    {
  1.1472 +	      _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni);
  1.1473 +	    }
  1.1474 +	}
  1.1475 +      if(active_nodemaps[N_TEXT]!="")
  1.1476 +	{
  1.1477 +	  for(NodeIt ni(digraph);ni!=INVALID;++ni)
  1.1478 +	    {
  1.1479 +	      std::ostringstream o;
  1.1480 +	      o << get(active_nodemaps[N_TEXT], ni);
  1.1481 +	      _nodeTextMap[ni]=o.str();	      
  1.1482 +	    }
  1.1483 +	}
  1.1484 +    }
  1.1485 +  if(options[E_MAPS])
  1.1486 +    {
  1.1487 +      if(active_arcmaps[E_WIDTH]!="")
  1.1488 +	{
  1.1489 +	  _arcWidths=getNumericArcMap(active_arcmaps[E_WIDTH]);
  1.1490 +	}
  1.1491 +      if(active_arcmaps[E_COLOR]!="")
  1.1492 +	{
  1.1493 +	  for(ArcIt ei(digraph);ei!=INVALID;++ei)
  1.1494 +	    {
  1.1495 +	      _arcColors[ei]=(int)get(active_arcmaps[E_COLOR], ei);
  1.1496 +	    }
  1.1497 +	}
  1.1498 +    }
  1.1499 +  if(shapemap!="Default values")
  1.1500 +    {
  1.1501 +      double min = std::numeric_limits<double>::max();
  1.1502 +      double max = std::numeric_limits<double>::min();
  1.1503 +      for (NodeIt n(digraph); n != INVALID; ++n)
  1.1504 +      {
  1.1505 +        double v = static_cast<double>(get(shapemap, n));
  1.1506 +        if (v < min) min = v;
  1.1507 +        if (v > max) max = v;
  1.1508 +      }
  1.1509 +      if((min>=0)&&(max<=4))
  1.1510 +	{
  1.1511 +          NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map;
  1.1512 +          for (NodeIt n(digraph); n != INVALID; ++n)
  1.1513 +          {
  1.1514 +            _shapes[n] = static_cast<int>(map[n]);
  1.1515 +          }
  1.1516 +	}
  1.1517 +    }
  1.1518 +
  1.1519 +  Palette palette;
  1.1520 +  Palette paletteW(true);
  1.1521 +
  1.1522 +  graphToEps(digraph,filename).
  1.1523 +    title("Sample .eps figure (fits to A4)").
  1.1524 +    copyright("(C) 2006 LEMON Project").
  1.1525 +    absoluteNodeSizes().absoluteArcWidths().
  1.1526 +    nodeScale(2).nodeSizes(_nodeSizes).
  1.1527 +    coords(node_coords).
  1.1528 +    nodeShapes(_shapes).
  1.1529 +    nodeColors(composeMap(paletteW,_nodeColors)).
  1.1530 +    arcColors(composeMap(palette,_arcColors)).
  1.1531 +    arcWidthScale(0.3).arcWidths(_arcWidths).
  1.1532 +    nodeTexts(_nodeTextMap).nodeTextSize(7).
  1.1533 +    enableParallel(_enableParallel).parArcDist(5).
  1.1534 +    drawArrows(_drawArrows).arrowWidth(7).arrowLength(7).
  1.1535 +    run();
  1.1536 +
  1.1537 +}