COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
06/02/05 01:30:13 (16 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1917
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas.cc

    r1440 r1441  
    44GraphDisplayerCanvas::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)
    55{
     6  //set_center_scroll_region(true);
    67
    78  //first edges are drawn, to hide joining with nodes later
     
    5152  }
    5253
     54/*
    5355  //setting zoom to be able to see the whole graph on the canvas
    5456
     
    6062  std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
    6163  std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
    62 
     64*/
     65  updateScrollRegion();
    6366}
    6467
     
    174177};
    175178
    176 
    177 int GraphDisplayerCanvas::rezoom ()
    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 
    186   double x1, x2, y1, y2;
    187   int x,y;
    188 
    189   NodeIt i(g);
    190   nodesmap[i]->get_bounds(x1, y1, x2, y2);
    191 
    192   x=(int)((x1+x2)/2);
    193   y=(int)((y1+y2)/2);
    194  
    195   int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
    196 
    197   for (; i!=INVALID; ++i)
    198   {
    199     nodesmap[i]->get_bounds(x1, y1, x2, y2);
    200 
    201     x=(int)((x1+x2)/2);
    202     y=(int)((y1+y2)/2);
    203 
    204     if(x>maxx)maxx=x;
    205     if(y>maxy)maxy=y;
    206     if(x<minx)minx=x;
    207     if(y<miny)miny=y;
    208   }
    209 
    210   double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    211   double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
    212 
    213   set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
    214   return 0;
    215 };
    216 
    217 
    218179bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
    219180{
     
    301262  return true;
    302263}
     264
     265void GraphDisplayerCanvas::zoomIn()
     266{
     267  set_pixels_per_unit(
     268      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
     269}
     270
     271void GraphDisplayerCanvas::zoomOut()
     272{
     273  set_pixels_per_unit(
     274      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
     275}
     276
     277void GraphDisplayerCanvas::zoomFit()
     278{
     279  // get the height and width of the canvas
     280  Gtk::Allocation a = get_allocation();
     281  int aw = a.get_width();
     282  int ah = a.get_height();
     283  // add some space
     284  aw -= 5; if (aw < 0) aw = 0;
     285  ah -= 5; if (ah < 0) ah = 0;
     286  //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
     287
     288  // get the bounding box of the graph
     289  set_pixels_per_unit(1.0); // I don't really understand why this is necessary
     290  double wx1, wy1, wx2, wy2;
     291  double cx1, cy1, cx2, cy2;
     292  Gnome::Canvas::Item* pCanvasItem = root();
     293  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
     294  //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
     295  w2c(wx1, wy1, cx1, cy1);
     296  w2c(wx2, wy2, cx2, cy2);
     297  //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
     298  //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
     299
     300  // fit the graph to the window
     301  double ppu1 = (double) aw / fabs(cx2 - cx1);
     302  double ppu2 = (double) ah / fabs(cy2 - cy1);
     303  //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
     304  (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
     305}
     306
     307void GraphDisplayerCanvas::zoom100()
     308{
     309  set_pixels_per_unit(1.0);
     310}
     311
     312void GraphDisplayerCanvas::updateScrollRegion()
     313{
     314  double wx1, wy1, wx2, wy2;
     315  int cx1, cy1, cx2, cy2;
     316  Gnome::Canvas::Item* pCanvasItem = root();
     317  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
     318  w2c(wx1, wy1, cx1, cy1);
     319  w2c(wx2, wy2, cx2, cy2);
     320  set_scroll_region(cx1, cy1, cx2, cy2);
     321}
Note: See TracChangeset for help on using the changeset viewer.