1.1 --- a/gui/graph_displayer_canvas.cc Thu May 26 16:32:26 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas.cc Fri May 27 10:34:20 2005 +0000
1.3 @@ -1,19 +1,26 @@
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 {
1.9
1.10 + //first edges are drawn, to hide joining with nodes later
1.11 +
1.12 for (EdgeIt i(g); i!=INVALID; ++i)
1.13 {
1.14 +
1.15 + //drawing green lines, coordinates are from cm
1.16 +
1.17 Gnome::Canvas::Points coos;
1.18 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
1.19 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
1.20
1.21 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
1.22 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
1.23 - edgesmap[i]->property_width_pixels().set_value(10);
1.24 + edgesmap[i]->property_width_pixels().set_value(10);
1.25
1.26 -
1.27 + //initializing edge-text as well, to empty string
1.28 +
1.29 double x1, x2, y1, y2;
1.30 edgesmap[i]->get_bounds(x1, y1, x2, y2);
1.31
1.32 @@ -21,22 +28,30 @@
1.33 edgetextmap[i]->property_fill_color().set_value("black");
1.34 }
1.35
1.36 + //afterwards nodes come to be drawn
1.37 +
1.38 NodeIt i(g);
1.39 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
1.40
1.41 for (; i!=INVALID; ++i)
1.42 {
1.43 + //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
1.44 +
1.45 if(cm[i].x>maxx)maxx=(int)cm[i].x;
1.46 if(cm[i].y>maxy)maxy=(int)cm[i].y;
1.47 if(cm[i].x<minx)minx=(int)cm[i].x;
1.48 if(cm[i].y<miny)miny=(int)cm[i].y;
1.49
1.50 + //drawing bule nodes, with black line around them
1.51 +
1.52 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
1.53 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.54 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
1.55 (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
1.56 }
1.57
1.58 + //setting zoom to be able to see the whole graph on the canvas
1.59 +
1.60 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
1.61 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
1.62
1.63 @@ -49,28 +64,32 @@
1.64
1.65 GraphDisplayerCanvas::~GraphDisplayerCanvas()
1.66 {
1.67 - Graph::NodeMap <int> id(g);
1.68 - Graph::NodeMap <double> xc(g);
1.69 - Graph::NodeMap <double> yc(g);
1.70
1.71 - int j=1;
1.72 + //writing out the end state of the graph
1.73 + //\todo all the maps has to be write out!
1.74
1.75 - for (NodeIt i(g); i!=INVALID; ++i)
1.76 - {
1.77 - double x1,y1,x2,y2;
1.78 - nodesmap[i]->get_bounds(x1, y1, x2, y2);
1.79 + Graph::NodeMap <int> id(g);
1.80 + Graph::NodeMap <double> xc(g);
1.81 + Graph::NodeMap <double> yc(g);
1.82 +
1.83 + int j=1;
1.84 +
1.85 + for (NodeIt i(g); i!=INVALID; ++i)
1.86 + {
1.87 + double x1,y1,x2,y2;
1.88 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
1.89 +
1.90 + id[i]=j++;
1.91 + xc[i]=(x1+x2)/2;
1.92 + yc[i]=(y1+y2)/2;
1.93 + }
1.94
1.95 - id[i]=j++;
1.96 - xc[i]=(x1+x2)/2;
1.97 - yc[i]=(y1+y2)/2;
1.98 - }
1.99 -
1.100 - GraphWriter<Graph> writer(std::cout,g);
1.101 -
1.102 - writer.writeNodeMap("id", id);
1.103 - writer.writeNodeMap("coordinates_x", xc);
1.104 - writer.writeNodeMap("coordinates_y", yc);
1.105 - writer.run();
1.106 + GraphWriter<Graph> writer(std::cout,g);
1.107 +
1.108 + writer.writeNodeMap("id", id);
1.109 + writer.writeNodeMap("coordinates_x", xc);
1.110 + writer.writeNodeMap("coordinates_y", yc);
1.111 + writer.run();
1.112 }
1.113
1.114 int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
1.115 @@ -85,6 +104,11 @@
1.116
1.117 int GraphDisplayerCanvas::changeColor (std::string mapname)
1.118 {
1.119 +
1.120 + //function maps the range of the maximum and
1.121 + //the minimum of the nodemap to the range of
1.122 + //green in RGB
1.123 +
1.124 for (EdgeIt i(g); i!=INVALID; ++i)
1.125 {
1.126 double w=(*(mapstorage.edgemap_storage)[mapname])[i];
1.127 @@ -109,6 +133,13 @@
1.128
1.129 int GraphDisplayerCanvas::changeText (std::string mapname)
1.130 {
1.131 +
1.132 + //the number in the map will be written on the edge
1.133 + //EXCEPT when the name of the map is Text, because
1.134 + //in that case empty string will be written, because
1.135 + //that is the deleter map
1.136 + //\todo isn't it a bit woodcutter?
1.137 +
1.138 for (EdgeIt i(g); i!=INVALID; ++i)
1.139 {
1.140 if(mapname!="Text")
1.141 @@ -145,6 +176,13 @@
1.142
1.143 int GraphDisplayerCanvas::rezoom ()
1.144 {
1.145 +
1.146 + //searches for the minimum and the maximum
1.147 + //value of the coordinates of the nodes to
1.148 + //set the pixel rpo unit to a value to be
1.149 + //able to see the whole graph in the canvas
1.150 + //\todo does not work properly
1.151 +
1.152 double x1, x2, y1, y2;
1.153 int x,y;
1.154
1.155 @@ -177,14 +215,12 @@
1.156 };
1.157
1.158
1.159 -///This function moves only one node of displayed_graph,
1.160 -///but recalculate the location of weight point,
1.161 -///and also redraw the sides of the planefigure.
1.162 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
1.163 {
1.164 switch(e->type)
1.165 {
1.166 case GDK_BUTTON_PRESS:
1.167 + //we mark the location of the event to be able to calculate parameters of dragging
1.168 clicked_x=e->button.x;
1.169 clicked_y=e->button.y;
1.170 active_item=(get_item_at(e->button.x, e->button.y));
1.171 @@ -195,16 +231,23 @@
1.172 active_item=NULL;
1.173 break;
1.174 case GDK_MOTION_NOTIFY:
1.175 + //we only have to do sg. if the mouse button is pressed
1.176 if(isbutton)
1.177 {
1.178 + //new coordinates will be the old values,
1.179 + //because the item will be moved to the
1.180 + //new coordinate therefore the new movement
1.181 + //has to be calculated from here
1.182 +
1.183 double dx=e->motion.x-clicked_x;
1.184 double dy=e->motion.y-clicked_y;
1.185 active_item->move(dx, dy);
1.186 clicked_x=e->motion.x;
1.187 clicked_y=e->motion.y;
1.188
1.189 + //all the edges connected to the moved point has to be redrawn
1.190 +
1.191 EdgeIt e;
1.192 -
1.193 g.firstOut(e,n);
1.194 for(;e!=INVALID;g.nextOut(e))
1.195 {