gui_reader.cc
changeset 201 879e47e5b731
parent 194 6b2b718420eb
     1.1 --- a/gui_reader.cc	Wed May 02 20:33:58 2007 +0000
     1.2 +++ b/gui_reader.cc	Wed Jan 02 21:03:09 2008 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  #include <mapstorage.h>
     1.5  
     1.6  #include <xml.h>
     1.7 +#include "io_helper.h"
     1.8  #include <lemon/dim2.h>
     1.9  #include <vector>
    1.10  
    1.11 @@ -33,34 +34,139 @@
    1.12  
    1.13  void GuiReader::read(std::istream& is)
    1.14  {
    1.15 +  using std::vector;
    1.16 +  using std::string;
    1.17 +  using std::pair;
    1.18 +  using std::make_pair;
    1.19 +  using std::string;
    1.20 +  using std::map;
    1.21 +
    1.22    XmlIo x(is);
    1.23 -  std::map<int, XY > m;
    1.24 -  x("arrow_pos", m);
    1.25  
    1.26 -  if ((int)m.size() == countEdges(mapstorage->graph))
    1.27 +  { x("main_node_map_names", gui_data.main_node_map_names); }
    1.28 +  { x("gui_node_map_names", gui_data.gui_node_map_names); }
    1.29 +
    1.30 +  { x("node_map_types", gui_data.node_map_types); }
    1.31 +
    1.32 +  { x("main_edge_map_names", gui_data.main_edge_map_names); }
    1.33 +  { x("gui_edge_map_names", gui_data.gui_edge_map_names); }
    1.34 +
    1.35 +  { x("edge_map_types", gui_data.edge_map_types); }
    1.36 +
    1.37 +  for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin();
    1.38 +      it != gui_data.gui_node_map_names.end(); ++it)
    1.39 +  {
    1.40 +    MapValue::Type type = gui_data.node_map_types[*it];
    1.41 +    switch (type)
    1.42      {
    1.43 -      for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
    1.44 -	{
    1.45 -	  int edgeid = (int)(*mapstorage->edgemap_storage["label"])[e];
    1.46 -	  mapstorage->arrow_pos.set(e, m[edgeid]);
    1.47 -	}
    1.48 -      mapstorage->ArrowPosReadOK();
    1.49 +      case MapValue::NUMERIC:
    1.50 +        {
    1.51 +          map<int, double>* p_map_data =
    1.52 +            new map<int, double>;
    1.53 +          gui_data.numeric_node_maps[*it] = p_map_data;
    1.54 +          { x(*it, *p_map_data); }
    1.55 +        }
    1.56 +        break;
    1.57 +      case MapValue::STRING:
    1.58 +        {
    1.59 +          map<int, string>* p_map_data =
    1.60 +            new map<int, string>;
    1.61 +          gui_data.string_node_maps[*it] = p_map_data;
    1.62 +          { x(*it, *p_map_data); }
    1.63 +        }
    1.64 +        break;
    1.65      }
    1.66 -  
    1.67 +  }
    1.68 +
    1.69 +  for (vector<string>::const_iterator it = gui_data.gui_edge_map_names.begin();
    1.70 +      it != gui_data.gui_edge_map_names.end(); ++it)
    1.71 +  {
    1.72 +    MapValue::Type type = gui_data.edge_map_types[*it];
    1.73 +    switch (type)
    1.74 +    {
    1.75 +      case MapValue::NUMERIC:
    1.76 +        {
    1.77 +          map<int, double>* p_map_data =
    1.78 +            new map<int, double>;
    1.79 +          gui_data.numeric_edge_maps[*it] = p_map_data;
    1.80 +          { x(*it, *p_map_data); }
    1.81 +        }
    1.82 +        break;
    1.83 +      case MapValue::STRING:
    1.84 +        {
    1.85 +          map<int, string>* p_map_data =
    1.86 +            new map<int, string>;
    1.87 +          gui_data.string_edge_maps[*it] = p_map_data;
    1.88 +          { x(*it, *p_map_data); }
    1.89 +        }
    1.90 +        break;
    1.91 +    }
    1.92 +  }
    1.93 +
    1.94 +  {
    1.95 +    std::string node_coords_save_dest;
    1.96 +    { x("node_coords_save_dest", node_coords_save_dest); }
    1.97 +    if (node_coords_save_dest == "gui_sect")
    1.98 +    {
    1.99 +      // read the node coorinates
   1.100 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
   1.101 +      { x("node_coord_map", gui_data.node_coord_map); }
   1.102 +    }
   1.103 +    else if (node_coords_save_dest == "nodeset_sect_1_map")
   1.104 +    {
   1.105 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.106 +      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
   1.107 +      { x("map_name", gui_data.node_coords_one_map_name); }
   1.108 +    }
   1.109 +    else if (node_coords_save_dest == "nodeset_sect_2_maps")
   1.110 +    {
   1.111 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.112 +      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
   1.113 +      { x("map1_name", gui_data.node_coords_two_maps_1_name); }
   1.114 +      { x("map2_name", gui_data.node_coords_two_maps_2_name); }
   1.115 +    }
   1.116 +  }
   1.117 +
   1.118 +  {
   1.119 +    std::string arrow_coords_save_dest;
   1.120 +    { x("arrow_coords_save_dest", arrow_coords_save_dest); }
   1.121 +    if (arrow_coords_save_dest == "gui_sect")
   1.122 +    {
   1.123 +      // read the arrow coorinates
   1.124 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
   1.125 +      { x("arrow_coord_map", gui_data.arrow_coord_map); }
   1.126 +    }
   1.127 +    else if (arrow_coords_save_dest == "edgeset_sect_1_map")
   1.128 +    {
   1.129 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.130 +      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
   1.131 +      { x("map_name", gui_data.arrow_coords_one_map_name); }
   1.132 +    }
   1.133 +    else if (arrow_coords_save_dest == "edgeset_sect_2_maps")
   1.134 +    {
   1.135 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.136 +      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
   1.137 +      { x("map1_name", gui_data.arrow_coords_two_maps_1_name); }
   1.138 +      { x("map2_name", gui_data.arrow_coords_two_maps_2_name); }
   1.139 +    }
   1.140 +  }
   1.141 +
   1.142 +
   1.143 +
   1.144    std::map<int, std::string> nm;
   1.145    x("active_nodemaps", nm);
   1.146  
   1.147    for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.148 -    {
   1.149 -      mapstorage->changeActiveMap(false, i, nm[i]);
   1.150 -    }
   1.151 +  {
   1.152 +    mapstorage->changeActiveMap(false, i, nm[i]);
   1.153 +  }
   1.154  
   1.155    std::map<int, std::string> em;
   1.156    x("active_edgemaps", em);
   1.157    for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.158 -    {
   1.159 -      mapstorage->changeActiveMap(true, i, em[i]);
   1.160 -    }
   1.161 +  {
   1.162 +    mapstorage->changeActiveMap(true, i, em[i]);
   1.163 +  }
   1.164  
   1.165    double attraction;
   1.166    double propulsation;
   1.167 @@ -77,6 +183,10 @@
   1.168    mapstorage->redesign_data_changed();
   1.169  }
   1.170  
   1.171 -GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms)
   1.172 +GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage,
   1.173 +    MapStorage::GUISectData& _gui_data) :
   1.174 +  Parent(reader),
   1.175 +  mapstorage(_mapstorage),
   1.176 +  gui_data(_gui_data)
   1.177  {
   1.178  }