MALE and FEMALE node shape added.
1 #include "mapstorage.h"
2 #include "gui_writer.h"
3 #include "gui_reader.h"
9 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
11 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
12 coords.setXMap(*nodemap_storage["coordinates_x"]);
13 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
14 coords.setYMap(*nodemap_storage["coordinates_y"]);
16 edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
17 arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
18 edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
19 arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
21 nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
22 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
24 nodemap_default["id"] = 1.0;
25 edgemap_default["id"] = 1.0;
27 active_nodemaps.resize(NODE_PROPERTY_NUM);
28 for(int i=0;i<NODE_PROPERTY_NUM;i++)
30 active_nodemaps[i]="";
33 active_edgemaps.resize(EDGE_PROPERTY_NUM);
34 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
36 active_edgemaps[i]="";
40 MapStorage::~MapStorage()
42 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
43 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
47 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
48 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
54 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
56 std::cout << default_value << std::endl;
57 if( nodemap_storage.find(name) == nodemap_storage.end() )
59 nodemap_storage[name]=nodemap;
60 // set the maps default value
61 nodemap_default[name] = default_value;
63 //announce changement in maps
64 signal_node_map.emit(name);
70 void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname)
74 active_edgemaps[prop]=mapname;
78 active_nodemaps[prop]=mapname;
80 signal_prop.emit(itisedge, prop);
83 std::string MapStorage::getActiveEdgeMap(int prop)
85 return active_edgemaps[prop];
88 std::string MapStorage::getActiveNodeMap(int prop)
90 return active_nodemaps[prop];
93 std::vector<std::string> MapStorage::getEdgeMapList()
95 std::vector<std::string> eml;
96 eml.resize(edgemap_storage.size());
98 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
99 for(;emsi!=endOfEdgeMaps();emsi++)
101 eml[i]=(emsi->first);
107 std::vector<std::string> MapStorage::getNodeMapList()
109 std::vector<std::string> nml;
110 nml.resize(nodemap_storage.size());
112 std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
113 for(;nmsi!=endOfNodeMaps();nmsi++)
115 nml[i]=(nmsi->first);
121 MapStorage::Signal_Prop MapStorage::signal_prop_ch()
126 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
128 if( edgemap_storage.find(name) == edgemap_storage.end() )
130 edgemap_storage[name]=edgemap;
131 // set the maps default value
132 edgemap_default[name] = default_value;
134 //announce changement in maps
135 signal_edge_map.emit(name);
141 double MapStorage::maxOfNodeMap(const std::string & name)
144 for (NodeIt j(graph); j!=INVALID; ++j)
146 if( (*nodemap_storage[name])[j]>max )
148 max=(*nodemap_storage[name])[j];
154 double MapStorage::maxOfEdgeMap(const std::string & name)
157 for (EdgeIt j(graph); j!=INVALID; ++j)
159 if( (*edgemap_storage[name])[j]>max )
161 max=(*edgemap_storage[name])[j];
167 double MapStorage::minOfNodeMap(const std::string & name)
173 min=(*nodemap_storage[name])[j];
179 for (; j!=INVALID; ++j)
181 if( (*nodemap_storage[name])[j]<min )
183 min=(*nodemap_storage[name])[j];
189 double MapStorage::minOfEdgeMap(const std::string & name)
195 min=(*edgemap_storage[name])[j];
201 for (EdgeIt j(graph); j!=INVALID; ++j)
203 if( (*edgemap_storage[name])[j]<min )
205 min=(*edgemap_storage[name])[j];
211 int MapStorage::readFromFile(const std::string &filename)
215 bool read_edge_id = false;
218 LemonReader lreader(filename);
219 ContentReader content(lreader);
222 if (content.nodeSetNum() < 1)
224 Gtk::MessageDialog mdialog("No nodeset found in file.");
230 if (content.edgeSetNum() < 1)
232 Gtk::MessageDialog mdialog("No edgeset found in file.");
238 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
239 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
241 GraphReader<Graph> greader(filename, graph);
242 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
243 it != nodeMapNames.end(); ++it)
245 if (*it == "coordinates_x")
248 //std::cout << "read X nodemap" << std::endl;
250 else if (*it == "coordinates_y")
253 //std::cout << "read Y nodemap" << std::endl;
255 else if (*it == "id")
257 //std::cout << "read id nodemap" << std::endl;
261 nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
262 //std::cout << "read " << *it << " nodemap" << std::endl;
264 greader.readNodeMap(*it, *nodemap_storage[*it]);
266 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
267 it != edgeMapNames.end(); ++it)
271 //std::cout << "read id edgemap" << std::endl;
275 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
276 //std::cout << "read " << *it << " edgemap" << std::endl;
278 greader.readEdgeMap(*it, *edgemap_storage[*it]);
280 GuiReader gui_reader(greader, this);
282 } catch (Exception& error) {
283 Gtk::MessageDialog mdialog(error.what());
291 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
293 for (EdgeIt e(graph); e != INVALID; ++e)
295 (*edgemap_storage["id"])[e] = i++;
299 if (!read_x || !read_y)
302 for (NodeIt n(graph); n != INVALID; ++n)
306 const double pi = 3.142;
307 double step = 2 * pi / (double) node_num;
309 for (NodeIt n(graph); n != INVALID; ++n)
311 nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
312 nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
317 if (!arrow_pos_read_ok)
319 arrow_pos_read_ok = false;
320 for (EdgeIt e(graph); e != INVALID; ++e)
322 arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
326 // fill in the default values for the maps
327 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
328 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
330 if ((it->first != "id") &&
331 (it->first != "coordiantes_x") &&
332 (it->first != "coordinates_y"))
334 nodemap_default[it->first] = 0.0;
336 else if (it->first == "id")
339 double max = (*nodemap_storage["id"])[n];
340 for (; n != INVALID; ++n)
342 if ((*nodemap_storage["id"])[n] > max)
343 max = (*nodemap_storage["id"])[n];
345 nodemap_default["id"] = max + 1.0;
348 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
349 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
351 if (it->first != "id")
353 edgemap_default[it->first] = 0.0;
357 double max = std::numeric_limits<double>::min();
358 for (EdgeIt e(graph); e != INVALID; ++e)
360 if ((*edgemap_storage["id"])[e] > max)
361 max = (*edgemap_storage["id"])[e];
363 if (max > std::numeric_limits<double>::min())
364 edgemap_default["id"] = max + 1.0;
366 edgemap_default["id"] = 1.0;
373 void MapStorage::writeToFile(const std::string &filename)
375 GraphWriter<Graph> gwriter(filename, graph);
377 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
378 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
380 gwriter.writeNodeMap(it->first, *(it->second));
382 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
383 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
385 if ((it->first != "arrow_pos_x") &&
386 (it->first != "arrow_pos_y"))
388 gwriter.writeEdgeMap(it->first, *(it->second));
392 GuiWriter gui_writer(gwriter, this);
397 void MapStorage::clear()
399 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
400 nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
402 if ((it->first != "coordinates_x") &&
403 (it->first != "coordinates_y") &&
407 nodemap_storage.erase(it);
410 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
411 edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
413 if ((it->first != "id") &&
414 (it->first != "arrow_pos_x") &&
415 (it->first != "arrow_pos_y"))
418 edgemap_storage.erase(it);
421 for (std::map<std::string, double>::iterator it =
422 nodemap_default.begin(); it != nodemap_default.end(); ++it)
424 if (it->first != "id")
425 nodemap_default.erase(it);
427 for (std::map<std::string, double>::iterator it =
428 edgemap_default.begin(); it != edgemap_default.end(); ++it)
430 if (it->first != "id")
431 edgemap_default.erase(it);
438 void MapStorage::ArrowPosReadOK()
440 arrow_pos_read_ok = true;
443 void MapStorage::mapChanged(bool itisedge, std::string mapname)
447 for(int i=0;i<EDGE_PROPERTY_NUM;i++)
449 if(active_edgemaps[i]==mapname)
451 signal_prop.emit(itisedge, i);
457 for(int i=0;i<NODE_PROPERTY_NUM;i++)
459 if(active_nodemaps[i]==mapname)
461 signal_prop.emit(itisedge, i);