gui_reader.cc
author Peter Hegyi <hegyi@tmit.bme.hu>
Wed, 13 Aug 2008 17:24:25 +0100
changeset 6 3a44a2bb6da8
permissions -rw-r--r--
Remove lemon/graph_utils.h include.
hegyi@1
     1
/* -*- C++ -*-
hegyi@1
     2
 *
hegyi@1
     3
 * This file is a part of LEMON, a generic C++ optimization library
hegyi@1
     4
 *
hegyi@1
     5
 * Copyright (C) 2003-2006
hegyi@1
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
hegyi@1
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
hegyi@1
     8
 *
hegyi@1
     9
 * Permission to use, modify and distribute this software is granted
hegyi@1
    10
 * provided that this copyright notice appears in all copies. For
hegyi@1
    11
 * precise terms see the accompanying LICENSE file.
hegyi@1
    12
 *
hegyi@1
    13
 * This software is provided "AS IS" with no warranty of any kind,
hegyi@1
    14
 * express or implied, and with no claim as to its suitability for any
hegyi@1
    15
 * purpose.
hegyi@1
    16
 *
hegyi@1
    17
 */
hegyi@1
    18
hegyi@1
    19
#include <gui_reader.h>
hegyi@1
    20
#include <mapstorage.h>
hegyi@1
    21
hegyi@1
    22
#include <xml.h>
hegyi@1
    23
#include "io_helper.h"
hegyi@1
    24
#include <lemon/dim2.h>
hegyi@1
    25
#include <vector>
hegyi@1
    26
hegyi@1
    27
// bool GuiReader::header(const std::string& line)
hegyi@1
    28
// {
hegyi@1
    29
//   std::istringstream ls(line);
hegyi@1
    30
//   std::string head;
hegyi@1
    31
//   ls >> head;
hegyi@1
    32
//   return head == "@gui";
hegyi@1
    33
// }
hegyi@1
    34
hegyi@1
    35
//void GuiReader::read(std::istream& is)
hegyi@1
    36
void GuiReader::operator()(std::istream& is, int& ln)
hegyi@1
    37
{
hegyi@1
    38
  using std::vector;
hegyi@1
    39
  using std::string;
hegyi@1
    40
  using std::pair;
hegyi@1
    41
  using std::make_pair;
hegyi@1
    42
  using std::string;
hegyi@1
    43
  using std::map;
hegyi@1
    44
hegyi@1
    45
  XmlIo x(is);
hegyi@1
    46
hegyi@1
    47
  { x("main_node_map_names", gui_data.main_node_map_names); }
hegyi@1
    48
  { x("gui_node_map_names", gui_data.gui_node_map_names); }
hegyi@1
    49
hegyi@1
    50
  { x("node_map_types", gui_data.node_map_types); }
hegyi@1
    51
hegyi@1
    52
  { x("main_arc_map_names", gui_data.main_arc_map_names); }
hegyi@1
    53
  { x("gui_arc_map_names", gui_data.gui_arc_map_names); }
hegyi@1
    54
hegyi@1
    55
  { x("arc_map_types", gui_data.arc_map_types); }
hegyi@1
    56
hegyi@1
    57
  for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin();
hegyi@1
    58
      it != gui_data.gui_node_map_names.end(); ++it)
hegyi@1
    59
  {
hegyi@1
    60
    MapValue::Type type = gui_data.node_map_types[*it];
hegyi@1
    61
    switch (type)
hegyi@1
    62
    {
hegyi@1
    63
      case MapValue::NUMERIC:
hegyi@1
    64
        {
hegyi@1
    65
          map<int, double>* p_map_data =
hegyi@1
    66
            new map<int, double>;
hegyi@1
    67
          gui_data.numeric_node_maps[*it] = p_map_data;
hegyi@1
    68
          { x(*it, *p_map_data); }
hegyi@1
    69
        }
hegyi@1
    70
        break;
hegyi@1
    71
      case MapValue::STRING:
hegyi@1
    72
        {
hegyi@1
    73
          map<int, string>* p_map_data =
hegyi@1
    74
            new map<int, string>;
hegyi@1
    75
          gui_data.string_node_maps[*it] = p_map_data;
hegyi@1
    76
          { x(*it, *p_map_data); }
hegyi@1
    77
        }
hegyi@1
    78
        break;
hegyi@1
    79
    }
hegyi@1
    80
  }
hegyi@1
    81
hegyi@1
    82
  for (vector<string>::const_iterator it = gui_data.gui_arc_map_names.begin();
hegyi@1
    83
      it != gui_data.gui_arc_map_names.end(); ++it)
