mapstorage.cc
branchgui
changeset 63 59768817442a
parent 62 80eefca04b1e
child 64 7a32d528857f
     1.1 --- a/mapstorage.cc	Thu Aug 18 13:33:49 2005 +0000
     1.2 +++ b/mapstorage.cc	Tue Aug 23 07:36:09 2005 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  #include "mapstorage.h"
     1.5 +#include <gtkmm.h>
     1.6  #include <cmath>
     1.7  
     1.8  MapStorage::MapStorage() : modified(false), file_name("")
     1.9 @@ -26,21 +27,25 @@
    1.10    }
    1.11  }
    1.12  
    1.13 -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
    1.14 +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0)
    1.15  {
    1.16    if( nodemap_storage.find(name) == nodemap_storage.end() )
    1.17      {
    1.18        nodemap_storage[name]=nodemap;
    1.19 +      // set the maps default value
    1.20 +      nodemap_default[name] = default_value;
    1.21        return 0;
    1.22      }
    1.23    return 1;
    1.24  }
    1.25  
    1.26 -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
    1.27 +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)
    1.28  {
    1.29    if( edgemap_storage.find(name) == edgemap_storage.end() )
    1.30      {
    1.31        edgemap_storage[name]=edgemap;
    1.32 +      // set the maps default value
    1.33 +      edgemap_default[name] = default_value;
    1.34        return 0;
    1.35      }
    1.36    return 1;
    1.37 @@ -116,16 +121,7 @@
    1.38    return min;
    1.39  }
    1.40  
    1.41 -void MapStorage::initMapsForEdge(Edge e)
    1.42 -{
    1.43 -  std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it;
    1.44 -  for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++)
    1.45 -    {
    1.46 -      (*((*ems_it).second))[e]=5;
    1.47 -    }
    1.48 -}
    1.49 -
    1.50 -void MapStorage::readFromFile(const std::string &filename)
    1.51 +int MapStorage::readFromFile(const std::string &filename)
    1.52  {
    1.53    bool read_x = false;
    1.54    bool read_y = false;
    1.55 @@ -179,13 +175,11 @@
    1.56      }
    1.57      greader.run();
    1.58    } catch (DataFormatError& error) {
    1.59 -    /*
    1.60      Gtk::MessageDialog mdialog("Read Error");
    1.61      mdialog.set_message(error.what());
    1.62      mdialog.run();
    1.63 -    */
    1.64 -    // reset graph and mapstorage ?
    1.65 -    return;
    1.66 +    clear();
    1.67 +    return 1;
    1.68    }
    1.69  
    1.70    if (!read_x || !read_y)
    1.71 @@ -205,6 +199,28 @@
    1.72        i++;
    1.73      }
    1.74    }
    1.75 +
    1.76 +  // fill in the default values for the maps
    1.77 +  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    1.78 +      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    1.79 +  {
    1.80 +    if ((it->first != "id") &&
    1.81 +        (it->first != "coordiantes_x") &&
    1.82 +        (it->first != "coordinates_y"))
    1.83 +    {
    1.84 +      nodemap_default[it->first] = 0.0;
    1.85 +    }
    1.86 +  }
    1.87 +  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    1.88 +      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    1.89 +  {
    1.90 +    if (it->first != "id")
    1.91 +    {
    1.92 +      edgemap_default[it->first] = 0.0;
    1.93 +    }
    1.94 +  }
    1.95 +
    1.96 +  return 0;
    1.97  }
    1.98  
    1.99  void MapStorage::writeToFile(const std::string &filename)
   1.100 @@ -248,6 +264,16 @@
   1.101        edgemap_storage.erase(it);
   1.102      }
   1.103    }
   1.104 +  for (std::map<std::string, double>::iterator it =
   1.105 +      nodemap_default.begin(); it != nodemap_default.end(); ++it)
   1.106 +  {
   1.107 +    nodemap_default.erase(it);
   1.108 +  }
   1.109 +  for (std::map<std::string, double>::iterator it =
   1.110 +      edgemap_default.begin(); it != edgemap_default.end(); ++it)
   1.111 +  {
   1.112 +    edgemap_default.erase(it);
   1.113 +  }
   1.114    graph.clear();
   1.115    file_name = "";
   1.116    modified = false;