COIN-OR::LEMON - Graph Library

Changeset 201:879e47e5b731 in glemon-0.x for mapstorage.cc


Ignore:
Timestamp:
01/02/08 22:03:09 (16 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
Message:

Merge branches/akos to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mapstorage.cc

    r199 r201  
    88 *
    99 * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
     10 * provided that this copyright notice appears in all cop       ies. For
    1111 * precise terms see the accompanying LICENSE file.
    1212 *
     
    1717 */
    1818
     19#include "i18n.h"
    1920#include <limits>
    2021#include <cmath>
     22#include <iostream>
     23#include <fstream>
     24#include <string>
     25#include <algorithm>
    2126#include <gtkmm.h>
    22 
     27#include "file_import_dialog.h"
    2328#include <mapstorage.h>
    2429#include <gui_writer.h>
     
    3035const double p_d=40000;
    3136
    32 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false)
    33 {
    34   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
    35   coords.setXMap(*nodemap_storage["coordinates_x"]);
    36   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    37   coords.setYMap(*nodemap_storage["coordinates_y"]);
    38 
    39   edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
    40   arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
    41   edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
    42   arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    43 
    44   nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
    45   edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
    46 
    47   nodemap_default["label"] = 1.0;
    48   edgemap_default["label"] = 1.0;
     37MapStorage::MapStorage() :
     38  gui_sect_save_dest(LGF_FILE),
     39  node_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
     40  arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
     41  modified(false),
     42  file_name(""),
     43  max_node_label(0),
     44  max_edge_label(0),
     45  node_coords_one_map_name("coord"),
     46  node_coords_two_maps_1_name("coord_x"),
     47  node_coords_two_maps_2_name("coord_y"),
     48  arrow_coords_one_map_name("arrow"),
     49  arrow_coords_two_maps_1_name("arrow_x"),
     50  arrow_coords_two_maps_2_name("arrow_y"),
     51  iterations(i_d),
     52  attraction(a_d),
     53  propulsation(p_d),
     54  node_coords_x(graph),
     55  node_coords_y(graph),
     56  arrow_coords_x(graph),
     57  arrow_coords_y(graph),
     58  node_label(graph),
     59  edge_label(graph),
     60  background_set(false)
     61{
     62  node_coords.setXMap(node_coords_x);
     63  node_coords.setYMap(node_coords_y);
     64  arrow_coords.setXMap(arrow_coords_x);
     65  arrow_coords.setYMap(arrow_coords_y);
    4966
    5067  active_nodemaps.resize(NODE_PROPERTY_NUM);
     
    6380MapStorage::~MapStorage()
    6481{
    65   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    66       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    67   {
    68     delete it->second;
    69   }
    70   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    71       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    72   {
    73     delete it->second;
    74   }
    75 }
    76 
    77 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
    78 {
    79   if( nodemap_storage.find(name) == nodemap_storage.end() )
    80     {
    81       nodemap_storage[name]=nodemap;
    82       // set the maps default value
    83       nodemap_default[name] = default_value;
    84 
    85       //announce changement in maps
    86       signal_node_map.emit(name);
    87       return 0;
    88     }
    89   return 1;
     82  clear();
     83}
     84
     85void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
     86    MapValue def_val)
     87{
     88  NodeMapStore::const_iterator it = nodemaps.find(name);
     89  if (it != nodemaps.end())
     90    throw Error("Node map " + name + " already exists.");
     91
     92  switch (type)
     93  {
     94    case MapValue::NUMERIC:
     95      nodemaps[name] = new NumericNodeMapData(graph, def_val);
     96      break;
     97    case MapValue::STRING:
     98      nodemaps[name] = new StringNodeMapData(graph, def_val);
     99      break;
     100  }
     101
     102  nodemaps[name]->default_value = def_val;
     103
     104  signal_node_map.emit(name, type);
     105}
     106
     107void MapStorage::createEdgeMap(const std::string& name, MapValue::Type type,
     108    MapValue def_val)
     109{
     110  EdgeMapStore::const_iterator it = edgemaps.find(name);
     111  if (it != edgemaps.end())
     112    throw Error("Edge map " + name + " already exists.");
     113
     114  switch (type)
     115  {
     116    case MapValue::NUMERIC:
     117      edgemaps[name] = new NumericEdgeMapData(graph, def_val);
     118      break;
     119    case MapValue::STRING:
     120      edgemaps[name] = new StringEdgeMapData(graph, def_val);
     121      break;
     122  }
     123
     124  edgemaps[name]->default_value = def_val;
     125
     126  signal_edge_map.emit(name, type);
    90127}
    91128
     
    116153}
    117154
    118 
    119155std::string MapStorage::getActiveEdgeMap(int prop)
    120156{
     
    127163}
    128164
    129 std::vector<std::string> MapStorage::getEdgeMapList()
    130 {
    131   std::vector<std::string> eml;
    132   eml.resize(edgemap_storage.size());
    133   int i=0;
    134   std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
    135   for(;emsi!=endOfEdgeMaps();emsi++)
    136     {
    137       eml[i]=(emsi->first);
    138       i++;
    139     }
    140   return eml;
    141 }
    142 
    143 std::vector<std::string> MapStorage::getNodeMapList()
    144 {
    145   std::vector<std::string> nml;
    146   nml.resize(nodemap_storage.size());
    147   int i=0;
    148   std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
    149   for(;nmsi!=endOfNodeMaps();nmsi++)
    150     {
    151       nml[i]=(nmsi->first);
    152       i++;
    153     }
    154   return nml;
     165std::vector<std::string> MapStorage::getEdgeMapList(MapType type)
     166{
     167  if (type == ALL)
     168  {
     169    std::vector<std::string> ret;
     170    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     171        it != edgemaps.end(); ++it)
     172    {
     173      ret.push_back(it->first);
     174    }
     175    return ret;
     176  }
     177  else
     178  {
     179    std::vector<std::string> ret;
     180    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     181        it != edgemaps.end(); ++it)
     182    {
     183      EdgeMapData* data = getEdgeMapData(it->first);
     184      MapValue::Type t = data->type();
     185      if ((t == MapValue::NUMERIC && (type & NUM)) ||
     186          (t == MapValue::STRING && (type & STR)))
     187      {
     188        ret.push_back(it->first);
     189      }
     190    }
     191    return ret;
     192  }
     193}
     194
     195std::vector<std::string> MapStorage::getNodeMapList(MapType type)
     196{
     197  if (type == ALL)
     198  {
     199    std::vector<std::string> ret;
     200    for (NodeMapStore::const_iterator it = nodemaps.begin();
     201        it != nodemaps.end(); ++it)
     202    {
     203      ret.push_back(it->first);
     204    }
     205    return ret;
     206  }
     207  else
     208  {
     209    std::vector<std::string> ret;
     210    for (NodeMapStore::const_iterator it = nodemaps.begin();
     211        it != nodemaps.end(); ++it)
     212    {
     213      NodeMapData* data = getNodeMapData(it->first);
     214      MapValue::Type t = data->type();
     215      if ((t == MapValue::NUMERIC && (type & NUM)) ||
     216          (t == MapValue::STRING && (type & STR)))
     217      {
     218        ret.push_back(it->first);
     219      }
     220    }
     221    return ret;
     222  }
    155223}
    156224
     
    160228}
    161229
    162 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
    163 {
    164   if( edgemap_storage.find(name) == edgemap_storage.end() )
    165     {
    166       edgemap_storage[name]=edgemap;
    167       // set the maps default value
    168       edgemap_default[name] = default_value;
    169 
    170       //announce changement in maps
    171       signal_edge_map.emit(name);
    172       return 0;
    173     }
    174   return 1;
    175 }
    176 
    177 double MapStorage::maxOfNodeMap(const std::string & name)
    178 {
    179   double max=0;
    180   for (NodeIt j(graph); j!=INVALID; ++j)
    181   {
    182     if( (*nodemap_storage[name])[j]>max )
    183     {
    184       max=(*nodemap_storage[name])[j];
    185     }
    186   }
    187   return max;
    188 }
    189 
    190 double MapStorage::maxOfEdgeMap(const std::string & name)
    191 {
    192   double max=0;
    193   for (EdgeIt j(graph); j!=INVALID; ++j)
    194   {
    195     if( (*edgemap_storage[name])[j]>max )
    196     {
    197       max=(*edgemap_storage[name])[j];
    198     }
    199   }
    200   return max;
    201 }
    202 
    203 double MapStorage::minOfNodeMap(const std::string & name)
    204 {
    205   NodeIt j(graph);
    206   double min;
    207   if(j!=INVALID)
    208     {
    209       min=(*nodemap_storage[name])[j];
    210     }
     230int MapStorage::readFromFile(const std::string &filename)
     231{
     232  using std::vector;
     233  using std::map;
     234  using std::string;
     235
     236  // check whether the .conf file exists
     237  bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(),
     238      (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
     239
     240  // check whether the .lgf file contains a gui section
     241  bool gui_data_in_lgf = false;
     242  {
     243    std::ifstream ifs(filename.c_str());
     244    std::string line;
     245    while (getline(ifs, line))
     246    {
     247      int pos = line.find("@gui");
     248      if (pos != std::string::npos)
     249      {
     250        bool only_whitespace_before = true;
     251        for (int i = 0; i < pos; ++i)
     252        {
     253          if (!std::isspace(line[i]))
     254          {
     255            only_whitespace_before = false;
     256            break;
     257          }
     258        }
     259        if (only_whitespace_before) gui_data_in_lgf = true;
     260      }
     261    }
     262  }
     263
     264  bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
     265
     266  // ask for user input if both exist
     267  bool use_gui_data_in_lgf = false;
     268  if (gui_data_in_conf && gui_data_in_lgf)
     269  {
     270    Gtk::MessageDialog mdialog(_("<b>Found both ") + filename +
     271        _(".conf and a gui section in ") + filename + _(".</b>"), true,
     272        Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
     273          mdialog.add_button(_("Use the ._conf file"), 1);
     274          mdialog.add_button(_("Use the _gui section"), 2);
     275    switch (mdialog.run())
     276    {
     277      case 1:
     278        use_gui_data_in_lgf = false;
     279        break;
     280      case 2:
     281        use_gui_data_in_lgf = true;
     282        break;
     283      case Gtk::RESPONSE_NONE:
     284        return 1;
     285    }
     286  }
    211287  else
    212     {
    213       min=0;
    214     }
    215   for (; j!=INVALID; ++j)
    216   {
    217     if( (*nodemap_storage[name])[j]<min )
    218     {
    219       min=(*nodemap_storage[name])[j];
    220     }
    221   }
    222   return min;
    223 }
    224 
    225 double MapStorage::minOfEdgeMap(const std::string & name)
    226 {
    227   EdgeIt j(graph);
    228   double min;
    229   if(j!=INVALID)
    230     {
    231       min=(*edgemap_storage[name])[j];
    232     }
    233   else
    234     {
    235       min=0;
    236     }
    237   for (EdgeIt j(graph); j!=INVALID; ++j)
    238   {
    239     if( (*edgemap_storage[name])[j]<min )
    240     {
    241       min=(*edgemap_storage[name])[j];
    242     }
    243   }
    244   return min;
    245 }
    246 
    247 int MapStorage::readFromFile(const std::string &filename)
    248 {
    249   bool read_x = false;
    250   bool read_y = false;
    251   bool read_edge_id = false;
    252 
    253   try {
    254     LemonReader lreader(filename);
    255     ContentReader content(lreader);
    256     lreader.run();
    257 
    258     if (content.nodeSetNum() < 1)
    259     {
    260       Gtk::MessageDialog mdialog("No nodeset found in file.");
    261       mdialog.run();
     288  {
     289    use_gui_data_in_lgf = gui_data_in_lgf;
     290  }
     291
     292  if (gui_data_found)
     293  {
     294    GUISectData gui_data;
     295    if (use_gui_data_in_lgf)
     296    {
     297      // read the gui section from the .lgf file
     298      try
     299      {
     300        LemonReader lreader(filename);
     301        GuiReader gui_reader(lreader, this, gui_data);
     302        lreader.run();
     303        gui_sect_save_dest = LGF_FILE;
     304      }
     305      catch (Exception& error)
     306      {
     307        clear();
     308        return 1;
     309      }
     310    }
     311    else
     312    {
     313      // read the gui section from the .conf file
     314      try
     315      {
     316        LemonReader lreader(filename + ".conf");
     317        GuiReader gui_reader(lreader, this, gui_data);
     318        lreader.run();
     319        gui_sect_save_dest = CONF_FILE;
     320      }
     321      catch (Exception& error)
     322      {
     323        clear();
     324        return 1;
     325      }
     326    }
     327
     328    // read the graph and maps form the .lgf file
     329    try
     330    {
     331      std::string node_coord_xmap_name, node_coord_ymap_name;
     332      std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
     333
     334      if (gui_data.node_coords_save_dest ==
     335          MapStorage::SpecMapSaveOpts::NESET_SECT)
     336      {
     337        switch (gui_data.node_coords_save_map_num)
     338        {
     339          case SpecMapSaveOpts::ONE_MAP:
     340            node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x";
     341            node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y";
     342            node_coords_one_map_name = gui_data.node_coords_one_map_name;
     343            break;
     344          case SpecMapSaveOpts::TWO_MAPS:
     345            node_coord_xmap_name = gui_data.node_coords_two_maps_1_name;
     346            node_coord_ymap_name = gui_data.node_coords_two_maps_2_name;
     347            node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name;
     348            node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name;
     349            break;
     350        }
     351        node_coords_save_dest = gui_data.node_coords_save_dest;
     352        node_coords_save_map_num = gui_data.node_coords_save_map_num;
     353      }
     354
     355      if (gui_data.arrow_coords_save_dest ==
     356          MapStorage::SpecMapSaveOpts::NESET_SECT)
     357      {
     358        switch (gui_data.arrow_coords_save_map_num)
     359        {
     360          case SpecMapSaveOpts::ONE_MAP:
     361            arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x";
     362            arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y";
     363            arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name;
     364            break;
     365          case SpecMapSaveOpts::TWO_MAPS:
     366            arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name;
     367            arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name;
     368            arrow_coords_two_maps_1_name =
     369              gui_data.arrow_coords_two_maps_1_name;
     370            arrow_coords_two_maps_2_name =
     371              gui_data.arrow_coords_two_maps_2_name;
     372            break;
     373        }
     374        arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
     375        arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num;
     376      }
     377      readLGF(filename, true,
     378          gui_data.main_node_map_names, gui_data.main_edge_map_names,
     379          gui_data.node_map_types, gui_data.edge_map_types,
     380          node_coord_xmap_name, node_coord_ymap_name,
     381          arrow_coord_xmap_name, arrow_coord_ymap_name);
     382    }
     383    catch (Exception& error)
     384    {
    262385      clear();
    263386      return 1;
    264387    }
    265388
    266     if (content.edgeSetNum() < 1)
    267     {
    268       Gtk::MessageDialog mdialog("No edgeset found in file.");
    269       mdialog.run();
    270       clear();
    271       return 1;
    272     }
    273 
    274     const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
    275     const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
    276 
    277     GraphReader<Graph> greader(filename, graph);
    278     for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
    279         it != nodeMapNames.end(); ++it)
    280     {
    281       if (*it == "coordinates_x")
    282       {
    283         read_x = true;
    284         //std::cout << "read X nodemap" << std::endl;
    285       }
    286       else if (*it == "coordinates_y")
    287       {
    288         read_y = true;
    289         //std::cout << "read Y nodemap" << std::endl;
    290       }
    291       else if (*it == "label")
    292       {
    293         //std::cout << "read id nodemap" << std::endl;
     389    // add the maps from the gui section
     390    for (vector<string>::const_iterator
     391        it = gui_data.gui_node_map_names.begin();
     392        it != gui_data.gui_node_map_names.end(); ++it)
     393    {
     394      string map_name = *it;
     395      switch (gui_data.node_map_types[map_name])
     396      {
     397        case MapValue::NUMERIC:
     398          {
     399            createNodeMap(map_name, MapValue::NUMERIC, double());
     400            NumericNodeMap& dmap = getNumericNodeMap(map_name);
     401            map<int, double>& smap = *gui_data.numeric_node_maps[map_name];
     402            for (NodeIt n(graph); n != INVALID; ++n)
     403            {
     404              dmap[n] = smap[node_label[n]];
     405            }
     406            break;
     407          }
     408        case MapValue::STRING:
     409          {
     410            createNodeMap(map_name, MapValue::STRING, string());
     411            StringNodeMap& dmap = getStringNodeMap(map_name);
     412            map<int, string>& smap = *gui_data.string_node_maps[map_name];
     413            for (NodeIt n(graph); n != INVALID; ++n)
     414            {
     415              dmap[n] = smap[node_label[n]];
     416            }
     417            break;
     418          }
     419      }
     420      getNodeMapData(map_name)->save_dest = GUI_SECT;
     421    }
     422    for (vector<string>::const_iterator
     423        it = gui_data.gui_edge_map_names.begin();
     424        it != gui_data.gui_edge_map_names.end(); ++it)
     425    {
     426      string map_name = *it;
     427      switch (gui_data.edge_map_types[map_name])
     428      {
     429        case MapValue::NUMERIC:
     430          {
     431            createEdgeMap(map_name, MapValue::NUMERIC, double());
     432            NumericEdgeMap& dmap = getNumericEdgeMap(map_name);
     433            map<int, double>& smap = *gui_data.numeric_edge_maps[map_name];
     434            for (EdgeIt e(graph); e != INVALID; ++e)
     435            {
     436              dmap[e] = smap[edge_label[e]];
     437            }
     438            break;
     439          }
     440        case MapValue::STRING:
     441          {
     442            createEdgeMap(map_name, MapValue::STRING, string());
     443            StringEdgeMap& dmap = getStringEdgeMap(map_name);
     444            map<int, string>& smap = *gui_data.string_edge_maps[map_name];
     445            for (EdgeIt e(graph); e != INVALID; ++e)
     446            {
     447              dmap[e] = smap[edge_label[e]];
     448            }
     449            break;
     450          }
     451      }
     452      getEdgeMapData(map_name)->save_dest = GUI_SECT;
     453    }
     454
     455    // restore the node coordinate maps
     456    if (gui_data.node_coords_save_dest ==
     457        MapStorage::SpecMapSaveOpts::GUI_SECT)
     458    {
     459      for (NodeIt n(graph); n != INVALID; ++n)
     460      {
     461        node_coords.set(n, gui_data.node_coord_map[node_label[n]]);
     462      }
     463      node_coords_save_dest = gui_data.node_coords_save_dest;
     464    }
     465    // restore the arrow coordinate maps
     466    if (gui_data.arrow_coords_save_dest ==
     467        MapStorage::SpecMapSaveOpts::GUI_SECT)
     468    {
     469      for (EdgeIt e(graph); e != INVALID; ++e)
     470      {
     471        arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]);
     472      }
     473      arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
     474    }
     475  }
     476  else
     477  {
     478    // there is no gui section neither in the .lgf file nor in the .conf file
     479    {
     480      LemonReader lreader(filename);
     481      ContentReader content(lreader);
     482      try
     483      {
     484        lreader.run();
     485      }
     486      catch (Exception& error)
     487      {
     488        Gtk::MessageDialog mdialog(error.what());
     489        mdialog.run();
     490        clear();
     491        return 1;
     492      }
     493
     494      if (content.nodeSetNum() < 1)
     495      {
     496        Gtk::MessageDialog mdialog("No nodeset found in file.");
     497        mdialog.run();
     498        clear();
     499        return 1;
     500      }
     501
     502      if (content.edgeSetNum() < 1)
     503      {
     504        Gtk::MessageDialog mdialog("No edgeset found in file.");
     505        mdialog.run();
     506        clear();
     507        return 1;
     508      }
     509
     510      std::vector<std::string> nodeMapNames = content.nodeSetMaps(0);
     511      std::vector<std::string> edgeMapNames = content.edgeSetMaps(0);
     512     
     513      bool read_edge_label = true;
     514      if (std::find(edgeMapNames.begin(), edgeMapNames.end(), "label") ==
     515          edgeMapNames.end())
     516      {
     517        read_edge_label = false;
     518      }
     519
     520      nodeMapNames.erase(
     521          std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"),
     522          nodeMapNames.end());
     523
     524      edgeMapNames.erase(
     525          std::remove(edgeMapNames.begin(), edgeMapNames.end(), "label"),
     526          edgeMapNames.end());
     527
     528      FileImportDialog::ImportData data(nodeMapNames, edgeMapNames);
     529      FileImportDialog fidialog(&data);
     530      int response = fidialog.run();
     531      if (response == Gtk::RESPONSE_OK)
     532      {
     533        try
     534        {
     535          std::string node_coord_xmap_name, node_coord_ymap_name;
     536          std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
     537          bool gen_node_coords = false;
     538          bool gen_arrow_coords = false;
     539
     540          switch (data.node_coord_load_from)
     541          {
     542            case FileImportDialog::ImportData::ONE_MAP:
     543              node_coord_xmap_name = data.node_coord_one_map_name + ":x";
     544              node_coord_ymap_name = data.node_coord_one_map_name + ":y";
     545              node_coords_one_map_name = data.node_coord_one_map_name;
     546
     547              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     548              node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
     549              break;
     550            case FileImportDialog::ImportData::TWO_MAPS:
     551              node_coord_xmap_name = data.node_coord_two_maps_1_name;
     552              node_coord_ymap_name = data.node_coord_two_maps_2_name;
     553              node_coords_two_maps_1_name = data.node_coord_two_maps_1_name;
     554              node_coords_two_maps_2_name = data.node_coord_two_maps_2_name;
     555
     556              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     557              node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
     558              break;
     559            case FileImportDialog::ImportData::DONT_READ:
     560              node_coord_xmap_name = "";
     561              node_coord_ymap_name = "";
     562
     563              node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     564              gen_node_coords = true;
     565              break;
     566          }
     567
     568          switch (data.arrow_coord_load_from)
     569          {
     570            case FileImportDialog::ImportData::ONE_MAP:
     571              arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x";
     572              arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y";
     573              arrow_coords_one_map_name = data.arrow_coord_one_map_name;
     574
     575              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     576              arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
     577              break;
     578            case FileImportDialog::ImportData::TWO_MAPS:
     579              arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name;
     580              arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name;
     581              arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name;
     582              arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name;
     583
     584              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     585              arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
     586              break;
     587            case FileImportDialog::ImportData::DONT_READ:
     588              arrow_coord_xmap_name = "";
     589              arrow_coord_ymap_name = "";
     590
     591              arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     592              gen_arrow_coords = true;
     593              break;
     594          }
     595
     596          // read edge and node maps
     597          std::vector<std::string> node_map_names;
     598          std::vector<std::string> edge_map_names;
     599          std::map<std::string, MapValue::Type> node_map_types;
     600          std::map<std::string, MapValue::Type> edge_map_types;
     601          for (std::vector<std::string>::const_iterator it =
     602              data.numeric_node_map_names.begin();
     603              it != data.numeric_node_map_names.end(); ++it)
     604          {
     605            node_map_names.push_back(*it);
     606            node_map_types[*it] = MapValue::NUMERIC;
     607          }
     608          for (std::vector<std::string>::const_iterator it =
     609              data.string_node_map_names.begin();
     610              it != data.string_node_map_names.end(); ++it)
     611          {
     612            node_map_names.push_back(*it);
     613            node_map_types[*it] = MapValue::STRING;
     614          }
     615          for (std::vector<std::string>::const_iterator it =
     616              data.numeric_edge_map_names.begin();
     617              it != data.numeric_edge_map_names.end(); ++it)
     618          {
     619            edge_map_names.push_back(*it);
     620            edge_map_types[*it] = MapValue::NUMERIC;
     621          }
     622          for (std::vector<std::string>::const_iterator it =
     623              data.string_edge_map_names.begin();
     624              it != data.string_edge_map_names.end(); ++it)
     625          {
     626            edge_map_names.push_back(*it);
     627            edge_map_types[*it] = MapValue::STRING;
     628          }
     629
     630          readLGF(filename, read_edge_label,
     631              node_map_names, edge_map_names,
     632              node_map_types, edge_map_types,
     633              node_coord_xmap_name, node_coord_ymap_name,
     634              arrow_coord_xmap_name, arrow_coord_ymap_name);
     635
     636          // generate edge labels
     637          if (!read_edge_label)
     638          {
     639            int l = 0;
     640            for (EdgeIt e(graph); e != INVALID; ++e)
     641            {
     642              edge_label[e] = l++;
     643            }
     644          }
     645
     646          if (gen_node_coords)
     647          {
     648            // generate node coordinates
     649            int node_num = 0;
     650            for (NodeIt n(graph); n != INVALID; ++n) { node_num++; }
     651            const double pi = 3.142;
     652            double step = 2 * pi / (double) node_num;
     653            int i = 0;
     654            for (NodeIt n(graph); n != INVALID; ++n)
     655            {
     656              setNodeCoords(n,
     657                  XY(250.0 * std::cos(i * step),
     658                    250.0 * std::sin(i * step)));
     659              i++;
     660            }
     661          }
     662          if (gen_arrow_coords)
     663          {
     664            // generate arrow coordinates
     665            for (EdgeIt e(graph); e != INVALID; ++e)
     666            {
     667              if (graph.source(e) == graph.target(e))
     668              {
     669                setArrowCoords(e,
     670                    getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
     671              }
     672              else
     673              {
     674                setArrowCoords(e,
     675                    (getNodeCoords(graph.source(e)) +
     676                     getNodeCoords(graph.target(e))) / 2.0);
     677              }
     678            }
     679          }
     680        }
     681        catch (Exception& error)
     682        {
     683          clear();
     684          return 1;
     685        }
    294686      }
    295687      else
    296688      {
    297         nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
    298         //std::cout << "read " << *it << " nodemap" << std::endl;
    299       }
    300       greader.readNodeMap(*it, *nodemap_storage[*it]);
    301     }
    302     for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
    303         it != edgeMapNames.end(); ++it)
    304     {
    305       if (*it == "label")
    306       {
    307         //std::cout << "read id edgemap" << std::endl;
    308         read_edge_id = true;
    309       }
    310       else
    311       {
    312         edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
    313         //std::cout << "read " << *it << " edgemap" << std::endl;
    314       }
    315       greader.readEdgeMap(*it, *edgemap_storage[*it]);
    316     }
    317     GuiReader gui_reader(greader, this);
    318     greader.run();
    319   } catch (Exception& error) {
    320     Gtk::MessageDialog mdialog(error.what());
    321     mdialog.run();
    322     clear();
    323     return 1;
    324   }
    325 
    326   if (!read_edge_id)
    327   {
    328     edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
    329     int i = 1;
     689        clear();
     690        return 1;
     691      }
     692    }
     693  }
     694
     695  // set max_node_label
     696  {
     697    max_node_label = std::numeric_limits<int>::min();
     698    for (NodeIt n(graph); n != INVALID; ++n)
     699    {
     700      if (node_label[n] > max_node_label)
     701      {
     702        max_node_label = node_label[n];
     703      }
     704    }
     705  }
     706  // set max_edge_label
     707  {
     708    max_edge_label = std::numeric_limits<int>::min();
    330709    for (EdgeIt e(graph); e != INVALID; ++e)
    331710    {
    332       (*edgemap_storage["label"])[e] = i++;
    333     }
    334   }
    335 
    336   if (!read_x || !read_y)
    337   {
    338     int node_num = 0;
    339     for (NodeIt n(graph); n != INVALID; ++n)
    340     {
    341       node_num++;
    342     }
    343     const double pi = 3.142;
    344     double step = 2 * pi / (double) node_num;
    345     int i = 0;
    346     for (NodeIt n(graph); n != INVALID; ++n)
    347     {
    348       nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
    349       nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
    350       i++;
    351     }
    352   }
    353 
    354   if (!arrow_pos_read_ok)
    355   {
    356     arrow_pos_read_ok = false;
    357     for (EdgeIt e(graph); e != INVALID; ++e)
    358     {
    359       if (graph.source(e) == graph.target(e))
    360       {
    361         arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
    362       }
    363       else
    364       {
    365         arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
    366       }
    367     }
    368   }
    369 
    370   // fill in the default values for the maps
    371   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    372       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    373   {
    374     if ((it->first != "label") &&
    375         (it->first != "coordiantes_x") &&
    376         (it->first != "coordinates_y"))
    377     {
    378       nodemap_default[it->first] = 0.0;
    379     }
    380     else if (it->first == "label")
    381     {
    382       NodeIt n(graph);
    383       double max = (*nodemap_storage["label"])[n];
    384       for (; n != INVALID; ++n)
    385       {
    386         if ((*nodemap_storage["label"])[n] > max)
    387           max = (*nodemap_storage["label"])[n];
    388       }
    389       nodemap_default["label"] = max + 1.0;
    390     }
    391   }
    392   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    393       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    394   {
    395     if (it->first != "label")
    396     {
    397       edgemap_default[it->first] = 0.0;
     711      if (edge_label[e] > max_edge_label)
     712      {
     713        max_edge_label = edge_label[e];
     714      }
     715    }
     716  }
     717
     718  return 0;
     719}
     720
     721void MapStorage::writeToFile(const std::string &filename)
     722{
     723  // relabel nodes and edges
     724  int i = 0;
     725  for (NodeIt n(graph); n != INVALID; ++n)
     726  {
     727    node_label[n] = i++;
     728  }
     729  max_node_label = i-1;
     730  i = 0;
     731  for (EdgeIt e(graph); e != INVALID; ++e)
     732  {
     733    edge_label[e] = i++;
     734  }
     735  max_edge_label = i-1;
     736
     737  // write .lgf file
     738  {
     739    GraphWriter<Graph> gwriter(filename, graph);
     740
     741    gwriter.writeNodeMap("label", node_label);
     742    gwriter.writeEdgeMap("label", edge_label);
     743
     744    // write node maps
     745    for (NodeMapStore::const_iterator it = nodemaps.begin();
     746        it != nodemaps.end(); ++it)
     747    {
     748      if (it->second->save_dest == NESET_SECT)
     749      {
     750        switch (it->second->type())
     751        {
     752          case MapValue::NUMERIC:
     753            gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first));
     754            break;
     755          case MapValue::STRING:
     756            gwriter.writeNodeMap(it->first, getStringNodeMap(it->first));
     757            break;
     758        }
     759      }
     760    }
     761
     762    // write edge maps
     763    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     764        it != edgemaps.end(); ++it)
     765    {
     766      if (it->second->save_dest == NESET_SECT)
     767      {
     768        switch (it->second->type())
     769        {
     770          case MapValue::NUMERIC:
     771            gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first));
     772            break;
     773          case MapValue::STRING:
     774            gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first));
     775            break;
     776        }
     777      }
     778    }
     779
     780    // write node coordinates
     781    switch (getNodeCoordsSaveDest())
     782    {
     783      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     784        break;
     785      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     786        switch (getNodeCoordsSaveMapNum())
     787        {
     788          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     789            gwriter.writeNodeMap(node_coords_one_map_name + ":x",
     790                node_coords_x);
     791            gwriter.writeNodeMap(node_coords_one_map_name + ":y",
     792                node_coords_y);
     793            break;
     794          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     795            gwriter.writeNodeMap(node_coords_two_maps_1_name,
     796                node_coords_x);
     797            gwriter.writeNodeMap(node_coords_two_maps_2_name,
     798                node_coords_y);
     799            break;
     800        }
     801        break;
     802    }
     803
     804    // write arrow coordinates
     805    switch (getArrowCoordsSaveDest())
     806    {
     807      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     808        break;
     809      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     810        switch (getArrowCoordsSaveMapNum())
     811        {
     812          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     813            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x",
     814                arrow_coords_x);
     815            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y",
     816                arrow_coords_y);
     817            break;
     818          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     819            gwriter.writeEdgeMap(arrow_coords_two_maps_1_name,
     820                arrow_coords_x);
     821            gwriter.writeEdgeMap(arrow_coords_two_maps_2_name,
     822                arrow_coords_y);
     823            break;
     824        }
     825        break;
     826    }
     827
     828    if (gui_sect_save_dest == LGF_FILE)
     829    {
     830      GuiWriter gui_writer(gwriter, this);
     831      gwriter.run();
    398832    }
    399833    else
    400834    {
    401       double max = std::numeric_limits<double>::min();
    402       for (EdgeIt e(graph); e != INVALID; ++e)
    403       {
    404         if ((*edgemap_storage["label"])[e] > max)
    405           max = (*edgemap_storage["label"])[e];
    406       }
    407       if (max > std::numeric_limits<double>::min())
    408         edgemap_default["label"] = max + 1.0;
    409       else
    410         edgemap_default["label"] = 1.0;
    411     }
    412   }
    413 
    414   return 0;
    415 }
    416 
    417 void MapStorage::writeToFile(const std::string &filename)
    418 {
    419   GraphWriter<Graph> gwriter(filename, graph);
    420 
    421   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    422       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    423   {
    424     gwriter.writeNodeMap(it->first, *(it->second));
    425   }
    426   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    427       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    428   {
    429     if ((it->first != "arrow_pos_x") &&
    430         (it->first != "arrow_pos_y"))
    431     {
    432       gwriter.writeEdgeMap(it->first, *(it->second));
    433     }
    434   }
    435 
    436   GuiWriter gui_writer(gwriter, this);
    437 
    438   gwriter.run();
     835      gwriter.run();
     836    }
     837  }
     838
     839  // write .conf file
     840  if (gui_sect_save_dest == CONF_FILE)
     841  {
     842    LemonWriter lwriter(filename + ".conf");
     843    GuiWriter gui_writer(lwriter, this);
     844    lwriter.run();
     845  }
    439846}
    440847
    441848void MapStorage::clear()
    442849{
    443   for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
    444       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    445   {
    446     if ((it->first != "coordinates_x") &&
    447         (it->first != "coordinates_y") &&
    448         (it->first != "label"))
    449     {
    450       delete it->second;
    451       nodemap_storage.erase(it);
    452     }
    453   }
    454   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
    455       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    456   {
    457     if ((it->first != "label") &&
    458         (it->first != "arrow_pos_x") &&
    459         (it->first != "arrow_pos_y"))
    460     {
    461       delete it->second;
    462       edgemap_storage.erase(it);
    463     }
    464   }
    465   for (std::map<std::string, double>::iterator it =
    466       nodemap_default.begin(); it != nodemap_default.end(); ++it)
    467   {
    468     if (it->first != "label")
    469       nodemap_default.erase(it);
    470   }
    471   for (std::map<std::string, double>::iterator it =
    472       edgemap_default.begin(); it != edgemap_default.end(); ++it)
    473   {
    474     if (it->first != "label")
    475       edgemap_default.erase(it);
     850  for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
     851  {
     852    delete it->second;
     853    nodemaps.erase(it);
     854  }
     855  for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
     856  {
     857    delete it->second;
     858    edgemaps.erase(it);
    476859  }
    477860  graph.clear();
    478861  file_name = "";
    479862  modified = false;
    480 
    481   arrow_pos_read_ok = false;
    482  
     863  max_node_label = 0;
     864  max_edge_label = 0;
     865  background_set = false;
     866
     867  gui_sect_save_dest = LGF_FILE;
     868  node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     869  arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     870  node_coords_one_map_name = "coord";
     871  node_coords_two_maps_1_name = "coord_x";
     872  node_coords_two_maps_2_name = "coord_y";
     873  arrow_coords_one_map_name = "arrow";
     874  arrow_coords_two_maps_1_name = "arrow_x";
     875  arrow_coords_two_maps_2_name = "arrow_y";
     876
    483877  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    484878    {
     
    500894}
    501895
    502 void MapStorage::ArrowPosReadOK()
    503 {
    504   arrow_pos_read_ok = true;
    505 }
    506 
    507896void MapStorage::mapChanged(bool itisedge, std::string mapname)
    508897{
    509898  if(itisedge)
    510     {
    511       for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    512         {
    513           if(active_edgemaps[i]==mapname)
    514             {
    515               signal_prop.emit(itisedge, i);
    516             }
    517         }
    518     }
     899  {
     900    for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     901    {
     902      if(active_edgemaps[i]==mapname)
     903      {
     904        signal_prop.emit(itisedge, i);
     905      }
     906    }
     907  }
    519908  else
    520     {
    521       for(int i=0;i<NODE_PROPERTY_NUM;i++)
    522         {
    523           if(active_nodemaps[i]==mapname)
    524             {
    525               signal_prop.emit(itisedge, i);
    526             }
    527         }
    528     }
     909  {
     910    for(int i=0;i<NODE_PROPERTY_NUM;i++)
     911    {
     912      if(active_nodemaps[i]==mapname)
     913      {
     914        signal_prop.emit(itisedge, i);
     915      }
     916    }
     917  }
    529918}
    530919
     
    554943{
    555944  signal_design_win.emit(attraction, propulsation, iterations);
     945}
     946
     947XY MapStorage::getNodeCoords(Node n) const
     948{
     949  return node_coords[n];
     950}
     951
     952void MapStorage::setNodeCoords(Node n, XY c)
     953{
     954  node_coords.set(n, c);
     955}
     956
     957XY MapStorage::getArrowCoords(Edge e) const
     958{
     959  return arrow_coords[e];
     960}
     961
     962void MapStorage::setArrowCoords(Edge e, XY c)
     963{
     964  arrow_coords.set(e, c);
     965}
     966
     967MapValue MapStorage::get(const std::string& name, Node node) const
     968{
     969  NodeMapData* data = getNodeMapData(name);
     970  return data->get(node);
     971}
     972
     973void MapStorage::set(const std::string& name, Node node, MapValue val)
     974{
     975  NodeMapData* data = getNodeMapData(name);
     976  data->set(node, val);
     977}
     978
     979MapValue MapStorage::get(const std::string& name, Edge edge) const
     980{
     981  EdgeMapData* data = getEdgeMapData(name);
     982  return data->get(edge);
     983}
     984
     985void MapStorage::set(const std::string& name, Edge edge, MapValue val)
     986{
     987  EdgeMapData* data = getEdgeMapData(name);
     988  data->set(edge, val);
     989}
     990
     991const std::string& MapStorage::getFileName() const
     992{
     993  return file_name;
     994}
     995
     996void MapStorage::setFileName(const std::string& fn)
     997{
     998  file_name = fn;
     999}
     1000
     1001bool MapStorage::getModified() const
     1002{
     1003  return modified;
     1004}
     1005
     1006void MapStorage::setModified(bool m)
     1007{
     1008  modified = m;
     1009}
     1010
     1011Node MapStorage::addNode(XY coords)
     1012{
     1013  Node node = graph.addNode();
     1014
     1015  setNodeCoords(node, coords);
     1016
     1017  max_node_label++;
     1018
     1019  node_label[node] = max_node_label;
     1020
     1021  std::vector<std::string> node_maps = getNodeMapList();
     1022  for (std::vector<std::string>::const_iterator it = node_maps.begin();
     1023      it != node_maps.end(); ++it)
     1024  {
     1025    NodeMapData* data = getNodeMapData(*it);
     1026    set(*it, node, data->default_value);
     1027  }
     1028
     1029  return node;
     1030}
     1031
     1032Edge MapStorage::addEdge(Node from, Node to)
     1033{
     1034  Edge edge = graph.addEdge(from, to);
     1035
     1036  if (from == to)
     1037  {
     1038    setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0));
     1039  }
     1040  else
     1041  {
     1042    setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
     1043  }
     1044
     1045  max_edge_label++;
     1046
     1047  edge_label[edge] = max_edge_label;
     1048
     1049  std::vector<std::string> edge_maps = getEdgeMapList();
     1050  for (std::vector<std::string>::const_iterator it = edge_maps.begin();
     1051      it != edge_maps.end(); ++it)
     1052  {
     1053    EdgeMapData* data = getEdgeMapData(*it);
     1054    set(*it, edge, data->default_value);
     1055  }
     1056  return edge;
     1057}
     1058
     1059MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
     1060{
     1061  NodeMapData* data = getNodeMapData(name);
     1062  if (data->type() != MapValue::NUMERIC)
     1063    throw Error("Numeric node map " + name + " does not exists.");
     1064  return static_cast<NumericNodeMapData*>(data)->map;
     1065}
     1066
     1067MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
     1068{
     1069  NodeMapData* data = getNodeMapData(name);
     1070  if (data->type() != MapValue::STRING)
     1071    throw Error("String node map " + name + " does not exists.");
     1072  return static_cast<StringNodeMapData*>(data)->map;
     1073}
     1074
     1075MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name)
     1076{
     1077  EdgeMapData* data = getEdgeMapData(name);
     1078  if (data->type() != MapValue::NUMERIC)
     1079    throw Error("Numeric edge map " + name + " does not exists.");
     1080  return static_cast<NumericEdgeMapData*>(data)->map;
     1081}
     1082
     1083MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
     1084{
     1085  EdgeMapData* data = getEdgeMapData(name);
     1086  if (data->type() != MapValue::STRING)
     1087    throw Error("String edge map " + name + " does not exists.");
     1088  return static_cast<StringEdgeMapData*>(data)->map;
     1089}
     1090
     1091MapValueEdgeMap MapStorage::getEdgeMap(const std::string& name)
     1092{
     1093  return MapValueEdgeMap(name, this);
     1094}
     1095
     1096MapValueNodeMap MapStorage::getNodeMap(const std::string& name)
     1097{
     1098  return MapValueNodeMap(name, this);
     1099}
     1100
     1101int MapStorage::getLabel(Node n) const
     1102{
     1103  return node_label[n];
     1104}
     1105
     1106int MapStorage::getLabel(Edge e) const
     1107{
     1108  return edge_label[e];
     1109}
     1110
     1111MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation()
     1112{
     1113  return gui_sect_save_dest;
     1114}
     1115
     1116void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest)
     1117{
     1118  gui_sect_save_dest = dest;
     1119}
     1120
     1121MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const
     1122{
     1123  NodeMapData *data = getNodeMapData(name);
     1124  return data->save_dest;
     1125}
     1126
     1127MapStorage::MapSaveDest MapStorage::getEdgeMapSaveDest(std::string name) const
     1128{
     1129  EdgeMapData *data = getEdgeMapData(name);
     1130  return data->save_dest;
     1131}
     1132
     1133void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
     1134{
     1135  NodeMapData *data = getNodeMapData(name);
     1136  data->save_dest = dest;
     1137}
     1138
     1139void MapStorage::setEdgeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
     1140{
     1141  EdgeMapData *data = getEdgeMapData(name);
     1142  data->save_dest = dest;
     1143}
     1144
     1145MapStorage::EdgeMapData* MapStorage::getEdgeMapData(std::string name) const
     1146{
     1147  EdgeMapStore::const_iterator it = edgemaps.find(name);
     1148  if (it != edgemaps.end())
     1149    return it->second;
     1150  else
     1151    throw Error("Edge map " + name + " does not exists.");
     1152}
     1153
     1154MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
     1155{
     1156  NodeMapStore::const_iterator it = nodemaps.find(name);
     1157  if (it != nodemaps.end())
     1158    return it->second;
     1159  else
     1160    throw Error("Node map " + name + " does not exists.");
     1161}
     1162
     1163MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
     1164{
     1165  NodeMapData *data = getNodeMapData(name);
     1166  return data->type();
     1167}
     1168
     1169MapValue::Type MapStorage::getEdgeMapElementType(std::string name) const
     1170{
     1171  EdgeMapData *data = getEdgeMapData(name);
     1172  return data->type();
     1173}
     1174
     1175const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
     1176{
     1177  return node_label;
     1178}
     1179
     1180const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap()
     1181{
     1182  return edge_label;
     1183}
     1184
     1185const Graph& MapStorage::getGraph()
     1186{
     1187  return graph;
     1188}
     1189
     1190bool MapStorage::nodeMapExists(std::string name)
     1191{
     1192  NodeMapStore::const_iterator it = nodemaps.find(name);
     1193  if (it == nodemaps.end())
     1194    return false;
     1195  else
     1196    return true;
     1197}
     1198
     1199bool MapStorage::edgeMapExists(std::string name)
     1200{
     1201  EdgeMapStore::const_iterator it = edgemaps.find(name);
     1202  if (it == edgemaps.end())
     1203    return false;
     1204  else
     1205    return true;
     1206}
     1207
     1208std::vector<std::string> MapStorage::getEdgeMaps(MapType type)
     1209{
     1210  std::vector<std::string> maps;
     1211  for (EdgeMapStore::const_iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
     1212  {
     1213    if (it->second->type() & type)
     1214    {
     1215      maps.push_back(it->first);
     1216    }
     1217  }
     1218  return maps;
     1219}
     1220
     1221std::vector<std::string> MapStorage::getNodeMaps(MapType type)
     1222{
     1223  std::vector<std::string> maps;
     1224  for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
     1225  {
     1226    if (it->second->type() & type)
     1227    {
     1228      maps.push_back(it->first);
     1229    }
     1230  }
     1231  return maps;
     1232}
     1233
     1234MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
     1235{
     1236  return node_coords;
     1237}
     1238
     1239MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
     1240{
     1241  return arrow_coords;
     1242}
     1243
     1244MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest()
     1245{
     1246  return node_coords_save_dest;
     1247}
     1248
     1249MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest()
     1250{
     1251  return arrow_coords_save_dest;
     1252}
     1253
     1254void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
     1255{
     1256  node_coords_save_dest = dest;
     1257}
     1258
     1259void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
     1260{
     1261  arrow_coords_save_dest = dest;
     1262}
     1263
     1264MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum()
     1265{
     1266  return node_coords_save_map_num;
     1267}
     1268
     1269MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum()
     1270{
     1271  return arrow_coords_save_map_num;
     1272}
     1273
     1274void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
     1275{
     1276  node_coords_save_map_num = num;
     1277}
     1278
     1279void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
     1280{
     1281  arrow_coords_save_map_num = num;
     1282}
     1283
     1284const std::string& MapStorage::getNodeCoordsOneMapName()
     1285{
     1286  return node_coords_one_map_name;
     1287}
     1288const std::string& MapStorage::getNodeCoordsTwoMaps1Name()
     1289{
     1290  return node_coords_two_maps_1_name;
     1291}
     1292const std::string& MapStorage::getNodeCoordsTwoMaps2Name()
     1293{
     1294  return node_coords_two_maps_2_name;
     1295}
     1296
     1297void MapStorage::setNodeCoordsOneMapName(const std::string& name)
     1298{
     1299  node_coords_one_map_name = name;
     1300}
     1301void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name)
     1302{
     1303  node_coords_two_maps_1_name = name;
     1304}
     1305void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name)
     1306{
     1307  node_coords_two_maps_2_name = name;
     1308}
     1309
     1310const std::string& MapStorage::getArrowCoordsOneMapName()
     1311{
     1312  return arrow_coords_one_map_name;
     1313}
     1314const std::string& MapStorage::getArrowCoordsTwoMaps1Name()
     1315{
     1316  return arrow_coords_two_maps_1_name;
     1317}
     1318const std::string& MapStorage::getArrowCoordsTwoMaps2Name()
     1319{
     1320  return arrow_coords_two_maps_2_name;
     1321}
     1322
     1323void MapStorage::setArrowCoordsOneMapName(const std::string& name)
     1324{
     1325  arrow_coords_one_map_name = name;
     1326}
     1327void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name)
     1328{
     1329  arrow_coords_two_maps_1_name = name;
     1330}
     1331void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name)
     1332{
     1333  arrow_coords_two_maps_2_name = name;
     1334}
     1335
     1336void MapStorage::readLGF(
     1337    const std::string& filename,
     1338    bool read_edge_label,
     1339    const std::vector<std::string>& node_map_names,
     1340    const std::vector<std::string>& edge_map_names,
     1341    const std::map<std::string, MapValue::Type>& node_map_types,
     1342    const std::map<std::string, MapValue::Type>& edge_map_types,
     1343    const std::string& node_coord_xmap_name,
     1344    const std::string& node_coord_ymap_name,
     1345    const std::string& arrow_coord_xmap_name,
     1346    const std::string& arrow_coord_ymap_name)
     1347{
     1348  using std::vector;
     1349  using std::map;
     1350  using std::string;
     1351
     1352  GraphReader<Graph> greader(filename, graph);
     1353
     1354  // read the label maps
     1355  greader.readNodeMap("label", node_label);
     1356  if (read_edge_label)
     1357    greader.readEdgeMap("label", edge_label);
     1358
     1359  // read the node maps
     1360  for (vector<string>::const_iterator
     1361      it = node_map_names.begin();
     1362      it != node_map_names.end(); ++it)
     1363  {
     1364    switch (node_map_types.find(*it)->second)
     1365    {
     1366      case MapValue::NUMERIC:
     1367        {
     1368          createNodeMap(*it, MapValue::NUMERIC, double());
     1369          greader.readNodeMap(*it, getNumericNodeMap(*it));
     1370          break;
     1371        }
     1372      case MapValue::STRING:
     1373        {
     1374          createNodeMap(*it, MapValue::STRING, string());
     1375          greader.readNodeMap(*it, getStringNodeMap(*it));
     1376          break;
     1377        }
     1378    }
     1379    getNodeMapData(*it)->save_dest = NESET_SECT;
     1380  }
     1381
     1382  // read the edge maps
     1383  for (vector<string>::const_iterator
     1384      it = edge_map_names.begin();
     1385      it != edge_map_names.end(); ++it)
     1386  {
     1387    switch (edge_map_types.find(*it)->second)
     1388    {
     1389      case MapValue::NUMERIC:
     1390        {
     1391          createEdgeMap(*it, MapValue::NUMERIC, double());
     1392          greader.readEdgeMap(*it, getNumericEdgeMap(*it));
     1393          break;
     1394        }
     1395      case MapValue::STRING:
     1396        {
     1397          createEdgeMap(*it, MapValue::STRING, string());
     1398          greader.readEdgeMap(*it, getStringEdgeMap(*it));
     1399          break;
     1400        }
     1401    }
     1402    getEdgeMapData(*it)->save_dest = NESET_SECT;
     1403  }
     1404
     1405  // read the node coordinate maps
     1406  if (node_coord_xmap_name != "")
     1407    greader.readNodeMap(node_coord_xmap_name, node_coords_x);
     1408  if (node_coord_ymap_name != "")
     1409    greader.readNodeMap(node_coord_ymap_name, node_coords_y);
     1410
     1411  // read the arrow coordinate maps
     1412  if (arrow_coord_xmap_name != "")
     1413    greader.readEdgeMap(arrow_coord_xmap_name, arrow_coords_x);
     1414  if (arrow_coord_ymap_name != "")
     1415    greader.readEdgeMap(arrow_coord_ymap_name, arrow_coords_y);
     1416
     1417  greader.run();
    5561418}
    5571419
     
    6111473      if(active_nodemaps[N_RADIUS]!="")
    6121474        {
    613           _nodeSizes=*(nodemap_storage[active_nodemaps[N_RADIUS]]);
     1475          _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]);
    6141476        }
    6151477      if(active_nodemaps[N_COLOR]!="")
     
    6171479          for(NodeIt ni(graph);ni!=INVALID;++ni)
    6181480            {
    619               _nodeColors[ni]=(int)((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]);
     1481              _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni);
    6201482            }
    6211483        }
     
    6251487            {
    6261488              std::ostringstream o;
    627               o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]);
     1489              o << get(active_nodemaps[N_TEXT], ni);
    6281490              _nodeTextMap[ni]=o.str();       
    6291491            }
     
    6341496      if(active_edgemaps[E_WIDTH]!="")
    6351497        {
    636           _edgeWidths=*(edgemap_storage[active_edgemaps[E_WIDTH]]);
     1498          _edgeWidths=getNumericEdgeMap(active_edgemaps[E_WIDTH]);
    6371499        }
    6381500      if(active_edgemaps[E_COLOR]!="")
     
    6401502          for(EdgeIt ei(graph);ei!=INVALID;++ei)
    6411503            {
    642               _edgeColors[ei]=(int)((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]);
     1504              _edgeColors[ei]=(int)get(active_edgemaps[E_COLOR], ei);
    6431505            }
    6441506        }
     
    6461508  if(shapemap!="Default values")
    6471509    {
    648       if((minOfNodeMap(shapemap)>=0)&&(maxOfNodeMap(shapemap)<=4))
     1510      double min = std::numeric_limits<double>::max();
     1511      double max = std::numeric_limits<double>::min();
     1512      for (NodeIt n(graph); n != INVALID; ++n)
     1513      {
     1514        double v = static_cast<double>(get(shapemap, n));
     1515        if (v < min) min = v;
     1516        if (v > max) max = v;
     1517      }
     1518      if((min>=0)&&(max<=4))
    6491519        {
    650           _shapes=*(nodemap_storage[shapemap]);
     1520          NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map;
     1521          for (NodeIt n(graph); n != INVALID; ++n)
     1522          {
     1523            _shapes[n] = static_cast<int>(map[n]);
     1524          }
    6511525        }
    6521526    }
     
    6601534    absoluteNodeSizes().absoluteEdgeWidths().
    6611535    nodeScale(2).nodeSizes(_nodeSizes).
    662     coords(coords).
     1536    coords(node_coords).
    6631537    nodeShapes(_shapes).
    6641538    nodeColors(composeMap(paletteW,_nodeColors)).
Note: See TracChangeset for help on using the changeset viewer.