Edge creation is available.
1.1 --- a/gui/graph_displayer_canvas.cc Fri Jun 10 12:50:43 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas.cc Mon Jun 13 10:30:08 2005 +0000
1.3 @@ -1,13 +1,10 @@
1.4 #include <graph_displayer_canvas.h>
1.5 #include <math.h>
1.6
1.7 -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
1.8 +GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL),target_item(NULL)
1.9 {
1.10 - Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
1.11 - *origo << Gnome::Canvas::Properties::fill_color("black");
1.12 - *origo << Gnome::Canvas::Properties::outline_color("black");
1.13
1.14 - actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
1.15 + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
1.16
1.17 //set_center_scroll_region(true);
1.18
1.19 @@ -366,7 +363,6 @@
1.20 clicked_y=e->motion.y;
1.21
1.22 //all the edges connected to the moved point has to be redrawn
1.23 -
1.24 EdgeIt e;
1.25
1.26 g.firstOut(e,active_node);
1.27 @@ -458,7 +454,81 @@
1.28
1.29 bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
1.30 {
1.31 - e=e;
1.32 + switch(e->type)
1.33 + {
1.34 + case GDK_BUTTON_PRESS:
1.35 + if(!active_item)
1.36 + {
1.37 + //we mark the location of the event to be able to calculate parameters of dragging
1.38 + clicked_x=e->button.x;
1.39 + clicked_y=e->button.y;
1.40 + active_item=(get_item_at(e->button.x, e->button.y));
1.41 + active_node=INVALID;
1.42 + for (NodeIt i(g); i!=INVALID; ++i)
1.43 + {
1.44 + if(nodesmap[i]==active_item)
1.45 + {
1.46 + active_node=i;
1.47 + }
1.48 + }
1.49 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.50 + isbutton=true;
1.51 + }
1.52 + else
1.53 + {
1.54 + target_item=(get_item_at(e->button.x, e->button.y));
1.55 + Graph::NodeIt target_node=INVALID;
1.56 + for (NodeIt i(g); i!=INVALID; ++i)
1.57 + {
1.58 + if(nodesmap[i]==target_item)
1.59 + {
1.60 + target_node=i;
1.61 + }
1.62 + }
1.63 + *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
1.64 +
1.65 + //creating new edge
1.66 + // Graph::Edge new_edge=g.addEdge(active_node, target_node);
1.67 + active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
1.68 +
1.69 + //calculating coordinates of new edge
1.70 + Gnome::Canvas::Points coos;
1.71 + double x1, x2, y1, y2;
1.72 +
1.73 + active_item->get_bounds(x1, y1, x2, y2);
1.74 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.75 +
1.76 + target_item->get_bounds(x1, y1, x2, y2);
1.77 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.78 +
1.79 + //drawing new edge
1.80 + edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);
1.81 + *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
1.82 + edgesmap[active_edge]->property_width_pixels().set_value(10);
1.83 +
1.84 + //redraw nodes to blank terminations of the new edge
1.85 + target_item->raise_to_top();
1.86 + active_item->raise_to_top();
1.87 +
1.88 + //initializing edge-text as well, to empty string
1.89 + edgesmap[active_edge]->get_bounds(x1, y1, x2, y2);
1.90 + edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
1.91 + edgetextmap[active_edge]->property_fill_color().set_value("black");
1.92 + }
1.93 + break;
1.94 + case GDK_BUTTON_RELEASE:
1.95 + isbutton=false;
1.96 + if(target_item)
1.97 + {
1.98 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.99 + *target_item << Gnome::Canvas::Properties::fill_color("blue");
1.100 + active_item=NULL;
1.101 + target_item=NULL;
1.102 + }
1.103 + break;
1.104 + default:
1.105 + break;
1.106 + }
1.107 return false;
1.108 }
1.109
2.1 --- a/gui/graph_displayer_canvas.h Fri Jun 10 12:50:43 2005 +0000
2.2 +++ b/gui/graph_displayer_canvas.h Mon Jun 13 10:30:08 2005 +0000
2.3 @@ -96,8 +96,9 @@
2.4 ///this variable is needed, because
2.5 ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
2.6 ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
2.7 - Gnome::Canvas::Item * active_item;
2.8 + Gnome::Canvas::Item * active_item, * target_item;
2.9 Graph::NodeIt active_node;
2.10 + Graph::EdgeIt active_edge;
2.11
2.12 static const int zoom_step = 5;
2.13 };