hegyi@1
    84
  {
hegyi@1
    85
    MapValue::Type type = gui_data.arc_map_types[*it];
hegyi@1
    86
    switch (type)
hegyi@1
    87
    {
hegyi@1
    88
      case MapValue::NUMERIC:
hegyi@1
    89
        {
hegyi@1
    90
          map<int, double>* p_map_data =
hegyi@1
    91
            new map<int, double>;
hegyi@1
    92
          gui_data.numeric_arc_maps[*it] = p_map_data;
hegyi@1
    93
          { x(*it, *p_map_data); }
hegyi@1
    94
        }
hegyi@1
    95
        break;
hegyi@1
    96
      case MapValue::STRING:
hegyi@1
    97
        {
hegyi@1
    98
          map<int, string>* p_map_data =
hegyi@1
    99
            new map<int, string>;
hegyi@1
   100
          gui_data.string_arc_maps[*it] = p_map_data;
hegyi@1
   101
          { x(*it, *p_map_data); }
hegyi@1
   102
        }
hegyi@1
   103
        break;
hegyi@1
   104
    }
hegyi@1
   105
  }
hegyi@1
   106
hegyi@1
   107
  {
hegyi@1
   108
    std::string node_coords_save_dest;
hegyi@1
   109
    { x("node_coords_save_dest", node_coords_save_dest); }
hegyi@1
   110
    if (node_coords_save_dest == "gui_sect")
hegyi@1
   111
    {
hegyi@1
   112
      // read the node coorinates
hegyi@1
   113
      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
hegyi@1
   114
      { x("node_coord_map", gui_data.node_coord_map); }
hegyi@1
   115
    }
hegyi@1
   116
    else if (node_coords_save_dest == "nodeset_sect_1_map")
hegyi@1
   117
    {
hegyi@1
   118
      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
hegyi@1
   119
      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
hegyi@1
   120
      { x("map_name", gui_data.node_coords_one_map_name); }
hegyi@1
   121
    }
hegyi@1
   122
    else if (node_coords_save_dest == "nodeset_sect_2_maps")
hegyi@1
   123
    {
hegyi@1
   124
      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
hegyi@1
   125
      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
hegyi@1
   126
      { x("map1_name", gui_data.node_coords_two_maps_1_name); }
hegyi@1
   127
      { x("map2_name", gui_data.node_coords_two_maps_2_name); }
hegyi@1
   128
    }
hegyi@1
   129
  }
hegyi@1
   130
hegyi@1
   131
  {
hegyi@1
   132
    std::string arrow_coords_save_dest;
hegyi@1
   133
    { x("arrow_coords_save_dest", arrow_coords_save_dest); }
hegyi@1
   134
    if (arrow_coords_save_dest == "gui_sect")
hegyi@1
   135
    {
hegyi@1
   136
      // read the arrow coorinates
hegyi@1
   137
      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
hegyi@1
   138
      { x("arrow_coord_map", gui_data.arrow_coord_map); }
hegyi@1
   139
    }
hegyi@1
   140
    else if (arrow_coords_save_dest == "arcset_sect_1_map")
hegyi@1
   141
    {
hegyi@1
   142
      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
hegyi@1
   143
      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
hegyi@1
   144
      { x("map_name", gui_data.arrow_coords_one_map_name); }
hegyi@1
   145
    }
hegyi@1
   146
    else if (arrow_coords_save_dest == "arcset_sect_2_maps")
hegyi@1
   147
    {
hegyi@1
   148
      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
hegyi@1
   149
      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
hegyi@1
   150
      { x("map1_name", gui_data.arrow_coords_two_maps_1_name); }
hegyi@1
   151
      { x("map2_name", gui_data.arrow_coords_two_maps_2_name); }
hegyi@1
   152
    }
hegyi@1
   153
  }
hegyi@1
   154
hegyi@1
   155
hegyi@1
   156
hegyi@1
   157
  std::map<int, std::string> nm;
hegyi@1
   158
  x("active_nodemaps", nm);
hegyi@1
   159
hegyi@1
   160
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1
   161
  {
hegyi@1
   162
    mapstorage->changeActiveMap(false, i, nm[i]);
hegyi@1
   163
  }
hegyi@1
   164
hegyi@1
   165
  std::map<int, std::string> em;
hegyi@1
   166
  x("active_arcmaps", em);
hegyi@1
   167
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1
   168
  {
hegyi@1
   169
    mapstorage->changeActiveMap(true, i, em[i]);
hegyi@1
   170
  }
hegyi@1
   171
hegyi@1
   172
  double attraction;
hegyi@1
   173
  double propulsation;
hegyi@1
   174
  int iteration;
hegyi@1
   175
hegyi@1
   176
  x("redesign-attraction", attraction);
hegyi@1
   177
  x("redesign-propulsation", propulsation);
hegyi@1
   178
  x("redesign-iteration", iteration);
hegyi@1
   179
hegyi@1
   180
  mapstorage->set_attraction(attraction);
hegyi@1
   181
  mapstorage->set_propulsation(propulsation);
hegyi@1
   182
  mapstorage->set_iteration(iteration);
hegyi@1
   183
hegyi@1
   184
  mapstorage->redesign_data_changed();
hegyi@1
   185
}
hegyi@1
   186
hegyi@1
   187
//GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage,
hegyi@1
   188
GuiReader::GuiReader(MapStorage* _mapstorage,
hegyi@1
   189
    MapStorage::GUISectData& _gui_data) :
hegyi@1
   190
  //Parent(reader),
hegyi@1
   191
  mapstorage(_mapstorage),
hegyi@1
   192
  gui_data(_gui_data)
hegyi@1
   193
{
hegyi@1
   194
}