diff -r 62548b317e65 -r 4a04bb856ac7 gui/mapstorage.cc --- a/gui/mapstorage.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/mapstorage.cc Tue Aug 23 07:36:09 2005 +0000 @@ -1,4 +1,5 @@ #include "mapstorage.h" +#include #include MapStorage::MapStorage() : modified(false), file_name("") @@ -26,21 +27,25 @@ } } -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap) +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value = 0.0) { if( nodemap_storage.find(name) == nodemap_storage.end() ) { nodemap_storage[name]=nodemap; + // set the maps default value + nodemap_default[name] = default_value; return 0; } return 1; } -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap) +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value = 0.0) { if( edgemap_storage.find(name) == edgemap_storage.end() ) { edgemap_storage[name]=edgemap; + // set the maps default value + edgemap_default[name] = default_value; return 0; } return 1; @@ -116,16 +121,7 @@ return min; } -void MapStorage::initMapsForEdge(Edge e) -{ - std::map< std::string,Graph::EdgeMap * >::iterator ems_it; - for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++) - { - (*((*ems_it).second))[e]=5; - } -} - -void MapStorage::readFromFile(const std::string &filename) +int MapStorage::readFromFile(const std::string &filename) { bool read_x = false; bool read_y = false; @@ -179,13 +175,11 @@ } greader.run(); } catch (DataFormatError& error) { - /* Gtk::MessageDialog mdialog("Read Error"); mdialog.set_message(error.what()); mdialog.run(); - */ - // reset graph and mapstorage ? - return; + clear(); + return 1; } if (!read_x || !read_y) @@ -205,6 +199,28 @@ i++; } } + + // 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; + } + } + for (std::map*>::const_iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + if (it->first != "id") + { + edgemap_default[it->first] = 0.0; + } + } + + return 0; } void MapStorage::writeToFile(const std::string &filename) @@ -248,6 +264,16 @@ edgemap_storage.erase(it); } } + for (std::map::iterator it = + nodemap_default.begin(); it != nodemap_default.end(); ++it) + { + nodemap_default.erase(it); + } + for (std::map::iterator it = + edgemap_default.begin(); it != edgemap_default.end(); ++it) + { + edgemap_default.erase(it); + } graph.clear(); file_name = ""; modified = false;