- The number of gcc-4.0 warnings has significantly decreases.
- Some code clean-up in gui
1 #include "mapstorage.h"
4 MapStorage::MapStorage() : modified(false), file_name("")
6 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
7 coords.setXMap(*nodemap_storage["coordinates_x"]);
8 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
9 coords.setYMap(*nodemap_storage["coordinates_y"]);
11 nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
12 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
15 MapStorage::~MapStorage()
17 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
18 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
22 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
23 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
29 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
31 if( nodemap_storage.find(name) == nodemap_storage.end() )
33 nodemap_storage[name]=nodemap;
39 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
41 if( edgemap_storage.find(name) == edgemap_storage.end() )
43 edgemap_storage[name]=edgemap;
49 double MapStorage::maxOfNodeMap(const std::string & name)
52 for (NodeIt j(graph); j!=INVALID; ++j)
54 if( (*nodemap_storage[name])[j]>max )
56 max=(*nodemap_storage[name])[j];
62 double MapStorage::maxOfEdgeMap(const std::string & name)
65 for (EdgeIt j(graph); j!=INVALID; ++j)
67 if( (*edgemap_storage[name])[j]>max )
69 max=(*edgemap_storage[name])[j];
75 double MapStorage::minOfNodeMap(const std::string & name)
81 min=(*nodemap_storage[name])[j];
87 for (; j!=INVALID; ++j)
89 if( (*nodemap_storage[name])[j]<min )
91 min=(*nodemap_storage[name])[j];
97 double MapStorage::minOfEdgeMap(const std::string & name)
103 min=(*edgemap_storage[name])[j];
109 for (EdgeIt j(graph); j!=INVALID; ++j)
111 if( (*edgemap_storage[name])[j]<min )
113 min=(*edgemap_storage[name])[j];
119 void MapStorage::initMapsForEdge(Edge e)
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++)
124 (*((*ems_it).second))[e]=5;
128 void MapStorage::readFromFile(const std::string &filename)
134 LemonReader lreader(filename);
135 ContentReader content(lreader);
138 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
139 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
141 GraphReader<Graph> greader(filename, graph);
142 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
143 it != nodeMapNames.end(); ++it)
145 if (*it == "coordinates_x")
148 //std::cout << "read X nodemap" << std::endl;
150 else if (*it == "coordinates_y")
153 //std::cout << "read Y nodemap" << std::endl;
155 else if (*it == "id")
157 //std::cout << "read id nodemap" << std::endl;
161 nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
162 //std::cout << "read " << *it << " nodemap" << std::endl;
164 greader.readNodeMap(*it, *nodemap_storage[*it]);
166 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
167 it != edgeMapNames.end(); ++it)
171 //std::cout << "read id edgemap" << std::endl;
175 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
176 //std::cout << "read " << *it << " edgemap" << std::endl;
178 greader.readEdgeMap(*it, *edgemap_storage[*it]);
181 } catch (DataFormatError& error) {
183 Gtk::MessageDialog mdialog("Read Error");
184 mdialog.set_message(error.what());
187 // reset graph and mapstorage ?
191 if (!read_x || !read_y)
194 for (NodeIt n(graph); n != INVALID; ++n)
198 const double pi = 3.142;
199 double step = 2 * pi / (double) node_num;
201 for (NodeIt n(graph); n != INVALID; ++n)
203 nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step));
204 nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step));
210 void MapStorage::writeToFile(const std::string &filename)
212 GraphWriter<Graph> gwriter(filename, graph);
214 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
215 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
217 gwriter.writeNodeMap(it->first, *(it->second));
218 //std::cout << "wrote " << it->first << " nodemap" << std::endl;
220 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
221 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
223 gwriter.writeEdgeMap(it->first, *(it->second));
224 //std::cout << "wrote " << it->first << " edgemap" << std::endl;
229 void MapStorage::clear()
231 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
232 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
234 if ((it->first != "coordinates_x") &&
235 (it->first != "coordinates_y") &&
239 nodemap_storage.erase(it);
242 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
243 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
245 if (it->first != "id")
248 edgemap_storage.erase(it);