graph_displayer_canvas-event.cc
branchgui
changeset 62 80eefca04b1e
parent 59 c38925cc6a4d
child 63 59768817442a
equal deleted inserted replaced
19:050af543cbb9 20:8dd881e33a42
   223     case GDK_BUTTON_PRESS:
   223     case GDK_BUTTON_PRESS:
   224       mapstorage.modified = true;
   224       mapstorage.modified = true;
   225 
   225 
   226       isbutton=1;
   226       isbutton=1;
   227 
   227 
   228       active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
   228       active_node=mapstorage.graph.addNode();
   229 
   229 
   230       //initiating values corresponding to new node in maps
   230       //initiating values corresponding to new node in maps
   231 
   231 
   232       window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   232       window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   233 
   233 
   337 	  //node
   337 	  //node
   338 	  else
   338 	  else
   339 	    {
   339 	    {
   340 	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   340 	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   341 	      target_item=(get_item_at(clicked_x, clicked_y));
   341 	      target_item=(get_item_at(clicked_x, clicked_y));
   342 	      Graph::NodeIt target_node=INVALID;
   342 	      Node target_node=INVALID;
   343 	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   343 	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   344 		{
   344 		{
   345 		  if(nodesmap[i]==target_item)
   345 		  if(nodesmap[i]==target_item)
   346 		    {
   346 		    {
   347 		      target_node=i;
   347 		      target_node=i;
   352 		{
   352 		{
   353 		  if(target_node!=active_node)		
   353 		  if(target_node!=active_node)		
   354 		    {
   354 		    {
   355           mapstorage.modified = true;
   355           mapstorage.modified = true;
   356 
   356 
   357 		      *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
   357 		      *(nodesmap[target_node]) <<
       
   358 			Gnome::Canvas::Properties::fill_color("red");
   358 
   359 
   359 		      //creating new edge
   360 		      //creating new edge
   360 		      active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
   361 		      active_edge=mapstorage.graph.addEdge(active_node,
       
   362 							   target_node);
   361 
   363 
   362 		      //initiating values corresponding to new edge in maps
   364 		      //initiating values corresponding to new edge in maps
   363 		      mapstorage.initMapsForEdge(active_edge);
   365 		      mapstorage.initMapsForEdge(active_edge);
   364                       (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
   366                       (*mapstorage.edgemap_storage["id"])[active_edge] = 
       
   367 			mapstorage.graph.id(active_edge);
   365 	  
   368 	  
   366 		      //calculating coordinates of new edge
   369 		      //calculating coordinates of new edge
   367 		      Gnome::Canvas::Points coos;
   370 		      Gnome::Canvas::Points coos;
   368 		      double x1, x2, y1, y2;
   371 		      double x1, x2, y1, y2;
   369 	  
   372 	  
   553 	  }
   556 	  }
   554 	case GDK_BUTTON_PRESS:
   557 	case GDK_BUTTON_PRESS:
   555 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   558 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   556 	  {
   559 	  {
   557 	    //for determine, whether it was an edge
   560 	    //for determine, whether it was an edge
   558 	    Graph::EdgeIt clicked_edge=INVALID;
   561 	    Edge clicked_edge=INVALID;
   559 
   562 
   560 	    //find the activated item between texts
   563 	    //find the activated item between texts
   561 	    active_item=(get_item_at(e->button.x, e->button.y));
   564 	    active_item=(get_item_at(e->button.x, e->button.y));
   562 	    for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   565 	    for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   563 	      {
   566 	      {
   675 	  }
   678 	  }
   676 	case GDK_BUTTON_PRESS:
   679 	case GDK_BUTTON_PRESS:
   677 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   680 	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   678 	  {
   681 	  {
   679 	    //for determine, whether it was a node
   682 	    //for determine, whether it was a node
   680 	    Graph::NodeIt clicked_node=INVALID;
   683 	    Node clicked_node=INVALID;
   681 
   684 
   682 	    //find the activated item between texts
   685 	    //find the activated item between texts
   683 	    active_item=(get_item_at(e->button.x, e->button.y));
   686 	    active_item=(get_item_at(e->button.x, e->button.y));
   684 	    for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   687 	    for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   685 	      {
   688 	      {
   847 	}
   850 	}
   848     }
   851     }
   849   return false;
   852   return false;
   850 }
   853 }
   851 
   854 
   852 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
   855 void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
   853 {
   856 {
   854   delete(nodetextmap[node_to_delete]);
   857   delete(nodetextmap[node_to_delete]);
   855   delete(nodesmap[node_to_delete]);
   858   delete(nodesmap[node_to_delete]);
   856   mapstorage.graph.erase(node_to_delete);
   859   mapstorage.graph.erase(node_to_delete);
   857 }
   860 }
   858 
   861 
   859 void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
   862 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
   860 {
   863 {
   861   delete(edgetextmap[edge_to_delete]);
   864   delete(edgetextmap[edge_to_delete]);
   862   delete(edgesmap[edge_to_delete]);
   865   delete(edgesmap[edge_to_delete]);
   863   mapstorage.graph.erase(edge_to_delete);
   866   mapstorage.graph.erase(edge_to_delete);
   864 }
   867 }
   865 
   868 
   866 void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
       
   867 {
       
   868   delete(edgetextmap[edge_to_delete]);
       
   869   delete(edgesmap[edge_to_delete]);
       
   870   mapstorage.graph.erase(edge_to_delete);
       
   871 }
       
   872 
       
   873 void GraphDisplayerCanvas::textReposition(xy<double> new_place)
   869 void GraphDisplayerCanvas::textReposition(xy<double> new_place)
   874 {
   870 {
   875   new_place+=(xy<double>(10,10));
   871   new_place+=(xy<double>(10,10));
   876   edgetextmap[forming_edge]->property_x().set_value(new_place.x);
   872   edgetextmap[forming_edge]->property_x().set_value(new_place.x);
   877   edgetextmap[forming_edge]->property_y().set_value(new_place.y);
   873   edgetextmap[forming_edge]->property_y().set_value(new_place.y);