diff -r 4fa618f7aa69 -r dc4ea2010dee gui/mapstorage.cc --- a/gui/mapstorage.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/mapstorage.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,8 +1,29 @@ -#include +#include "mapstorage.h" -MapStorage::MapStorage(Graph & graph):g(graph) +MapStorage::MapStorage() : modified(false), file_name("") { -}; + 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"]); + + nodemap_storage["id"] = new Graph::NodeMap(graph); + edgemap_storage["id"] = new Graph::EdgeMap(graph); +} + +MapStorage::~MapStorage() +{ + for (std::map*>::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) { @@ -27,7 +48,7 @@ double MapStorage::maxOfNodeMap(const std::string & name) { double max=0; - for (NodeIt j(g); j!=INVALID; ++j) + for (NodeIt j(graph); j!=INVALID; ++j) { if( (*nodemap_storage[name])[j]>max ) { @@ -40,7 +61,7 @@ double MapStorage::maxOfEdgeMap(const std::string & name) { double max=0; - for (EdgeIt j(g); j!=INVALID; ++j) + for (EdgeIt j(graph); j!=INVALID; ++j) { if( (*edgemap_storage[name])[j]>max ) { @@ -52,7 +73,7 @@ double MapStorage::minOfNodeMap(const std::string & name) { - NodeIt j(g); + NodeIt j(graph); double min=(*nodemap_storage[name])[j]; for (; j!=INVALID; ++j) { @@ -66,9 +87,9 @@ double MapStorage::minOfEdgeMap(const std::string & name) { - EdgeIt j(g); + EdgeIt j(graph); double min=(*edgemap_storage[name])[j]; - for (EdgeIt j(g); j!=INVALID; ++j) + for (EdgeIt j(graph); j!=INVALID; ++j) { if( (*edgemap_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]); + } + greader.run(); + } catch (DataFormatError& error) { + /* + Gtk::MessageDialog mdialog("Read Error"); + mdialog.set_message(error.what()); + mdialog.run(); + */ + // reset graph and mapstorage ? + return; + } + + 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 * cos(i * step)); + nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step)); + i++; + } + } +} + +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)); + //std::cout << "wrote " << it->first << " nodemap" << std::endl; + } + for (std::map*>::const_iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + gwriter.writeEdgeMap(it->first, *(it->second)); + //std::cout << "wrote " << it->first << " edgemap" << std::endl; + } + 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") + { + delete it->second; + edgemap_storage.erase(it); + } + } + graph.clear(); + file_name = ""; + modified = false; +}