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 | { |
---|
37 | using std::vector; |
---|
38 | using std::string; |
---|
39 | using std::pair; |
---|
40 | using std::make_pair; |
---|
41 | using std::string; |
---|
42 | using std::map; |
---|
43 | |
---|
44 | XmlIo x(is); |
---|
45 | |
---|
46 | { x("main_node_map_names", gui_data.main_node_map_names); } |
---|
47 | { x("gui_node_map_names", gui_data.gui_node_map_names); } |
---|
48 | |
---|
49 | { x("node_map_types", gui_data.node_map_types); } |
---|
50 | |
---|
51 | { x("main_edge_map_names", gui_data.main_edge_map_names); } |
---|
52 | { x("gui_edge_map_names", gui_data.gui_edge_map_names); } |
---|
53 | |
---|
54 | { x("edge_map_types", gui_data.edge_map_types); } |
---|
55 | |
---|
56 | for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin(); |
---|
57 | it != gui_data.gui_node_map_names.end(); ++it) |
---|
58 | { |
---|
59 | MapValue::Type type = gui_data.node_map_types[*it]; |
---|
60 | switch (type) |
---|
61 | { |
---|
62 | case MapValue::NUMERIC: |
---|
63 | { |
---|
64 | map<int, double>* p_map_data = |
---|
65 | new map<int, double>; |
---|
66 | gui_data.numeric_node_maps[*it] = p_map_data; |
---|
67 | { x(*it, *p_map_data); } |
---|
68 | } |
---|
69 | break; |
---|
70 | case MapValue::STRING: |
---|
71 | { |
---|
72 | map<int, string>* p_map_data = |
---|
73 | new map<int, string>; |
---|
74 | gui_data.string_node_maps[*it] = p_map_data; |
---|
75 | { x(*it, *p_map_data); } |
---|
76 | } |
---|
77 | break; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | for (vector<string>::const_iterator it = gui_data.gui_edge_map_names.begin(); |
---|
82 | it != gui_data.gui_edge_map_names.end(); ++it) |
---|
83 | { |
---|
84 | MapValue::Type type = gui_data.edge_map_types[*it]; |
---|
85 | switch (type) |
---|
86 | { |
---|
87 | case MapValue::NUMERIC: |
---|
88 | { |
---|
89 | map<int, double>* p_map_data = |
---|
90 | new map<int, double>; |
---|
91 | gui_data.numeric_edge_maps[*it] = p_map_data; |
---|
92 | { x(*it, *p_map_data); } |
---|
93 | } |
---|
94 | break; |
---|
95 | case MapValue::STRING: |
---|
96 | { |
---|
97 | map<int, string>* p_map_data = |
---|
98 | new map<int, string>; |
---|
99 | gui_data.string_edge_maps[*it] = p_map_data; |
---|
100 | { x(*it, *p_map_data); } |
---|
101 | } |
---|
102 | break; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | { |
---|
107 | std::string node_coords_save_dest; |
---|
108 | { x("node_coords_save_dest", node_coords_save_dest); } |
---|
109 | if (node_coords_save_dest == "gui_sect") |
---|
110 | { |
---|
111 | // read the node coorinates |
---|
112 | gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT; |
---|
113 | { x("node_coord_map", gui_data.node_coord_map); } |
---|
114 | } |
---|
115 | else if (node_coords_save_dest == "nodeset_sect_1_map") |
---|
116 | { |
---|
117 | gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; |
---|
118 | gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP; |
---|
119 | { x("map_name", gui_data.node_coords_one_map_name); } |
---|
120 | } |
---|
121 | else if (node_coords_save_dest == "nodeset_sect_2_maps") |
---|
122 | { |
---|
123 | gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; |
---|
124 | gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS; |
---|
125 | { x("map1_name", gui_data.node_coords_two_maps_1_name); } |
---|
126 | { x("map2_name", gui_data.node_coords_two_maps_2_name); } |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | { |
---|
131 | std::string arrow_coords_save_dest; |
---|
132 | { x("arrow_coords_save_dest", arrow_coords_save_dest); } |
---|
133 | if (arrow_coords_save_dest == "gui_sect") |
---|
134 | { |
---|
135 | // read the arrow coorinates |
---|
136 | gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT; |
---|
137 | { x("arrow_coord_map", gui_data.arrow_coord_map); } |
---|
138 | } |
---|
139 | else if (arrow_coords_save_dest == "edgeset_sect_1_map") |
---|
140 | { |
---|
141 | gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; |
---|
142 | gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP; |
---|
143 | { x("map_name", gui_data.arrow_coords_one_map_name); } |
---|
144 | } |
---|
145 | else if (arrow_coords_save_dest == "edgeset_sect_2_maps") |
---|
146 | { |
---|
147 | gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; |
---|
148 | gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS; |
---|
149 | { x("map1_name", gui_data.arrow_coords_two_maps_1_name); } |
---|
150 | { x("map2_name", gui_data.arrow_coords_two_maps_2_name); } |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | std::map<int, std::string> nm; |
---|
157 | x("active_nodemaps", nm); |
---|
158 | |
---|
159 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
160 | { |
---|
161 | mapstorage->changeActiveMap(false, i, nm[i]); |
---|
162 | } |
---|
163 | |
---|
164 | std::map<int, std::string> em; |
---|
165 | x("active_edgemaps", em); |
---|
166 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
167 | { |
---|
168 | mapstorage->changeActiveMap(true, i, em[i]); |
---|
169 | } |
---|
170 | |
---|
171 | double attraction; |
---|
172 | double propulsation; |
---|
173 | int iteration; |
---|
174 | |
---|
175 | x("redesign-attraction", attraction); |
---|
176 | x("redesign-propulsation", propulsation); |
---|
177 | x("redesign-iteration", iteration); |
---|
178 | |
---|
179 | mapstorage->set_attraction(attraction); |
---|
180 | mapstorage->set_propulsation(propulsation); |
---|
181 | mapstorage->set_iteration(iteration); |
---|
182 | |
---|
183 | mapstorage->redesign_data_changed(); |
---|
184 | } |
---|
185 | |
---|
186 | GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage, |
---|
187 | MapStorage::GUISectData& _gui_data) : |
---|
188 | Parent(reader), |
---|
189 | mapstorage(_mapstorage), |
---|
190 | gui_data(_gui_data) |
---|
191 | { |
---|
192 | } |
---|