gui_reader.cc
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui_reader.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,194 @@
     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 copies. 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 <gui_reader.h>
    1.23 +#include <mapstorage.h>
    1.24 +
    1.25 +#include <xml.h>
    1.26 +#include "io_helper.h"
    1.27 +#include <lemon/dim2.h>
    1.28 +#include <vector>
    1.29 +
    1.30 +// bool GuiReader::header(const std::string& line)
    1.31 +// {
    1.32 +//   std::istringstream ls(line);
    1.33 +//   std::string head;
    1.34 +//   ls >> head;
    1.35 +//   return head == "@gui";
    1.36 +// }
    1.37 +
    1.38 +//void GuiReader::read(std::istream& is)
    1.39 +void GuiReader::operator()(std::istream& is, int& ln)
    1.40 +{
    1.41 +  using std::vector;
    1.42 +  using std::string;
    1.43 +  using std::pair;
    1.44 +  using std::make_pair;
    1.45 +  using std::string;
    1.46 +  using std::map;
    1.47 +
    1.48 +  XmlIo x(is);
    1.49 +
    1.50 +  { x("main_node_map_names", gui_data.main_node_map_names); }
    1.51 +  { x("gui_node_map_names", gui_data.gui_node_map_names); }
    1.52 +
    1.53 +  { x("node_map_types", gui_data.node_map_types); }
    1.54 +
    1.55 +  { x("main_arc_map_names", gui_data.main_arc_map_names); }
    1.56 +  { x("gui_arc_map_names", gui_data.gui_arc_map_names); }
    1.57 +
    1.58 +  { x("arc_map_types", gui_data.arc_map_types); }
    1.59 +
    1.60 +  for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin();
    1.61 +      it != gui_data.gui_node_map_names.end(); ++it)
    1.62 +  {
    1.63 +    MapValue::Type type = gui_data.node_map_types[*it];
    1.64 +    switch (type)
    1.65 +    {
    1.66 +      case MapValue::NUMERIC:
    1.67 +        {
    1.68 +          map<int, double>* p_map_data =
    1.69 +            new map<int, double>;
    1.70 +          gui_data.numeric_node_maps[*it] = p_map_data;
    1.71 +          { x(*it, *p_map_data); }
    1.72 +        }
    1.73 +        break;
    1.74 +      case MapValue::STRING:
    1.75 +        {
    1.76 +          map<int, string>* p_map_data =
    1.77 +            new map<int, string>;
    1.78 +          gui_data.string_node_maps[*it] = p_map_data;
    1.79 +          { x(*it, *p_map_data); }
    1.80 +        }
    1.81 +        break;
    1.82 +    }
    1.83 +  }
    1.84 +
    1.85 +  for (vector<string>::const_iterator it = gui_data.gui_arc_map_names.begin();
    1.86 +      it != gui_data.gui_arc_map_names.end(); ++it)
    1.87 +  {
    1.88 +    MapValue::Type type = gui_data.arc_map_types[*it];
    1.89 +    switch (type)
    1.90 +    {
    1.91 +      case MapValue::NUMERIC:
    1.92 +        {
    1.93 +          map<int, double>* p_map_data =
    1.94 +            new map<int, double>;
    1.95 +          gui_data.numeric_arc_maps[*it] = p_map_data;
    1.96 +          { x(*it, *p_map_data); }
    1.97 +        }
    1.98 +        break;
    1.99 +      case MapValue::STRING:
   1.100 +        {
   1.101 +          map<int, string>* p_map_data =
   1.102 +            new map<int, string>;
   1.103 +          gui_data.string_arc_maps[*it] = p_map_data;
   1.104 +          { x(*it, *p_map_data); }
   1.105 +        }
   1.106 +        break;
   1.107 +    }
   1.108 +  }
   1.109 +
   1.110 +  {
   1.111 +    std::string node_coords_save_dest;
   1.112 +    { x("node_coords_save_dest", node_coords_save_dest); }
   1.113 +    if (node_coords_save_dest == "gui_sect")
   1.114 +    {
   1.115 +      // read the node coorinates
   1.116 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
   1.117 +      { x("node_coord_map", gui_data.node_coord_map); }
   1.118 +    }
   1.119 +    else if (node_coords_save_dest == "nodeset_sect_1_map")
   1.120 +    {
   1.121 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.122 +      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
   1.123 +      { x("map_name", gui_data.node_coords_one_map_name); }
   1.124 +    }
   1.125 +    else if (node_coords_save_dest == "nodeset_sect_2_maps")
   1.126 +    {
   1.127 +      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.128 +      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
   1.129 +      { x("map1_name", gui_data.node_coords_two_maps_1_name); }
   1.130 +      { x("map2_name", gui_data.node_coords_two_maps_2_name); }
   1.131 +    }
   1.132 +  }
   1.133 +
   1.134 +  {
   1.135 +    std::string arrow_coords_save_dest;
   1.136 +    { x("arrow_coords_save_dest", arrow_coords_save_dest); }
   1.137 +    if (arrow_coords_save_dest == "gui_sect")
   1.138 +    {
   1.139 +      // read the arrow coorinates
   1.140 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
   1.141 +      { x("arrow_coord_map", gui_data.arrow_coord_map); }
   1.142 +    }
   1.143 +    else if (arrow_coords_save_dest == "arcset_sect_1_map")
   1.144 +    {
   1.145 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.146 +      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
   1.147 +      { x("map_name", gui_data.arrow_coords_one_map_name); }
   1.148 +    }
   1.149 +    else if (arrow_coords_save_dest == "arcset_sect_2_maps")
   1.150 +    {
   1.151 +      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
   1.152 +      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
   1.153 +      { x("map1_name", gui_data.arrow_coords_two_maps_1_name); }
   1.154 +      { x("map2_name", gui_data.arrow_coords_two_maps_2_name); }
   1.155 +    }
   1.156 +  }
   1.157 +
   1.158 +
   1.159 +
   1.160 +  std::map<int, std::string> nm;
   1.161 +  x("active_nodemaps", nm);
   1.162 +
   1.163 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.164 +  {
   1.165 +    mapstorage->changeActiveMap(false, i, nm[i]);
   1.166 +  }
   1.167 +
   1.168 +  std::map<int, std::string> em;
   1.169 +  x("active_arcmaps", em);
   1.170 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.171 +  {
   1.172 +    mapstorage->changeActiveMap(true, i, em[i]);
   1.173 +  }
   1.174 +
   1.175 +  double attraction;
   1.176 +  double propulsation;
   1.177 +  int iteration;
   1.178 +
   1.179 +  x("redesign-attraction", attraction);
   1.180 +  x("redesign-propulsation", propulsation);
   1.181 +  x("redesign-iteration", iteration);
   1.182 +
   1.183 +  mapstorage->set_attraction(attraction);
   1.184 +  mapstorage->set_propulsation(propulsation);
   1.185 +  mapstorage->set_iteration(iteration);
   1.186 +
   1.187 +  mapstorage->redesign_data_changed();
   1.188 +}
   1.189 +
   1.190 +//GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage,
   1.191 +GuiReader::GuiReader(MapStorage* _mapstorage,
   1.192 +    MapStorage::GUISectData& _gui_data) :
   1.193 +  //Parent(reader),
   1.194 +  mapstorage(_mapstorage),
   1.195 +  gui_data(_gui_data)
   1.196 +{
   1.197 +}