#include "mapstorage.h" #include "gui_writer.h" #include "gui_reader.h" #include #include #include MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false) { nodemap_storage["coordinates_x"] = new Graph::NodeMap(graph); coords.setXMap(*nodemap_storage["coordinates_x"]); nodemap_storage["coordinates_y"] = new Graph::NodeMap(graph); coords.setYMap(*nodemap_storage["coordinates_y"]); edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap(graph); arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]); edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap(graph); arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]); nodemap_storage["id"] = new Graph::NodeMap(graph); edgemap_storage["id"] = new Graph::EdgeMap(graph); nodemap_default["id"] = 1.0; edgemap_default["id"] = 1.0; active_nodemaps.resize(NODE_PROPERTY_NUM); for(int i=0;i*>::const_iterator it = nodemap_storage.begin(); it != nodemap_storage.end(); ++it) { delete it->second; } for (std::map*>::const_iterator it = edgemap_storage.begin(); it != edgemap_storage.end(); ++it) { delete it->second; } } int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value) { std::cout << default_value << std::endl; if( nodemap_storage.find(name) == nodemap_storage.end() ) { nodemap_storage[name]=nodemap; // set the maps default value nodemap_default[name] = default_value; //announce changement in maps signal_node_map.emit(name); return 0; } return 1; } void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname) { if(itisedge) { active_edgemaps[prop]=mapname; } else { active_nodemaps[prop]=mapname; } signal_prop.emit(itisedge, prop); } std::string MapStorage::getActiveEdgeMap(int prop) { return active_edgemaps[prop]; } std::string MapStorage::getActiveNodeMap(int prop) { return active_nodemaps[prop]; } std::vector MapStorage::getEdgeMapList() { std::vector eml; eml.resize(edgemap_storage.size()); int i=0; std::map< std::string,Graph::EdgeMap * >::iterator emsi=beginOfEdgeMaps(); for(;emsi!=endOfEdgeMaps();emsi++) { eml[i]=(emsi->first); i++; } return eml; } std::vector MapStorage::getNodeMapList() { std::vector nml; nml.resize(nodemap_storage.size()); int i=0; std::map< std::string,Graph::NodeMap * >::iterator nmsi=beginOfNodeMaps(); for(;nmsi!=endOfNodeMaps();nmsi++) { nml[i]=(nmsi->first); i++; } return nml; } MapStorage::Signal_Prop MapStorage::signal_prop_ch() { return signal_prop; } int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value) { if( edgemap_storage.find(name) == edgemap_storage.end() ) { edgemap_storage[name]=edgemap; // set the maps default value edgemap_default[name] = default_value; //announce changement in maps signal_edge_map.emit(name); return 0; } return 1; } double MapStorage::maxOfNodeMap(const std::string & name) { double max=0; for (NodeIt j(graph); j!=INVALID; ++j) { if( (*nodemap_storage[name])[j]>max ) { max=(*nodemap_storage[name])[j]; } } return max; } double MapStorage::maxOfEdgeMap(const std::string & name) { double max=0; for (EdgeIt j(graph); j!=INVALID; ++j) { if( (*edgemap_storage[name])[j]>max ) { max=(*edgemap_storage[name])[j]; } } return max; } double MapStorage::minOfNodeMap(const std::string & name) { NodeIt j(graph); double min; if(j!=INVALID) { min=(*nodemap_storage[name])[j]; } else { min=0; } for (; j!=INVALID; ++j) { if( (*nodemap_storage[name])[j]& nodeMapNames = content.nodeSetMaps(0); const std::vector& edgeMapNames = content.edgeSetMaps(0); GraphReader greader(filename, graph); for (std::vector::const_iterator it = nodeMapNames.begin(); it != nodeMapNames.end(); ++it) { if (*it == "coordinates_x") { read_x = true; //std::cout << "read X nodemap" << std::endl; } else if (*it == "coordinates_y") { read_y = true; //std::cout << "read Y nodemap" << std::endl; } else if (*it == "id") { //std::cout << "read id nodemap" << std::endl; } else { nodemap_storage[*it] = new Graph::NodeMap(graph); //std::cout << "read " << *it << " nodemap" << std::endl; } greader.readNodeMap(*it, *nodemap_storage[*it]); } for (std::vector::const_iterator it = edgeMapNames.begin(); it != edgeMapNames.end(); ++it) { if (*it == "id") { //std::cout << "read id edgemap" << std::endl; } else { edgemap_storage[*it] = new Graph::EdgeMap(graph); //std::cout << "read " << *it << " edgemap" << std::endl; } greader.readEdgeMap(*it, *edgemap_storage[*it]); } GuiReader gui_reader(greader, this); greader.run(); } catch (Exception& error) { Gtk::MessageDialog mdialog(error.what()); mdialog.run(); clear(); return 1; } if (!read_edge_id) { edgemap_storage["id"] = new Graph::EdgeMap(graph); int i = 1; for (EdgeIt e(graph); e != INVALID; ++e) { (*edgemap_storage["id"])[e] = i++; } } if (!read_x || !read_y) { int node_num = 0; for (NodeIt n(graph); n != INVALID; ++n) { node_num++; } const double pi = 3.142; double step = 2 * pi / (double) node_num; int i = 0; for (NodeIt n(graph); n != INVALID; ++n) { nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step)); nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step)); i++; } } if (!arrow_pos_read_ok) { arrow_pos_read_ok = false; for (EdgeIt e(graph); e != INVALID; ++e) { arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); } } // fill in the default values for the maps for (std::map*>::const_iterator it = nodemap_storage.begin(); it != nodemap_storage.end(); ++it) { if ((it->first != "id") && (it->first != "coordiantes_x") && (it->first != "coordinates_y")) { nodemap_default[it->first] = 0.0; } else if (it->first == "id") { NodeIt n(graph); double max = (*nodemap_storage["id"])[n]; for (; n != INVALID; ++n) { if ((*nodemap_storage["id"])[n] > max) max = (*nodemap_storage["id"])[n]; } nodemap_default["id"] = max + 1.0; } } for (std::map*>::const_iterator it = edgemap_storage.begin(); it != edgemap_storage.end(); ++it) { if (it->first != "id") { edgemap_default[it->first] = 0.0; } else { double max = std::numeric_limits::min(); for (EdgeIt e(graph); e != INVALID; ++e) { if ((*edgemap_storage["id"])[e] > max) max = (*edgemap_storage["id"])[e]; } if (max > std::numeric_limits::min()) edgemap_default["id"] = max + 1.0; else edgemap_default["id"] = 1.0; } } return 0; } void MapStorage::writeToFile(const std::string &filename) { GraphWriter gwriter(filename, graph); for (std::map*>::const_iterator it = nodemap_storage.begin(); it != nodemap_storage.end(); ++it) { gwriter.writeNodeMap(it->first, *(it->second)); } for (std::map*>::const_iterator it = edgemap_storage.begin(); it != edgemap_storage.end(); ++it) { if ((it->first != "arrow_pos_x") && (it->first != "arrow_pos_y")) { gwriter.writeEdgeMap(it->first, *(it->second)); } } GuiWriter gui_writer(gwriter, this); gwriter.run(); } void MapStorage::clear() { for (std::map*>::iterator it = nodemap_storage.begin(); it != nodemap_storage.end(); ++it) { if ((it->first != "coordinates_x") && (it->first != "coordinates_y") && (it->first != "id")) { delete it->second; nodemap_storage.erase(it); } } for (std::map*>::iterator it = edgemap_storage.begin(); it != edgemap_storage.end(); ++it) { if ((it->first != "id") && (it->first != "arrow_pos_x") && (it->first != "arrow_pos_y")) { delete it->second; edgemap_storage.erase(it); } } for (std::map::iterator it = nodemap_default.begin(); it != nodemap_default.end(); ++it) { if (it->first != "id") nodemap_default.erase(it); } for (std::map::iterator it = edgemap_default.begin(); it != edgemap_default.end(); ++it) { if (it->first != "id") edgemap_default.erase(it); } graph.clear(); file_name = ""; modified = false; } void MapStorage::ArrowPosReadOK() { arrow_pos_read_ok = true; } void MapStorage::mapChanged(bool itisedge, std::string mapname) { if(itisedge) { for(int i=0;i