1.1 --- a/gui/graph_displayer_canvas.cc Wed Jun 01 23:30:13 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas.cc Wed Jun 01 23:33:26 2005 +0000
1.3 @@ -1,321 +1,321 @@
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 - //set_center_scroll_region(true);
1.10 -
1.11 - //first edges are drawn, to hide joining with nodes later
1.12 -
1.13 - for (EdgeIt i(g); i!=INVALID; ++i)
1.14 - {
1.15 -
1.16 - //drawing green lines, coordinates are from cm
1.17 -
1.18 - Gnome::Canvas::Points coos;
1.19 - coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
1.20 - coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
1.21 -
1.22 - edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
1.23 - *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
1.24 - edgesmap[i]->property_width_pixels().set_value(10);
1.25 -
1.26 - //initializing edge-text as well, to empty string
1.27 -
1.28 - double x1, x2, y1, y2;
1.29 - edgesmap[i]->get_bounds(x1, y1, x2, y2);
1.30 -
1.31 - edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
1.32 - edgetextmap[i]->property_fill_color().set_value("black");
1.33 - }
1.34 -
1.35 - //afterwards nodes come to be drawn
1.36 -
1.37 - NodeIt i(g);
1.38 - int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
1.39 -
1.40 - for (; i!=INVALID; ++i)
1.41 - {
1.42 - //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
1.43 -
1.44 - if(cm[i].x>maxx)maxx=(int)cm[i].x;
1.45 - if(cm[i].y>maxy)maxy=(int)cm[i].y;
1.46 - if(cm[i].x<minx)minx=(int)cm[i].x;
1.47 - if(cm[i].y<miny)miny=(int)cm[i].y;
1.48 -
1.49 - //drawing bule nodes, with black line around them
1.50 -
1.51 - 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.52 - *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.53 - *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
1.54 - (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
1.55 - }
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 - set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
1.64 - std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
1.65 - std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
1.66 - std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
1.67 -*/
1.68 - updateScrollRegion();
1.69 -}
1.70 -
1.71 -GraphDisplayerCanvas::~GraphDisplayerCanvas()
1.72 -{
1.73 -
1.74 - //writing out the end state of the graph
1.75 - //\todo all the maps has to be write out!
1.76 -
1.77 - Graph::NodeMap <int> id(g);
1.78 - Graph::NodeMap <double> xc(g);
1.79 - Graph::NodeMap <double> yc(g);
1.80 -
1.81 - int j=1;
1.82 -
1.83 - for (NodeIt i(g); i!=INVALID; ++i)
1.84 - {
1.85 - double x1,y1,x2,y2;
1.86 - nodesmap[i]->get_bounds(x1, y1, x2, y2);
1.87 -
1.88 - id[i]=j++;
1.89 - xc[i]=(x1+x2)/2;
1.90 - yc[i]=(y1+y2)/2;
1.91 - }
1.92 -
1.93 - GraphWriter<Graph> writer(std::cout,g);
1.94 -
1.95 - writer.writeNodeMap("id", id);
1.96 - writer.writeNodeMap("coordinates_x", xc);
1.97 - writer.writeNodeMap("coordinates_y", yc);
1.98 - writer.run();
1.99 -}
1.100 -
1.101 -int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
1.102 -{
1.103 - for (EdgeIt i(g); i!=INVALID; ++i)
1.104 - {
1.105 - int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
1.106 - edgesmap[i]->property_width_pixels().set_value(w);
1.107 - }
1.108 - return 0;
1.109 -};
1.110 -
1.111 -int GraphDisplayerCanvas::changeColor (std::string mapname)
1.112 -{
1.113 -
1.114 - //function maps the range of the maximum and
1.115 - //the minimum of the nodemap to the range of
1.116 - //green in RGB
1.117 -
1.118 - for (EdgeIt i(g); i!=INVALID; ++i)
1.119 - {
1.120 - double w=(*(mapstorage.edgemap_storage)[mapname])[i];
1.121 - double max=mapstorage.maxOfEdgeMap(mapname);
1.122 - double min=mapstorage.minOfEdgeMap(mapname);
1.123 -
1.124 - //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
1.125 - Gdk::Color color;
1.126 - if(max!=min)
1.127 - {
1.128 - color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
1.129 - }
1.130 - else
1.131 - {
1.132 - color.set_rgb_p (0, 100, 0);
1.133 - }
1.134 -
1.135 - edgesmap[i]->property_fill_color_gdk().set_value(color);
1.136 - }
1.137 - return 0;
1.138 -};
1.139 -
1.140 -int GraphDisplayerCanvas::changeText (std::string mapname)
1.141 -{
1.142 -
1.143 - //the number in the map will be written on the edge
1.144 - //EXCEPT when the name of the map is Text, because
1.145 - //in that case empty string will be written, because
1.146 - //that is the deleter map
1.147 - //\todo isn't it a bit woodcutter?
1.148 -
1.149 - for (EdgeIt i(g); i!=INVALID; ++i)
1.150 - {
1.151 - if(mapname!="Text")
1.152 - {
1.153 - double number=(*(mapstorage.edgemap_storage)[mapname])[i];
1.154 - int length=(int)(floor(log(number)/log(10)))+1;
1.155 - int maxpos=(int)(pow(10,length-1));
1.156 - int strl=length+1+RANGE;
1.157 - char * str=new char[strl];
1.158 - str[length]='.';
1.159 - str[strl]='\0';
1.160 -
1.161 - for(int j=0;j<strl;j++)
1.162 - {
1.163 - if(j!=length)
1.164 - {
1.165 - int digit=(int)(number/maxpos);
1.166 - str[j]=(digit+'0');
1.167 - number-=digit*maxpos;
1.168 - number*=10;
1.169 - }
1.170 - }
1.171 -
1.172 - edgetextmap[i]->property_text().set_value(str);
1.173 - }
1.174 - else
1.175 - {
1.176 - edgetextmap[i]->property_text().set_value("");
1.177 - }
1.178 - }
1.179 - return 0;
1.180 -};
1.181 -
1.182 -bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
1.183 -{
1.184 - switch(e->type)
1.185 - {
1.186 - case GDK_BUTTON_PRESS:
1.187 - //we mark the location of the event to be able to calculate parameters of dragging
1.188 - clicked_x=e->button.x;
1.189 - clicked_y=e->button.y;
1.190 - active_item=(get_item_at(e->button.x, e->button.y));
1.191 - isbutton=true;
1.192 - break;
1.193 - case GDK_BUTTON_RELEASE:
1.194 - isbutton=false;
1.195 - active_item=NULL;
1.196 - break;
1.197 - case GDK_MOTION_NOTIFY:
1.198 - //we only have to do sg. if the mouse button is pressed
1.199 - if(isbutton)
1.200 - {
1.201 - //new coordinates will be the old values,
1.202 - //because the item will be moved to the
1.203 - //new coordinate therefore the new movement
1.204 - //has to be calculated from here
1.205 -
1.206 - double dx=e->motion.x-clicked_x;
1.207 - double dy=e->motion.y-clicked_y;
1.208 - active_item->move(dx, dy);
1.209 - clicked_x=e->motion.x;
1.210 - clicked_y=e->motion.y;
1.211 -
1.212 - //all the edges connected to the moved point has to be redrawn
1.213 -
1.214 - EdgeIt e;
1.215 - g.firstOut(e,n);
1.216 - for(;e!=INVALID;g.nextOut(e))
1.217 - {
1.218 - Gnome::Canvas::Points coos;
1.219 - double x1, x2, y1, y2;
1.220 -
1.221 - nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.222 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.223 -
1.224 - nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.225 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.226 -
1.227 - edgesmap[e]->property_points().set_value(coos);
1.228 -
1.229 - edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.230 -
1.231 - edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.232 - edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.233 - }
1.234 -
1.235 - g.firstIn(e,n);
1.236 - for(;e!=INVALID;g.nextIn(e))
1.237 - {
1.238 - Gnome::Canvas::Points coos;
1.239 - double x1, x2, y1, y2;
1.240 -
1.241 - nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.242 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.243 -
1.244 - nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.245 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.246 -
1.247 - edgesmap[e]->property_points().set_value(coos);
1.248 -
1.249 - edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.250 -
1.251 - edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.252 - edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.253 - }
1.254 - }
1.255 - default: break;
1.256 - }
1.257 - return true;
1.258 -}
1.259 -
1.260 -bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
1.261 -{
1.262 - Gnome::Canvas::CanvasAA::on_expose_event(event);
1.263 - //usleep(10000);
1.264 - //rezoom();
1.265 - return true;
1.266 -}
1.267 -
1.268 -void GraphDisplayerCanvas::zoomIn()
1.269 -{
1.270 - set_pixels_per_unit(
1.271 - (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
1.272 -}
1.273 -
1.274 -void GraphDisplayerCanvas::zoomOut()
1.275 -{
1.276 - set_pixels_per_unit(
1.277 - (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
1.278 -}
1.279 -
1.280 -void GraphDisplayerCanvas::zoomFit()
1.281 -{
1.282 - // get the height and width of the canvas
1.283 - Gtk::Allocation a = get_allocation();
1.284 - int aw = a.get_width();
1.285 - int ah = a.get_height();
1.286 - // add some space
1.287 - aw -= 5; if (aw < 0) aw = 0;
1.288 - ah -= 5; if (ah < 0) ah = 0;
1.289 - //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
1.290 -
1.291 - // get the bounding box of the graph
1.292 - set_pixels_per_unit(1.0); // I don't really understand why this is necessary
1.293 - double wx1, wy1, wx2, wy2;
1.294 - double cx1, cy1, cx2, cy2;
1.295 - Gnome::Canvas::Item* pCanvasItem = root();
1.296 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.297 - //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
1.298 - w2c(wx1, wy1, cx1, cy1);
1.299 - w2c(wx2, wy2, cx2, cy2);
1.300 - //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
1.301 - //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
1.302 -
1.303 - // fit the graph to the window
1.304 - double ppu1 = (double) aw / fabs(cx2 - cx1);
1.305 - double ppu2 = (double) ah / fabs(cy2 - cy1);
1.306 - //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
1.307 - (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
1.308 -}
1.309 -
1.310 -void GraphDisplayerCanvas::zoom100()
1.311 -{
1.312 - set_pixels_per_unit(1.0);
1.313 -}
1.314 -
1.315 -void GraphDisplayerCanvas::updateScrollRegion()
1.316 -{
1.317 - double wx1, wy1, wx2, wy2;
1.318 - int cx1, cy1, cx2, cy2;
1.319 - Gnome::Canvas::Item* pCanvasItem = root();
1.320 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.321 - w2c(wx1, wy1, cx1, cy1);
1.322 - w2c(wx2, wy2, cx2, cy2);
1.323 - set_scroll_region(cx1, cy1, cx2, cy2);
1.324 -}
1.325 +#include <graph_displayer_canvas.h>
1.326 +#include <math.h>
1.327 +
1.328 +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.329 +{
1.330 + //set_center_scroll_region(true);
1.331 +
1.332 + //first edges are drawn, to hide joining with nodes later
1.333 +
1.334 + for (EdgeIt i(g); i!=INVALID; ++i)
1.335 + {
1.336 +
1.337 + //drawing green lines, coordinates are from cm
1.338 +
1.339 + Gnome::Canvas::Points coos;
1.340 + coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
1.341 + coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
1.342 +
1.343 + edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
1.344 + *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
1.345 + edgesmap[i]->property_width_pixels().set_value(10);
1.346 +
1.347 + //initializing edge-text as well, to empty string
1.348 +
1.349 + double x1, x2, y1, y2;
1.350 + edgesmap[i]->get_bounds(x1, y1, x2, y2);
1.351 +
1.352 + edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
1.353 + edgetextmap[i]->property_fill_color().set_value("black");
1.354 + }
1.355 +
1.356 + //afterwards nodes come to be drawn
1.357 +
1.358 + NodeIt i(g);
1.359 + int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
1.360 +
1.361 + for (; i!=INVALID; ++i)
1.362 + {
1.363 + //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
1.364 +
1.365 + if(cm[i].x>maxx)maxx=(int)cm[i].x;
1.366 + if(cm[i].y>maxy)maxy=(int)cm[i].y;
1.367 + if(cm[i].x<minx)minx=(int)cm[i].x;
1.368 + if(cm[i].y<miny)miny=(int)cm[i].y;
1.369 +
1.370 + //drawing bule nodes, with black line around them
1.371 +
1.372 + 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.373 + *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.374 + *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
1.375 + (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
1.376 + }
1.377 +
1.378 +/*
1.379 + //setting zoom to be able to see the whole graph on the canvas
1.380 +
1.381 + double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
1.382 + double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
1.383 +
1.384 + set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
1.385 + std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
1.386 + std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
1.387 + std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
1.388 +*/
1.389 + updateScrollRegion();
1.390 +}
1.391 +
1.392 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
1.393 +{
1.394 +
1.395 + //writing out the end state of the graph
1.396 + //\todo all the maps has to be write out!
1.397 +
1.398 + Graph::NodeMap <int> id(g);
1.399 + Graph::NodeMap <double> xc(g);
1.400 + Graph::NodeMap <double> yc(g);
1.401 +
1.402 + int j=1;
1.403 +
1.404 + for (NodeIt i(g); i!=INVALID; ++i)
1.405 + {
1.406 + double x1,y1,x2,y2;
1.407 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
1.408 +
1.409 + id[i]=j++;
1.410 + xc[i]=(x1+x2)/2;
1.411 + yc[i]=(y1+y2)/2;
1.412 + }
1.413 +
1.414 + GraphWriter<Graph> writer(std::cout,g);
1.415 +
1.416 + writer.writeNodeMap("id", id);
1.417 + writer.writeNodeMap("coordinates_x", xc);
1.418 + writer.writeNodeMap("coordinates_y", yc);
1.419 + writer.run();
1.420 +}
1.421 +
1.422 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
1.423 +{
1.424 + for (EdgeIt i(g); i!=INVALID; ++i)
1.425 + {
1.426 + int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
1.427 + edgesmap[i]->property_width_pixels().set_value(w);
1.428 + }
1.429 + return 0;
1.430 +};
1.431 +
1.432 +int GraphDisplayerCanvas::changeColor (std::string mapname)
1.433 +{
1.434 +
1.435 + //function maps the range of the maximum and
1.436 + //the minimum of the nodemap to the range of
1.437 + //green in RGB
1.438 +
1.439 + for (EdgeIt i(g); i!=INVALID; ++i)
1.440 + {
1.441 + double w=(*(mapstorage.edgemap_storage)[mapname])[i];
1.442 + double max=mapstorage.maxOfEdgeMap(mapname);
1.443 + double min=mapstorage.minOfEdgeMap(mapname);
1.444 +
1.445 + //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
1.446 + Gdk::Color color;
1.447 + if(max!=min)
1.448 + {
1.449 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
1.450 + }
1.451 + else
1.452 + {
1.453 + color.set_rgb_p (0, 100, 0);
1.454 + }
1.455 +
1.456 + edgesmap[i]->property_fill_color_gdk().set_value(color);
1.457 + }
1.458 + return 0;
1.459 +};
1.460 +
1.461 +int GraphDisplayerCanvas::changeText (std::string mapname)
1.462 +{
1.463 +
1.464 + //the number in the map will be written on the edge
1.465 + //EXCEPT when the name of the map is Text, because
1.466 + //in that case empty string will be written, because
1.467 + //that is the deleter map
1.468 + //\todo isn't it a bit woodcutter?
1.469 +
1.470 + for (EdgeIt i(g); i!=INVALID; ++i)
1.471 + {
1.472 + if(mapname!="Text")
1.473 + {
1.474 + double number=(*(mapstorage.edgemap_storage)[mapname])[i];
1.475 + int length=(int)(floor(log(number)/log(10)))+1;
1.476 + int maxpos=(int)(pow(10,length-1));
1.477 + int strl=length+1+RANGE;
1.478 + char * str=new char[strl];
1.479 + str[length]='.';
1.480 + str[strl]='\0';
1.481 +
1.482 + for(int j=0;j<strl;j++)
1.483 + {
1.484 + if(j!=length)
1.485 + {
1.486 + int digit=(int)(number/maxpos);
1.487 + str[j]=(digit+'0');
1.488 + number-=digit*maxpos;
1.489 + number*=10;
1.490 + }
1.491 + }
1.492 +
1.493 + edgetextmap[i]->property_text().set_value(str);
1.494 + }
1.495 + else
1.496 + {
1.497 + edgetextmap[i]->property_text().set_value("");
1.498 + }
1.499 + }
1.500 + return 0;
1.501 +};
1.502 +
1.503 +bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
1.504 +{
1.505 + switch(e->type)
1.506 + {
1.507 + case GDK_BUTTON_PRESS:
1.508 + //we mark the location of the event to be able to calculate parameters of dragging
1.509 + clicked_x=e->button.x;
1.510 + clicked_y=e->button.y;
1.511 + active_item=(get_item_at(e->button.x, e->button.y));
1.512 + isbutton=true;
1.513 + break;
1.514 + case GDK_BUTTON_RELEASE:
1.515 + isbutton=false;
1.516 + active_item=NULL;
1.517 + break;
1.518 + case GDK_MOTION_NOTIFY:
1.519 + //we only have to do sg. if the mouse button is pressed
1.520 + if(isbutton)
1.521 + {
1.522 + //new coordinates will be the old values,
1.523 + //because the item will be moved to the
1.524 + //new coordinate therefore the new movement
1.525 + //has to be calculated from here
1.526 +
1.527 + double dx=e->motion.x-clicked_x;
1.528 + double dy=e->motion.y-clicked_y;
1.529 + active_item->move(dx, dy);
1.530 + clicked_x=e->motion.x;
1.531 + clicked_y=e->motion.y;
1.532 +
1.533 + //all the edges connected to the moved point has to be redrawn
1.534 +
1.535 + EdgeIt e;
1.536 + g.firstOut(e,n);
1.537 + for(;e!=INVALID;g.nextOut(e))
1.538 + {
1.539 + Gnome::Canvas::Points coos;
1.540 + double x1, x2, y1, y2;
1.541 +
1.542 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.543 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.544 +
1.545 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.546 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.547 +
1.548 + edgesmap[e]->property_points().set_value(coos);
1.549 +
1.550 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.551 +
1.552 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.553 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.554 + }
1.555 +
1.556 + g.firstIn(e,n);
1.557 + for(;e!=INVALID;g.nextIn(e))
1.558 + {
1.559 + Gnome::Canvas::Points coos;
1.560 + double x1, x2, y1, y2;
1.561 +
1.562 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.563 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.564 +
1.565 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.566 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.567 +
1.568 + edgesmap[e]->property_points().set_value(coos);
1.569 +
1.570 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.571 +
1.572 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.573 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.574 + }
1.575 + }
1.576 + default: break;
1.577 + }
1.578 + return true;
1.579 +}
1.580 +
1.581 +bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
1.582 +{
1.583 + Gnome::Canvas::CanvasAA::on_expose_event(event);
1.584 + //usleep(10000);
1.585 + //rezoom();
1.586 + return true;
1.587 +}
1.588 +
1.589 +void GraphDisplayerCanvas::zoomIn()
1.590 +{
1.591 + set_pixels_per_unit(
1.592 + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
1.593 +}
1.594 +
1.595 +void GraphDisplayerCanvas::zoomOut()
1.596 +{
1.597 + set_pixels_per_unit(
1.598 + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
1.599 +}
1.600 +
1.601 +void GraphDisplayerCanvas::zoomFit()
1.602 +{
1.603 + // get the height and width of the canvas
1.604 + Gtk::Allocation a = get_allocation();
1.605 + int aw = a.get_width();
1.606 + int ah = a.get_height();
1.607 + // add some space
1.608 + aw -= 5; if (aw < 0) aw = 0;
1.609 + ah -= 5; if (ah < 0) ah = 0;
1.610 + //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
1.611 +
1.612 + // get the bounding box of the graph
1.613 + set_pixels_per_unit(1.0); // I don't really understand why this is necessary
1.614 + double wx1, wy1, wx2, wy2;
1.615 + double cx1, cy1, cx2, cy2;
1.616 + Gnome::Canvas::Item* pCanvasItem = root();
1.617 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.618 + //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
1.619 + w2c(wx1, wy1, cx1, cy1);
1.620 + w2c(wx2, wy2, cx2, cy2);
1.621 + //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
1.622 + //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
1.623 +
1.624 + // fit the graph to the window
1.625 + double ppu1 = (double) aw / fabs(cx2 - cx1);
1.626 + double ppu2 = (double) ah / fabs(cy2 - cy1);
1.627 + //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
1.628 + (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
1.629 +}
1.630 +
1.631 +void GraphDisplayerCanvas::zoom100()
1.632 +{
1.633 + set_pixels_per_unit(1.0);
1.634 +}
1.635 +
1.636 +void GraphDisplayerCanvas::updateScrollRegion()
1.637 +{
1.638 + double wx1, wy1, wx2, wy2;
1.639 + int cx1, cy1, cx2, cy2;
1.640 + Gnome::Canvas::Item* pCanvasItem = root();
1.641 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.642 + w2c(wx1, wy1, cx1, cy1);
1.643 + w2c(wx2, wy2, cx2, cy2);
1.644 + set_scroll_region(cx1, cy1, cx2, cy2);
1.645 +}