graph_displayer_canvas.cc
branchgui
changeset 23 d0e4ac77bafe
parent 20 a3bd39d50930
child 25 c45a34eaa118
equal deleted inserted replaced
13:922f1d2a70c4 14:c4de8777c332
     3 #include <math.h>
     3 #include <math.h>
     4 
     4 
     5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL)
     5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL)
     6 {
     6 {
     7   
     7   
     8   actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
     8   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
       
     9   actual_tool=CREATE_NODE;
     9 
    10 
    10   active_node=INVALID;
    11   active_node=INVALID;
    11   active_edge=INVALID;
    12   active_edge=INVALID;
    12 
    13 
    13   //set_center_scroll_region(true);
    14   //set_center_scroll_region(true);
    21 
    22 
    22     Gnome::Canvas::Points coos;
    23     Gnome::Canvas::Points coos;
    23     coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    24     coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    24     coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
    25     coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
    25     
    26     
    26     edgesmap[i]=new BrokenEdge(displayed_graph, coos);
    27     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
    27     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    28     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    28     edgesmap[i]->property_width_pixels().set_value(10);    
    29     edgesmap[i]->property_width_pixels().set_value(10);    
    29     
    30     
    30     //initializing edge-text as well, to empty string
    31     //initializing edge-text as well, to empty string
    31 
    32 
   307 
   308 
   308 void GraphDisplayerCanvas::changeEditorialTool(int newtool)
   309 void GraphDisplayerCanvas::changeEditorialTool(int newtool)
   309 {
   310 {
   310   actual_handler.disconnect();
   311   actual_handler.disconnect();
   311 
   312 
       
   313   if(actual_tool==CREATE_EDGE)
       
   314     {
       
   315 	GdkEvent * generated=new GdkEvent();
       
   316 	generated->type=GDK_BUTTON_RELEASE;
       
   317 	generated->button.button=3;
       
   318 	create_edge_event_handler(generated);      
       
   319     }
       
   320 
       
   321   actual_tool=newtool;
       
   322 
   312   switch(newtool)
   323   switch(newtool)
   313     {
   324     {
   314     case MOVE:
   325     case MOVE:
   315       actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
   326       actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
   316       break;
   327       break;
   329       break;
   340       break;
   330 
   341 
   331     default:
   342     default:
   332       break;
   343       break;
   333     }
   344     }
       
   345 }
       
   346 
       
   347 int GraphDisplayerCanvas::get_actual_tool()
       
   348 {
       
   349   return actual_tool;
   334 }
   350 }
   335 
   351 
   336 bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
   352 bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
   337 {
   353 {
   338   switch(e->type)
   354   switch(e->type)
   562 
   578 
   563 		  target_item->get_bounds(x1, y1, x2, y2);
   579 		  target_item->get_bounds(x1, y1, x2, y2);
   564 		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   580 		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   565 
   581 
   566 		  //drawing new edge
   582 		  //drawing new edge
   567 		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos);
   583 		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
   568 		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
   584 		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
   569 		  edgesmap[active_edge]->property_width_pixels().set_value(10);
   585 		  edgesmap[active_edge]->property_width_pixels().set_value(10);
   570 
   586 
   571 		  //redraw nodes to blank terminations of the new edge
   587 		  //redraw nodes to blank terminations of the new edge
   572 		  target_item->raise_to_top();
   588 		  target_item->raise_to_top();