Changeset 4:e099638ff236 in glemon0.x for graph_displayer_canvas.cc
 Timestamp:
 05/27/05 12:34:20 (16 years ago)
 Branch:
 gui
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk/gui@1915
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

graph_displayer_canvas.cc
r1 r4 1 1 #include <graph_displayer_canvas.h> 2 #include <math.h> 2 3 3 4 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) 4 5 { 5 6 7 //first edges are drawn, to hide joining with nodes later 8 6 9 for (EdgeIt i(g); i!=INVALID; ++i) 7 10 { 11 12 //drawing green lines, coordinates are from cm 13 8 14 Gnome::Canvas::Points coos; 9 15 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); … … 12 18 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos); 13 19 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); 14 edgesmap[i]>property_width_pixels().set_value(10); 20 edgesmap[i]>property_width_pixels().set_value(10); 15 21 16 22 //initializing edgetext as well, to empty string 23 17 24 double x1, x2, y1, y2; 18 25 edgesmap[i]>get_bounds(x1, y1, x2, y2); … … 22 29 } 23 30 31 //afterwards nodes come to be drawn 32 24 33 NodeIt i(g); 25 34 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; … … 27 36 for (; i!=INVALID; ++i) 28 37 { 38 //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) 39 29 40 if(cm[i].x>maxx)maxx=(int)cm[i].x; 30 41 if(cm[i].y>maxy)maxy=(int)cm[i].y; … … 32 43 if(cm[i].y<miny)miny=(int)cm[i].y; 33 44 45 //drawing bule nodes, with black line around them 46 34 47 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x20, cm[i].y20, cm[i].x+20, cm[i].y+20); 35 48 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); … … 38 51 } 39 52 53 //setting zoom to be able to see the whole graph on the canvas 54 40 55 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); 41 56 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); … … 50 65 GraphDisplayerCanvas::~GraphDisplayerCanvas() 51 66 { 52 Graph::NodeMap <int> id(g); 53 Graph::NodeMap <double> xc(g); 54 Graph::NodeMap <double> yc(g); 55 56 int j=1; 57 58 for (NodeIt i(g); i!=INVALID; ++i) 59 { 60 double x1,y1,x2,y2; 61 nodesmap[i]>get_bounds(x1, y1, x2, y2); 62 63 id[i]=j++; 64 xc[i]=(x1+x2)/2; 65 yc[i]=(y1+y2)/2; 66 } 67 68 GraphWriter<Graph> writer(std::cout,g); 69 70 writer.writeNodeMap("id", id); 71 writer.writeNodeMap("coordinates_x", xc); 72 writer.writeNodeMap("coordinates_y", yc); 73 writer.run(); 67 68 //writing out the end state of the graph 69 //\todo all the maps has to be write out! 70 71 Graph::NodeMap <int> id(g); 72 Graph::NodeMap <double> xc(g); 73 Graph::NodeMap <double> yc(g); 74 75 int j=1; 76 77 for (NodeIt i(g); i!=INVALID; ++i) 78 { 79 double x1,y1,x2,y2; 80 nodesmap[i]>get_bounds(x1, y1, x2, y2); 81 82 id[i]=j++; 83 xc[i]=(x1+x2)/2; 84 yc[i]=(y1+y2)/2; 85 } 86 87 GraphWriter<Graph> writer(std::cout,g); 88 89 writer.writeNodeMap("id", id); 90 writer.writeNodeMap("coordinates_x", xc); 91 writer.writeNodeMap("coordinates_y", yc); 92 writer.run(); 74 93 } 75 94 … … 86 105 int GraphDisplayerCanvas::changeColor (std::string mapname) 87 106 { 107 108 //function maps the range of the maximum and 109 //the minimum of the nodemap to the range of 110 //green in RGB 111 88 112 for (EdgeIt i(g); i!=INVALID; ++i) 89 113 { … … 110 134 int GraphDisplayerCanvas::changeText (std::string mapname) 111 135 { 136 137 //the number in the map will be written on the edge 138 //EXCEPT when the name of the map is Text, because 139 //in that case empty string will be written, because 140 //that is the deleter map 141 //\todo isn't it a bit woodcutter? 142 112 143 for (EdgeIt i(g); i!=INVALID; ++i) 113 144 { … … 146 177 int GraphDisplayerCanvas::rezoom () 147 178 { 179 180 //searches for the minimum and the maximum 181 //value of the coordinates of the nodes to 182 //set the pixel rpo unit to a value to be 183 //able to see the whole graph in the canvas 184 //\todo does not work properly 185 148 186 double x1, x2, y1, y2; 149 187 int x,y; … … 178 216 179 217 180 ///This function moves only one node of displayed_graph,181 ///but recalculate the location of weight point,182 ///and also redraw the sides of the planefigure.183 218 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) 184 219 { … … 186 221 { 187 222 case GDK_BUTTON_PRESS: 223 //we mark the location of the event to be able to calculate parameters of dragging 188 224 clicked_x=e>button.x; 189 225 clicked_y=e>button.y; … … 196 232 break; 197 233 case GDK_MOTION_NOTIFY: 234 //we only have to do sg. if the mouse button is pressed 198 235 if(isbutton) 199 236 { 237 //new coordinates will be the old values, 238 //because the item will be moved to the 239 //new coordinate therefore the new movement 240 //has to be calculated from here 241 200 242 double dx=e>motion.xclicked_x; 201 243 double dy=e>motion.yclicked_y; … … 204 246 clicked_y=e>motion.y; 205 247 248 //all the edges connected to the moved point has to be redrawn 249 206 250 EdgeIt e; 207 208 251 g.firstOut(e,n); 209 252 for(;e!=INVALID;g.nextOut(e))
Note: See TracChangeset
for help on using the changeset viewer.