# HG changeset patch # User hegyi # Date 1122464113 0 # Node ID 121452cc40969812bbe3c06998741294fd77f976 # Parent 199f433eb7cd3a7390ec2a504dd1e95c690f27cc No maps with the same name can be added. diff -r 199f433eb7cd -r 121452cc4096 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Wed Jul 27 11:19:35 2005 +0000 +++ b/graph_displayer_canvas-event.cc Wed Jul 27 11:35:13 2005 +0000 @@ -854,29 +854,46 @@ } -void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) +int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) { //create the new map Graph::EdgeMap * emptr=new Graph::EdgeMap (g,default_value); - mapstorage.addEdgeMap(mapname,emptr); + + //if addition was not successful addEdgeMap returns one. + //cause can be that there is already a map named like the new one + if(mapstorage.addEdgeMap(mapname,emptr)) + { + return 1; + } + //add it to the list of the displayable maps mapwin->registerNewEdgeMap(mapname); //display it changeEdgeText(mapname); + + return 0; } -void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) +int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) { //create the new map Graph::NodeMap * emptr=new Graph::NodeMap (g,default_value); - mapstorage.addNodeMap(mapname,emptr); + + //if addition was not successful addNodeMap returns one. + //cause can be that there is already a map named like the new one + if(mapstorage.addNodeMap(mapname,emptr)) + { + return 1; + } //add it to the list of the displayable maps mapwin->registerNewNodeMap(mapname); //display it changeNodeText(mapname); + + return 0; } diff -r 199f433eb7cd -r 121452cc4096 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Wed Jul 27 11:19:35 2005 +0000 +++ b/graph_displayer_canvas.h Wed Jul 27 11:35:13 2005 +0000 @@ -110,9 +110,9 @@ int getActualTool(); ///creates a new Nodemap - void addNewNodeMap(double,std::string); + int addNewNodeMap(double,std::string); ///creates a new Edgemap - void addNewEdgeMap(double,std::string); + int addNewEdgeMap(double,std::string); private: ///Deletes the given element. diff -r 199f433eb7cd -r 121452cc4096 mapstorage.cc --- a/mapstorage.cc Wed Jul 27 11:19:35 2005 +0000 +++ b/mapstorage.cc Wed Jul 27 11:35:13 2005 +0000 @@ -6,14 +6,22 @@ int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap) { - nodemap_storage[name]=nodemap; - return 0; + if( nodemap_storage.find(name) == nodemap_storage.end() ) + { + nodemap_storage[name]=nodemap; + return 0; + } + return 1; } int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap) { - edgemap_storage[name]=edgemap; - return 0; + if( edgemap_storage.find(name) == edgemap_storage.end() ) + { + edgemap_storage[name]=edgemap; + return 0; + } + return 1; } double MapStorage::maxOfNodeMap(const std::string & name) diff -r 199f433eb7cd -r 121452cc4096 new_map_win.cc --- a/new_map_win.cc Wed Jul 27 11:19:35 2005 +0000 +++ b/new_map_win.cc Wed Jul 27 11:35:13 2005 +0000 @@ -89,17 +89,21 @@ if((point_num<=1)&&(valid_double)&&(!mapname.empty())) { + int abortion=0; if(edge.get_active()) { - gdc.addNewEdgeMap(def_val,mapname); + abortion=gdc.addNewEdgeMap(def_val,mapname); } else { - gdc.addNewNodeMap(def_val,mapname); + abortion=gdc.addNewNodeMap(def_val,mapname); } - name.set_text(""); - default_value.set_text("0"); - hide(); + if(!abortion) + { + name.set_text(""); + default_value.set_text("0"); + hide(); + } } }