At last, the most simple task, the graph-item deletion is solved...
authorhegyi
Wed, 15 Jun 2005 11:15:01 +0000
changeset 1496c60369a1c987
parent 1495 71676735a6ef
child 1497 529e48eb9786
At last, the most simple task, the graph-item deletion is solved...
gui/graph_displayer_canvas.cc
gui/graph_displayer_canvas.h
     1.1 --- a/gui/graph_displayer_canvas.cc	Wed Jun 15 11:01:55 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas.cc	Wed Jun 15 11:15:01 2005 +0000
     1.3 @@ -622,28 +622,31 @@
     1.4  	{
     1.5  	  if(active_node!=INVALID)
     1.6  	    {
     1.7 -//	      EdgeIt e;
     1.8 -// 	      g.firstOut(e,active_node);
     1.9 -// 	      for(;e!=INVALID;g.nextOut(e))
    1.10 -// 		{
    1.11 -// 		  if(e!=INVALID)delete_item(e);
    1.12 -// 		}
    1.13  
    1.14 -// 	      g.firstIn(e,active_node);
    1.15 -// 	      for(;e!=INVALID;g.nextIn(e))
    1.16 -// 		{
    1.17 -// 		  if(e!=INVALID)delete_item(e);
    1.18 -// 		}
    1.19 -	      for (EdgeIt i(g); i!=INVALID; ++i)
    1.20 +	      //collecting edges to delete
    1.21 +	      EdgeIt e;
    1.22 +	      std::set<Graph::Edge> edges_to_delete;
    1.23 +
    1.24 +	      g.firstOut(e,active_node);
    1.25 +	      for(;e!=INVALID;g.nextOut(e))
    1.26  		{
    1.27 -		  //std::cout << g.source(i).id << "-" << g.target(i).id << " " << active_node.id << std::endl;
    1.28 -		  if((g.source(i)==active_node)||(g.target(i)==active_node))
    1.29 -		    {
    1.30 -		      delete_item(i);
    1.31 -		    }
    1.32 +		      edges_to_delete.insert(e);
    1.33 +		}
    1.34 +
    1.35 +	      g.firstIn(e,active_node);
    1.36 +	      for(;e!=INVALID;g.nextIn(e))
    1.37 +		{
    1.38 +		      edges_to_delete.insert(e);
    1.39 +		}
    1.40 +
    1.41 +	      //deleting collected edges
    1.42 +	      for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
    1.43 +		{
    1.44 +		  delete_item(*edge_set_it);
    1.45  		}
    1.46  	      delete_item(active_node);
    1.47  	    }
    1.48 +	  //a simple edge was chosen
    1.49  	  else
    1.50  	    {
    1.51  	      delete_item(active_edge);
    1.52 @@ -651,6 +654,7 @@
    1.53  
    1.54  	  
    1.55  	}
    1.56 +      //pointer was moved, deletion is cancelled
    1.57        else
    1.58  	{
    1.59  	  if(active_node!=INVALID)
    1.60 @@ -662,6 +666,7 @@
    1.61  	      *active_item << Gnome::Canvas::Properties::fill_color("green");
    1.62  	    }
    1.63  	}
    1.64 +      //reseting datas
    1.65        active_item=NULL;
    1.66        active_edge=INVALID;
    1.67        active_node=INVALID;
    1.68 @@ -688,3 +693,9 @@
    1.69    g.erase(edge_to_delete);
    1.70  }
    1.71  
    1.72 +void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete)
    1.73 +{
    1.74 +  delete(edgesmap[edge_to_delete]);
    1.75 +  g.erase(edge_to_delete);
    1.76 +}
    1.77 +
     2.1 --- a/gui/graph_displayer_canvas.h	Wed Jun 15 11:01:55 2005 +0000
     2.2 +++ b/gui/graph_displayer_canvas.h	Wed Jun 15 11:15:01 2005 +0000
     2.3 @@ -73,6 +73,8 @@
     2.4    void delete_item(NodeIt);
     2.5    ///Deletes the given element.
     2.6    void delete_item(EdgeIt);
     2.7 +  ///Deletes the given element.
     2.8 +  void delete_item(Graph::Edge);
     2.9  
    2.10    ///The graph, on which we work
    2.11    Graph g;