COIN-OR::LEMON - Graph Library

Changeset 1645:4a04bb856ac7 in lemon-0.x for gui/mapstorage.cc


Ignore:
Timestamp:
08/23/05 09:36:09 (19 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2158
Message:
  • id maps are not editable
  • handle exceptions thrown by the file reader
  • texts are always above the edges
  • store a default value for all maps, so that edges and nodes created after adding a new map receive the default value too
  • create node on button release, not on click (fixes a few oddities)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/mapstorage.cc

    r1643 r1645  
    11#include "mapstorage.h"
     2#include <gtkmm.h>
    23#include <cmath>
    34
     
    2728}
    2829
    29 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
     30int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0)
    3031{
    3132  if( nodemap_storage.find(name) == nodemap_storage.end() )
    3233    {
    3334      nodemap_storage[name]=nodemap;
     35      // set the maps default value
     36      nodemap_default[name] = default_value;
    3437      return 0;
    3538    }
     
    3740}
    3841
    39 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
     42int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)
    4043{
    4144  if( edgemap_storage.find(name) == edgemap_storage.end() )
    4245    {
    4346      edgemap_storage[name]=edgemap;
     47      // set the maps default value
     48      edgemap_default[name] = default_value;
    4449      return 0;
    4550    }
     
    117122}
    118123
    119 void MapStorage::initMapsForEdge(Edge e)
    120 {
    121   std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it;
    122   for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++)
    123     {
    124       (*((*ems_it).second))[e]=5;
    125     }
    126 }
    127 
    128 void MapStorage::readFromFile(const std::string &filename)
     124int MapStorage::readFromFile(const std::string &filename)
    129125{
    130126  bool read_x = false;
     
    180176    greader.run();
    181177  } catch (DataFormatError& error) {
    182     /*
    183178    Gtk::MessageDialog mdialog("Read Error");
    184179    mdialog.set_message(error.what());
    185180    mdialog.run();
    186     */
    187     // reset graph and mapstorage ?
    188     return;
     181    clear();
     182    return 1;
    189183  }
    190184
     
    206200    }
    207201  }
     202
     203  // fill in the default values for the maps
     204  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
     205      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
     206  {
     207    if ((it->first != "id") &&
     208        (it->first != "coordiantes_x") &&
     209        (it->first != "coordinates_y"))
     210    {
     211      nodemap_default[it->first] = 0.0;
     212    }
     213  }
     214  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
     215      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
     216  {
     217    if (it->first != "id")
     218    {
     219      edgemap_default[it->first] = 0.0;
     220    }
     221  }
     222
     223  return 0;
    208224}
    209225
     
    249265    }
    250266  }
     267  for (std::map<std::string, double>::iterator it =
     268      nodemap_default.begin(); it != nodemap_default.end(); ++it)
     269  {
     270    nodemap_default.erase(it);
     271  }
     272  for (std::map<std::string, double>::iterator it =
     273      edgemap_default.begin(); it != edgemap_default.end(); ++it)
     274  {
     275    edgemap_default.erase(it);
     276  }
    251277  graph.clear();
    252278  file_name = "";
Note: See TracChangeset for help on using the changeset viewer.