gui_writer.cc
changeset 201 879e47e5b731
parent 194 6b2b718420eb
     1.1 --- a/gui_writer.cc	Wed May 02 20:33:58 2007 +0000
     1.2 +++ b/gui_writer.cc	Wed Jan 02 21:03:09 2008 +0000
     1.3 @@ -16,7 +16,10 @@
     1.4   *
     1.5   */
     1.6  
     1.7 -#include <xml.h>
     1.8 +#include "gui_writer.h"
     1.9 +#include "io_helper.h"
    1.10 +#include "mapstorage.h"
    1.11 +#include "xml.h"
    1.12  #include <lemon/dim2.h>
    1.13  #include <vector>
    1.14  
    1.15 @@ -30,28 +33,232 @@
    1.16  
    1.17  void GuiWriter::write(std::ostream& os)
    1.18  {
    1.19 +  using std::vector;
    1.20 +  using std::string;
    1.21 +  using std::map;
    1.22 +  using std::string;
    1.23 +
    1.24    XmlIo x(os);
    1.25 -  std::map<int, XY > m;
    1.26 -  for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
    1.27 +
    1.28 +  vector<string> all_node_map_names = mapstorage->getNodeMapList();
    1.29 +  // name of the maps saved to the nodeset section
    1.30 +  vector<string> main_node_map_names;
    1.31 +  // name of the maps saved to the gui section
    1.32 +  vector<string> gui_node_map_names;
    1.33 +
    1.34 +  for (vector<string>::const_iterator it = all_node_map_names.begin();
    1.35 +      it != all_node_map_names.end(); ++it)
    1.36    {
    1.37 -    int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e];
    1.38 -    m[edgeid] = mapstorage->arrow_pos[e];
    1.39 +    if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT)
    1.40 +      main_node_map_names.push_back(*it);
    1.41 +    else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT)
    1.42 +      gui_node_map_names.push_back(*it);
    1.43    }
    1.44 -  x("arrow_pos", m);
    1.45 +
    1.46 +  { x("main_node_map_names", main_node_map_names); }
    1.47 +  { x("gui_node_map_names", gui_node_map_names); }
    1.48 +
    1.49 +  map<string, MapValue::Type> node_map_types;
    1.50 +  for (vector<string>::const_iterator it = main_node_map_names.begin();
    1.51 +      it != main_node_map_names.end(); ++it)
    1.52 +  {
    1.53 +    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
    1.54 +  }
    1.55 +  for (vector<string>::const_iterator it = gui_node_map_names.begin();
    1.56 +      it != gui_node_map_names.end(); ++it)
    1.57 +  {
    1.58 +    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
    1.59 +  }
    1.60 +
    1.61 +  { x("node_map_types", node_map_types); }
    1.62 +
    1.63 +
    1.64 +  vector<string> all_edge_map_names = mapstorage->getEdgeMapList();
    1.65 +  // name of the maps saved to the edgeset section
    1.66 +  vector<string> main_edge_map_names;
    1.67 +  // name of the maps saved to the gui section
    1.68 +  vector<string> gui_edge_map_names;
    1.69 +
    1.70 +  for (vector<string>::const_iterator it = all_edge_map_names.begin();
    1.71 +      it != all_edge_map_names.end(); ++it)
    1.72 +  {
    1.73 +    if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::NESET_SECT)
    1.74 +      main_edge_map_names.push_back(*it);
    1.75 +    if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::GUI_SECT)
    1.76 +      gui_edge_map_names.push_back(*it);
    1.77 +  }
    1.78 +
    1.79 +  { x("main_edge_map_names", main_edge_map_names); }
    1.80 +  { x("gui_edge_map_names", gui_edge_map_names); }
    1.81 +
    1.82 +  map<string, MapValue::Type> edge_map_types;
    1.83 +  for (vector<string>::const_iterator it = main_edge_map_names.begin();
    1.84 +      it != main_edge_map_names.end(); ++it)
    1.85 +  {
    1.86 +    edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it);
    1.87 +  }
    1.88 +  for (vector<string>::const_iterator it = gui_edge_map_names.begin();
    1.89 +      it != gui_edge_map_names.end(); ++it)
    1.90 +  {
    1.91 +    edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it);
    1.92 +  }
    1.93 +
    1.94 +  { x("edge_map_types", edge_map_types); }
    1.95 +
    1.96 +  // write the gui node maps
    1.97 +  for (vector<string>::const_iterator it = gui_node_map_names.begin();
    1.98 +      it != gui_node_map_names.end(); ++it)
    1.99 +  {
   1.100 +    MapValue::Type type = mapstorage->getNodeMapElementType(*it);
   1.101 +    const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
   1.102 +    switch (type)
   1.103 +    {
   1.104 +      case MapValue::NUMERIC:
   1.105 +        {
   1.106 +          std::map<int, double> map_data;
   1.107 +          MapStorage::NumericNodeMap& map =
   1.108 +            mapstorage->getNumericNodeMap(*it);
   1.109 +          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
   1.110 +          {
   1.111 +            map_data[labels[n]] = map[n];
   1.112 +          }
   1.113 +          { x(*it, map_data); }
   1.114 +        }
   1.115 +        break;
   1.116 +      case MapValue::STRING:
   1.117 +        {
   1.118 +          std::map<int, std::string> map_data;
   1.119 +          MapStorage::StringNodeMap& map =
   1.120 +            mapstorage->getStringNodeMap(*it);
   1.121 +          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
   1.122 +          {
   1.123 +            map_data[labels[n]] = map[n];
   1.124 +          }
   1.125 +          { x(*it, map_data); }
   1.126 +        }
   1.127 +        break;
   1.128 +    }
   1.129 +  }
   1.130 +
   1.131 +  // write the gui edge maps
   1.132 +  for (vector<string>::const_iterator it = gui_edge_map_names.begin();
   1.133 +      it != gui_edge_map_names.end(); ++it)
   1.134 +  {
   1.135 +    MapValue::Type type = mapstorage->getEdgeMapElementType(*it);
   1.136 +    const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap();
   1.137 +    switch (type)
   1.138 +    {
   1.139 +      case MapValue::NUMERIC:
   1.140 +        {
   1.141 +          std::map<int, double> map_data;
   1.142 +          MapStorage::NumericEdgeMap& map =
   1.143 +            mapstorage->getNumericEdgeMap(*it);
   1.144 +          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
   1.145 +          {
   1.146 +            map_data[labels[e]] = map[e];
   1.147 +          }
   1.148 +          { x(*it, map_data); }
   1.149 +        }
   1.150 +        break;
   1.151 +      case MapValue::STRING:
   1.152 +        {
   1.153 +          std::map<int, std::string> map_data;
   1.154 +          MapStorage::StringEdgeMap& map =
   1.155 +            mapstorage->getStringEdgeMap(*it);
   1.156 +          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
   1.157 +          {
   1.158 +            map_data[labels[e]] = map[e];
   1.159 +          }
   1.160 +          { x(*it, map_data); }
   1.161 +        }
   1.162 +        break;
   1.163 +    }
   1.164 +  }
   1.165 +
   1.166 +  {
   1.167 +    switch (mapstorage->getNodeCoordsSaveDest())
   1.168 +    {
   1.169 +      case MapStorage::SpecMapSaveOpts::GUI_SECT:
   1.170 +        { x("node_coords_save_dest", string("gui_sect")); }
   1.171 +        // write the node coorinates
   1.172 +        {
   1.173 +          const MapStorage::NodeLabelMap& labels =
   1.174 +            mapstorage->getNodeLabelMap();
   1.175 +          std::map<int, XY> node_coord_map;
   1.176 +          MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
   1.177 +          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
   1.178 +          {
   1.179 +            node_coord_map[labels[n]] = map[n];
   1.180 +          }
   1.181 +          { x("node_coord_map", node_coord_map); }
   1.182 +        }
   1.183 +        break;
   1.184 +      case MapStorage::SpecMapSaveOpts::NESET_SECT:
   1.185 +        switch (mapstorage->getNodeCoordsSaveMapNum())
   1.186 +        {
   1.187 +          case MapStorage::SpecMapSaveOpts::ONE_MAP:
   1.188 +            { x("node_coords_save_dest", string("nodeset_sect_1_map")); }
   1.189 +            { x("map_name", mapstorage->getNodeCoordsOneMapName()); }
   1.190 +            break;
   1.191 +          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
   1.192 +            { x("node_coords_save_dest", string("nodeset_sect_2_maps")); }
   1.193 +            { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); }
   1.194 +            { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); }
   1.195 +            break;
   1.196 +        }
   1.197 +        break;
   1.198 +    }
   1.199 +  }
   1.200 +
   1.201 +  {
   1.202 +    switch (mapstorage->getArrowCoordsSaveDest())
   1.203 +    {
   1.204 +      case MapStorage::SpecMapSaveOpts::GUI_SECT:
   1.205 +        { x("arrow_coords_save_dest", string("gui_sect")); }
   1.206 +        // write the arrow coorinates
   1.207 +        {
   1.208 +          const MapStorage::EdgeLabelMap& labels =
   1.209 +            mapstorage->getEdgeLabelMap();
   1.210 +          std::map<int, XY> arrow_coord_map;
   1.211 +          MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
   1.212 +          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
   1.213 +          {
   1.214 +            arrow_coord_map[labels[e]] = map[e];
   1.215 +          }
   1.216 +          { x("arrow_coord_map", arrow_coord_map); }
   1.217 +        }
   1.218 +        break;
   1.219 +      case MapStorage::SpecMapSaveOpts::NESET_SECT:
   1.220 +        switch (mapstorage->getArrowCoordsSaveMapNum())
   1.221 +        {
   1.222 +          case MapStorage::SpecMapSaveOpts::ONE_MAP:
   1.223 +            { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); }
   1.224 +            { x("map_name", mapstorage->getArrowCoordsOneMapName()); }
   1.225 +            break;
   1.226 +          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
   1.227 +            { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); }
   1.228 +            { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); }
   1.229 +            { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); }
   1.230 +            break;
   1.231 +        }
   1.232 +        break;
   1.233 +    }
   1.234 +  }
   1.235 +
   1.236  
   1.237    std::map<int, std::string> nm;
   1.238    for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.239      {
   1.240        nm[i]=mapstorage->active_nodemaps[i];
   1.241      }
   1.242 -  x("active_nodemaps", nm);
   1.243 +  { x("active_nodemaps", nm); }
   1.244  
   1.245    std::map<int, std::string> em;
   1.246    for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.247      {
   1.248        em[i]=mapstorage->active_edgemaps[i];
   1.249      }
   1.250 -  x("active_edgemaps", em);
   1.251 +  { x("active_edgemaps", em); }
   1.252  
   1.253    double attraction;
   1.254    double propulsation;
   1.255 @@ -59,11 +266,13 @@
   1.256  
   1.257    mapstorage->get_design_data(attraction, propulsation, iteration);
   1.258  
   1.259 -  x("redesign-attraction", attraction);
   1.260 -  x("redesign-propulsation", propulsation);
   1.261 -  x("redesign-iteration", iteration);
   1.262 +  { x("redesign-attraction", attraction); }
   1.263 +  { x("redesign-propulsation", propulsation); }
   1.264 +  { x("redesign-iteration", iteration); }
   1.265  }
   1.266  
   1.267 -GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms)
   1.268 +GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) :
   1.269 +  Parent(writer),
   1.270 +  mapstorage(ms)
   1.271  {
   1.272  }