No maps with the same name can be added.
authorhegyi
Wed, 27 Jul 2005 11:35:13 +0000
changeset 159715b51d278bf0
parent 1596 44897b1ba4e2
child 1598 739df601808d
No maps with the same name can be added.
gui/graph_displayer_canvas-event.cc
gui/graph_displayer_canvas.h
gui/mapstorage.cc
gui/new_map_win.cc
     1.1 --- a/gui/graph_displayer_canvas-event.cc	Wed Jul 27 11:19:35 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas-event.cc	Wed Jul 27 11:35:13 2005 +0000
     1.3 @@ -854,29 +854,46 @@
     1.4  
     1.5  }
     1.6  
     1.7 -void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
     1.8 +int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
     1.9  {
    1.10    //create the new map
    1.11    Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
    1.12 -  mapstorage.addEdgeMap(mapname,emptr);
    1.13 +
    1.14 +  //if addition was not successful addEdgeMap returns one.
    1.15 +  //cause can be that there is already a map named like the new one
    1.16 +  if(mapstorage.addEdgeMap(mapname,emptr))
    1.17 +    {
    1.18 +      return 1;
    1.19 +    }
    1.20 +
    1.21  
    1.22    //add it to the list of the displayable maps
    1.23    mapwin->registerNewEdgeMap(mapname);
    1.24  
    1.25    //display it
    1.26    changeEdgeText(mapname);
    1.27 +
    1.28 +  return 0;
    1.29  }
    1.30  
    1.31 -void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
    1.32 +int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
    1.33  {
    1.34    //create the new map
    1.35    Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
    1.36 -  mapstorage.addNodeMap(mapname,emptr);
    1.37 +
    1.38 +  //if addition was not successful addNodeMap returns one.
    1.39 +  //cause can be that there is already a map named like the new one
    1.40 +  if(mapstorage.addNodeMap(mapname,emptr))
    1.41 +    {
    1.42 +      return 1;
    1.43 +    }
    1.44  
    1.45    //add it to the list of the displayable maps
    1.46    mapwin->registerNewNodeMap(mapname);
    1.47  
    1.48    //display it
    1.49    changeNodeText(mapname);
    1.50 +
    1.51 +  return 0;
    1.52  }
    1.53  
     2.1 --- a/gui/graph_displayer_canvas.h	Wed Jul 27 11:19:35 2005 +0000
     2.2 +++ b/gui/graph_displayer_canvas.h	Wed Jul 27 11:35:13 2005 +0000
     2.3 @@ -110,9 +110,9 @@
     2.4    int getActualTool();
     2.5  
     2.6    ///creates a new Nodemap
     2.7 -  void addNewNodeMap(double,std::string);
     2.8 +  int addNewNodeMap(double,std::string);
     2.9    ///creates a new Edgemap
    2.10 -  void addNewEdgeMap(double,std::string);
    2.11 +  int addNewEdgeMap(double,std::string);
    2.12  
    2.13  private:
    2.14    ///Deletes the given element.
     3.1 --- a/gui/mapstorage.cc	Wed Jul 27 11:19:35 2005 +0000
     3.2 +++ b/gui/mapstorage.cc	Wed Jul 27 11:35:13 2005 +0000
     3.3 @@ -6,14 +6,22 @@
     3.4  
     3.5  int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
     3.6  {
     3.7 -  nodemap_storage[name]=nodemap;
     3.8 -  return 0;
     3.9 +  if( nodemap_storage.find(name) == nodemap_storage.end() )
    3.10 +    {
    3.11 +      nodemap_storage[name]=nodemap;
    3.12 +      return 0;
    3.13 +    }
    3.14 +  return 1;
    3.15  }
    3.16  
    3.17  int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
    3.18  {
    3.19 -  edgemap_storage[name]=edgemap;
    3.20 -  return 0;
    3.21 +  if( edgemap_storage.find(name) == edgemap_storage.end() )
    3.22 +    {
    3.23 +      edgemap_storage[name]=edgemap;
    3.24 +      return 0;
    3.25 +    }
    3.26 +  return 1;
    3.27  }
    3.28  
    3.29  double MapStorage::maxOfNodeMap(const std::string & name)
     4.1 --- a/gui/new_map_win.cc	Wed Jul 27 11:19:35 2005 +0000
     4.2 +++ b/gui/new_map_win.cc	Wed Jul 27 11:35:13 2005 +0000
     4.3 @@ -89,17 +89,21 @@
     4.4  
     4.5    if((point_num<=1)&&(valid_double)&&(!mapname.empty()))
     4.6      {
     4.7 +      int abortion=0;
     4.8        if(edge.get_active())
     4.9  	{
    4.10 -	  gdc.addNewEdgeMap(def_val,mapname);
    4.11 +	  abortion=gdc.addNewEdgeMap(def_val,mapname);
    4.12  	}
    4.13        else
    4.14  	{
    4.15 -	  gdc.addNewNodeMap(def_val,mapname);
    4.16 +	  abortion=gdc.addNewNodeMap(def_val,mapname);
    4.17  	}
    4.18 -      name.set_text("");
    4.19 -      default_value.set_text("0");
    4.20 -      hide();
    4.21 +      if(!abortion)
    4.22 +	{
    4.23 +	  name.set_text("");
    4.24 +	  default_value.set_text("0");
    4.25 +	  hide();
    4.26 +	}
    4.27      }
    4.28  }
    4.29