Two minor changes.
DefaultReader<std::string>
comment lines
1 #include <graph_displayer_canvas.h>
3 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)
6 for (EdgeIt i(g); i!=INVALID; ++i)
8 Gnome::Canvas::Points coos;
9 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
10 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
12 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
13 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
14 edgesmap[i]->property_width_pixels().set_value(10);
17 double x1, x2, y1, y2;
18 edgesmap[i]->get_bounds(x1, y1, x2, y2);
20 edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
21 edgetextmap[i]->property_fill_color().set_value("black");
25 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
27 for (; i!=INVALID; ++i)
29 if(cm[i].x>maxx)maxx=(int)cm[i].x;
30 if(cm[i].y>maxy)maxy=(int)cm[i].y;
31 if(cm[i].x<minx)minx=(int)cm[i].x;
32 if(cm[i].y<miny)miny=(int)cm[i].y;
34 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
35 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
36 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
37 (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
40 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
41 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
43 set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
44 std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
45 std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
46 std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
50 GraphDisplayerCanvas::~GraphDisplayerCanvas()
52 Graph::NodeMap <int> id(g);
53 Graph::NodeMap <double> xc(g);
54 Graph::NodeMap <double> yc(g);
58 for (NodeIt i(g); i!=INVALID; ++i)
61 nodesmap[i]->get_bounds(x1, y1, x2, y2);
68 GraphWriter<Graph> writer(std::cout,g);
70 writer.writeNodeMap("id", id);
71 writer.writeNodeMap("coordinates_x", xc);
72 writer.writeNodeMap("coordinates_y", yc);
76 int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
78 for (EdgeIt i(g); i!=INVALID; ++i)
80 int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
81 edgesmap[i]->property_width_pixels().set_value(w);
86 int GraphDisplayerCanvas::changeColor (std::string mapname)
88 for (EdgeIt i(g); i!=INVALID; ++i)
90 double w=(*(mapstorage.edgemap_storage)[mapname])[i];
91 double max=mapstorage.maxOfEdgeMap(mapname);
92 double min=mapstorage.minOfEdgeMap(mapname);
94 //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
98 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
102 color.set_rgb_p (0, 100, 0);
105 edgesmap[i]->property_fill_color_gdk().set_value(color);
110 int GraphDisplayerCanvas::changeText (std::string mapname)
112 for (EdgeIt i(g); i!=INVALID; ++i)
116 double number=(*(mapstorage.edgemap_storage)[mapname])[i];
117 int length=(int)(floor(log(number)/log(10)))+1;
118 int maxpos=(int)(pow(10,length-1));
119 int strl=length+1+RANGE;
120 char * str=new char[strl];
124 for(int j=0;j<strl;j++)
128 int digit=(int)(number/maxpos);
130 number-=digit*maxpos;
135 edgetextmap[i]->property_text().set_value(str);
139 edgetextmap[i]->property_text().set_value("");
146 int GraphDisplayerCanvas::rezoom ()
148 double x1, x2, y1, y2;
152 nodesmap[i]->get_bounds(x1, y1, x2, y2);
157 int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
159 for (; i!=INVALID; ++i)
161 nodesmap[i]->get_bounds(x1, y1, x2, y2);
172 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
173 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
175 set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
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 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
187 case GDK_BUTTON_PRESS:
188 clicked_x=e->button.x;
189 clicked_y=e->button.y;
190 active_item=(get_item_at(e->button.x, e->button.y));
193 case GDK_BUTTON_RELEASE:
197 case GDK_MOTION_NOTIFY:
200 double dx=e->motion.x-clicked_x;
201 double dy=e->motion.y-clicked_y;
202 active_item->move(dx, dy);
203 clicked_x=e->motion.x;
204 clicked_y=e->motion.y;
209 for(;e!=INVALID;g.nextOut(e))
211 Gnome::Canvas::Points coos;
212 double x1, x2, y1, y2;
214 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
215 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
217 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
218 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
220 edgesmap[e]->property_points().set_value(coos);
222 edgesmap[e]->get_bounds(x1, y1, x2, y2);
224 edgetextmap[e]->property_x().set_value((x1+x2)/2);
225 edgetextmap[e]->property_y().set_value((y1+y2)/2);
229 for(;e!=INVALID;g.nextIn(e))
231 Gnome::Canvas::Points coos;
232 double x1, x2, y1, y2;
234 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
235 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
237 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
238 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
240 edgesmap[e]->property_points().set_value(coos);
242 edgesmap[e]->get_bounds(x1, y1, x2, y2);
244 edgetextmap[e]->property_x().set_value((x1+x2)/2);
245 edgetextmap[e]->property_y().set_value((y1+y2)/2);
253 bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
255 Gnome::Canvas::CanvasAA::on_expose_event(event);