Notebook style is provided. Without opportunity to close tabs. :-) But with all other necessary things (I think).
1 #include "mapstorage.h"
7 MapStorage::MapStorage() : modified(false), file_name("")
9 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
10 coords.setXMap(*nodemap_storage["coordinates_x"]);
11 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
12 coords.setYMap(*nodemap_storage["coordinates_y"]);
14 nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
15 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
17 nodemap_default["id"] = 1.0;
18 edgemap_default["id"] = 1.0;
20 active_nodemaps.resize(NODE_PROPERTY_NUM);
21 for(int i=0;i<NODE_PROPERTY_NUM;i++)
23 active_nodemaps[i]="";
26 active_edgemaps.resize(EDGE_PROPERTY_NUM);
27 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
29 active_edgemaps[i]="";
33 MapStorage::~MapStorage()
35 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
36 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
40 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
41 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
47 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0)
49 if( nodemap_storage.find(name) == nodemap_storage.end() )
51 nodemap_storage[name]=nodemap;
52 // set the maps default value
53 nodemap_default[name] = default_value;
59 void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname)
63 active_edgemaps[prop]=mapname;
67 active_nodemaps[prop]=mapname;
69 signal_prop.emit(itisedge, prop);
72 std::string MapStorage::getActiveEdgeMap(int prop)
74 return active_edgemaps[prop];
77 std::string MapStorage::getActiveNodeMap(int prop)
79 return active_nodemaps[prop];
82 std::vector<std::string> MapStorage::getEdgeMapList()
84 std::vector<std::string> eml;
85 eml.resize(edgemap_storage.size());
87 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
88 for(;emsi!=endOfEdgeMaps();emsi++)
96 std::vector<std::string> MapStorage::getNodeMapList()
98 std::vector<std::string> nml;
99 nml.resize(nodemap_storage.size());
101 std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
102 for(;nmsi!=endOfNodeMaps();nmsi++)
104 nml[i]=(nmsi->first);
110 MapStorage::Signal_Prop MapStorage::signal_prop_ch()
115 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)
117 if( edgemap_storage.find(name) == edgemap_storage.end() )
119 edgemap_storage[name]=edgemap;
120 // set the maps default value
121 edgemap_default[name] = default_value;
127 double MapStorage::maxOfNodeMap(const std::string & name)
130 for (NodeIt j(graph); j!=INVALID; ++j)
132 if( (*nodemap_storage[name])[j]>max )
134 max=(*nodemap_storage[name])[j];
140 double MapStorage::maxOfEdgeMap(const std::string & name)
143 for (EdgeIt j(graph); j!=INVALID; ++j)
145 if( (*edgemap_storage[name])[j]>max )
147 max=(*edgemap_storage[name])[j];
153 double MapStorage::minOfNodeMap(const std::string & name)
159 min=(*nodemap_storage[name])[j];
165 for (; j!=INVALID; ++j)
167 if( (*nodemap_storage[name])[j]<min )
169 min=(*nodemap_storage[name])[j];
175 double MapStorage::minOfEdgeMap(const std::string & name)
181 min=(*edgemap_storage[name])[j];
187 for (EdgeIt j(graph); j!=INVALID; ++j)
189 if( (*edgemap_storage[name])[j]<min )
191 min=(*edgemap_storage[name])[j];
197 int MapStorage::readFromFile(const std::string &filename)
201 bool read_edge_id = false;
204 LemonReader lreader(filename);
205 ContentReader content(lreader);
208 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
209 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
211 GraphReader<Graph> greader(filename, graph);
212 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
213 it != nodeMapNames.end(); ++it)
215 if (*it == "coordinates_x")
218 //std::cout << "read X nodemap" << std::endl;
220 else if (*it == "coordinates_y")
223 //std::cout << "read Y nodemap" << std::endl;
225 else if (*it == "id")
227 //std::cout << "read id nodemap" << std::endl;
231 nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
232 //std::cout << "read " << *it << " nodemap" << std::endl;
234 greader.readNodeMap(*it, *nodemap_storage[*it]);
236 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
237 it != edgeMapNames.end(); ++it)
241 //std::cout << "read id edgemap" << std::endl;
245 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
246 //std::cout << "read " << *it << " edgemap" << std::endl;
248 greader.readEdgeMap(*it, *edgemap_storage[*it]);
251 } catch (DataFormatError& error) {
252 Gtk::MessageDialog mdialog(error.what());
260 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
262 for (EdgeIt e(graph); e != INVALID; ++e)
264 (*edgemap_storage["id"])[e] = i++;
268 if (!read_x || !read_y)
271 for (NodeIt n(graph); n != INVALID; ++n)
275 const double pi = 3.142;
276 double step = 2 * pi / (double) node_num;
278 for (NodeIt n(graph); n != INVALID; ++n)
280 nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
281 nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
286 // fill in the default values for the maps
287 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
288 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
290 if ((it->first != "id") &&
291 (it->first != "coordiantes_x") &&
292 (it->first != "coordinates_y"))
294 nodemap_default[it->first] = 0.0;
296 else if (it->first == "id")
299 double max = (*nodemap_storage["id"])[n];
300 for (; n != INVALID; ++n)
302 if ((*nodemap_storage["id"])[n] > max)
303 max = (*nodemap_storage["id"])[n];
305 nodemap_default["id"] = max + 1.0;
308 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
309 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
311 if (it->first != "id")
313 edgemap_default[it->first] = 0.0;
317 double max = std::numeric_limits<double>::min();
318 for (EdgeIt e(graph); e != INVALID; ++e)
320 if ((*edgemap_storage["id"])[e] > max)
321 max = (*edgemap_storage["id"])[e];
323 if (max > std::numeric_limits<double>::min())
324 edgemap_default["id"] = max + 1.0;
326 edgemap_default["id"] = 1.0;
333 void MapStorage::writeToFile(const std::string &filename)
335 GraphWriter<Graph> gwriter(filename, graph);
337 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
338 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
340 gwriter.writeNodeMap(it->first, *(it->second));
341 //std::cout << "wrote " << it->first << " nodemap" << std::endl;
343 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
344 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
346 gwriter.writeEdgeMap(it->first, *(it->second));
347 //std::cout << "wrote " << it->first << " edgemap" << std::endl;
352 void MapStorage::clear()
354 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
355 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
357 if ((it->first != "coordinates_x") &&
358 (it->first != "coordinates_y") &&
362 nodemap_storage.erase(it);
365 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
366 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
368 if (it->first != "id")
371 edgemap_storage.erase(it);
374 for (std::map<std::string, double>::iterator it =
375 nodemap_default.begin(); it != nodemap_default.end(); ++it)
377 if (it->first != "id")
378 nodemap_default.erase(it);
380 for (std::map<std::string, double>::iterator it =
381 edgemap_default.begin(); it != edgemap_default.end(); ++it)
383 if (it->first != "id")
384 edgemap_default.erase(it);