# HG changeset patch # User ladanyi # Date 1124812632 0 # Node ID 2dd083dded66febd94811ba05e28734de479b206 # Parent 4a04bb856ac704a0fc665c9c8738a410d2a7945e - handle the case when there is no id map in the edgeset section - do not use ListGraph.id() to determine the id of a new node/edge diff -r 4a04bb856ac7 -r 2dd083dded66 gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Tue Aug 23 07:36:09 2005 +0000 +++ b/gui/graph_displayer_canvas-event.cc Tue Aug 23 15:57:12 2005 +0000 @@ -240,23 +240,20 @@ // update coordinates mapstorage.coords.set(active_node, xy(clicked_x, clicked_y)); - // update id map - (*mapstorage.nodemap_storage["id"])[active_node] = - mapstorage.graph.id(active_node); - // update all other maps for (std::map*>::const_iterator it = mapstorage.nodemap_storage.begin(); it != mapstorage.nodemap_storage.end(); ++it) { - if ((it->first != "id") && - (it->first != "coordinates_x") && - (it->first != "coordiantes_y")) + if ((it->first != "coordinates_x") && + (it->first != "coordinates_y")) { (*(it->second))[active_node] = mapstorage.nodemap_default[it->first]; } } + // increment the id map's default value + mapstorage.nodemap_default["id"] += 1.0; nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); @@ -356,22 +353,17 @@ active_edge=mapstorage.graph.addEdge(active_node, target_node); - // update id map - (*mapstorage.edgemap_storage["id"])[active_edge] = - mapstorage.graph.id(active_edge); - - // update all other maps + // update maps for (std::map*>::const_iterator it = mapstorage.edgemap_storage.begin(); it != mapstorage.edgemap_storage.end(); ++it) { - if (it->first != "id") - { - (*(it->second))[active_edge] = - mapstorage.edgemap_default[it->first]; - } + (*(it->second))[active_edge] = + mapstorage.edgemap_default[it->first]; } + // increment the id map's default value + mapstorage.edgemap_default["id"] += 1.0; //calculating coordinates of new edge Gnome::Canvas::Points coos; diff -r 4a04bb856ac7 -r 2dd083dded66 gui/mapstorage.cc --- a/gui/mapstorage.cc Tue Aug 23 07:36:09 2005 +0000 +++ b/gui/mapstorage.cc Tue Aug 23 15:57:12 2005 +0000 @@ -11,6 +11,9 @@ nodemap_storage["id"] = new Graph::NodeMap(graph); edgemap_storage["id"] = new Graph::EdgeMap(graph); + + nodemap_default["id"] = 1.0; + edgemap_default["id"] = 1.0; } MapStorage::~MapStorage() @@ -125,6 +128,7 @@ { bool read_x = false; bool read_y = false; + bool read_edge_id = false; try { LemonReader lreader(filename); @@ -182,6 +186,16 @@ return 1; } + if (!read_edge_id) + { + edgemap_storage["id"] = new Graph::EdgeMap(graph); + int i = 1; + for (EdgeIt e(graph); e != INVALID; ++e) + { + (*edgemap_storage["id"])[e] = i++; + } + } + if (!read_x || !read_y) { int node_num = 0; @@ -210,6 +224,17 @@ { nodemap_default[it->first] = 0.0; } + else if (it->first == "id") + { + NodeIt n(graph); + double max = (*nodemap_storage["id"])[n]; + for (; n != INVALID; ++n) + { + if ((*nodemap_storage["id"])[n] > max) + max = (*nodemap_storage["id"])[n]; + } + nodemap_default["id"] = max + 1.0; + } } for (std::map*>::const_iterator it = edgemap_storage.begin(); it != edgemap_storage.end(); ++it) @@ -218,6 +243,17 @@ { edgemap_default[it->first] = 0.0; } + else + { + EdgeIt e(graph); + double max = (*edgemap_storage["id"])[e]; + for (; e != INVALID; ++e) + { + if ((*edgemap_storage["id"])[e] > max) + max = (*edgemap_storage["id"])[e]; + } + edgemap_default["id"] = max + 1.0; + } } return 0; @@ -267,12 +303,14 @@ for (std::map::iterator it = nodemap_default.begin(); it != nodemap_default.end(); ++it) { - nodemap_default.erase(it); + if (it->first != "id") + nodemap_default.erase(it); } for (std::map::iterator it = edgemap_default.begin(); it != edgemap_default.end(); ++it) { - edgemap_default.erase(it); + if (it->first != "id") + edgemap_default.erase(it); } graph.clear(); file_name = "";