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