equal
deleted
inserted
replaced
1 #include "mapstorage.h" |
1 #include "mapstorage.h" |
|
2 #include <gtkmm.h> |
2 #include <cmath> |
3 #include <cmath> |
3 |
4 |
4 MapStorage::MapStorage() : modified(false), file_name("") |
5 MapStorage::MapStorage() : modified(false), file_name("") |
5 { |
6 { |
6 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph); |
7 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph); |
24 { |
25 { |
25 delete it->second; |
26 delete it->second; |
26 } |
27 } |
27 } |
28 } |
28 |
29 |
29 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap) |
30 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0) |
30 { |
31 { |
31 if( nodemap_storage.find(name) == nodemap_storage.end() ) |
32 if( nodemap_storage.find(name) == nodemap_storage.end() ) |
32 { |
33 { |
33 nodemap_storage[name]=nodemap; |
34 nodemap_storage[name]=nodemap; |
|
35 // set the maps default value |
|
36 nodemap_default[name] = default_value; |
34 return 0; |
37 return 0; |
35 } |
38 } |
36 return 1; |
39 return 1; |
37 } |
40 } |
38 |
41 |
39 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap) |
42 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0) |
40 { |
43 { |
41 if( edgemap_storage.find(name) == edgemap_storage.end() ) |
44 if( edgemap_storage.find(name) == edgemap_storage.end() ) |
42 { |
45 { |
43 edgemap_storage[name]=edgemap; |
46 edgemap_storage[name]=edgemap; |
|
47 // set the maps default value |
|
48 edgemap_default[name] = default_value; |
44 return 0; |
49 return 0; |
45 } |
50 } |
46 return 1; |
51 return 1; |
47 } |
52 } |
48 |
53 |
114 } |
119 } |
115 } |
120 } |
116 return min; |
121 return min; |
117 } |
122 } |
118 |
123 |
119 void MapStorage::initMapsForEdge(Edge e) |
124 int MapStorage::readFromFile(const std::string &filename) |
120 { |
|
121 std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it; |
|
122 for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++) |
|
123 { |
|
124 (*((*ems_it).second))[e]=5; |
|
125 } |
|
126 } |
|
127 |
|
128 void MapStorage::readFromFile(const std::string &filename) |
|
129 { |
125 { |
130 bool read_x = false; |
126 bool read_x = false; |
131 bool read_y = false; |
127 bool read_y = false; |
132 |
128 |
133 try { |
129 try { |
177 } |
173 } |
178 greader.readEdgeMap(*it, *edgemap_storage[*it]); |
174 greader.readEdgeMap(*it, *edgemap_storage[*it]); |
179 } |
175 } |
180 greader.run(); |
176 greader.run(); |
181 } catch (DataFormatError& error) { |
177 } catch (DataFormatError& error) { |
182 /* |
|
183 Gtk::MessageDialog mdialog("Read Error"); |
178 Gtk::MessageDialog mdialog("Read Error"); |
184 mdialog.set_message(error.what()); |
179 mdialog.set_message(error.what()); |
185 mdialog.run(); |
180 mdialog.run(); |
186 */ |
181 clear(); |
187 // reset graph and mapstorage ? |
182 return 1; |
188 return; |
|
189 } |
183 } |
190 |
184 |
191 if (!read_x || !read_y) |
185 if (!read_x || !read_y) |
192 { |
186 { |
193 int node_num = 0; |
187 int node_num = 0; |
203 nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step)); |
197 nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step)); |
204 nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step)); |
198 nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step)); |
205 i++; |
199 i++; |
206 } |
200 } |
207 } |
201 } |
|
202 |
|
203 // fill in the default values for the maps |
|
204 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
|
205 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) |
|
206 { |
|
207 if ((it->first != "id") && |
|
208 (it->first != "coordiantes_x") && |
|
209 (it->first != "coordinates_y")) |
|
210 { |
|
211 nodemap_default[it->first] = 0.0; |
|
212 } |
|
213 } |
|
214 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = |
|
215 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) |
|
216 { |
|
217 if (it->first != "id") |
|
218 { |
|
219 edgemap_default[it->first] = 0.0; |
|
220 } |
|
221 } |
|
222 |
|
223 return 0; |
208 } |
224 } |
209 |
225 |
210 void MapStorage::writeToFile(const std::string &filename) |
226 void MapStorage::writeToFile(const std::string &filename) |
211 { |
227 { |
212 GraphWriter<Graph> gwriter(filename, graph); |
228 GraphWriter<Graph> gwriter(filename, graph); |
246 { |
262 { |
247 delete it->second; |
263 delete it->second; |
248 edgemap_storage.erase(it); |
264 edgemap_storage.erase(it); |
249 } |
265 } |
250 } |
266 } |
|
267 for (std::map<std::string, double>::iterator it = |
|
268 nodemap_default.begin(); it != nodemap_default.end(); ++it) |
|
269 { |
|
270 nodemap_default.erase(it); |
|
271 } |
|
272 for (std::map<std::string, double>::iterator it = |
|
273 edgemap_default.begin(); it != edgemap_default.end(); ++it) |
|
274 { |
|
275 edgemap_default.erase(it); |
|
276 } |
251 graph.clear(); |
277 graph.clear(); |
252 file_name = ""; |
278 file_name = ""; |
253 modified = false; |
279 modified = false; |
254 } |
280 } |