COIN-OR::LEMON - Graph Library

Changeset 1441:fd4b6f6d592a in lemon-0.x


Ignore:
Timestamp:
06/02/05 01:30:13 (20 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1917
Message:
Location:
gui
Files:
4 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}
  • gui/graph_displayer_canvas.h

    r1440 r1441  
    3030  int changeText (std::string mapname);
    3131
    32   ///Changes the dot-pro-pixel to be able to show the whole graph.
    33   int rezoom();
     32  ///Callback for 'ViewZoomIn' action.
     33  virtual void zoomIn();
     34  ///Callback for 'ViewZoomOut' action.
     35  virtual void zoomOut();
     36  ///Callback for 'ViewZoomFit' action.
     37  virtual void zoomFit();
     38  ///Callback for 'ViewZoom100' action.
     39  virtual void zoom100();
     40  ///Sets the scroll region of the convas to the bounding box of the graph.
     41  void updateScrollRegion();
    3442
    3543protected:
     
    7684  Gnome::Canvas::Item * active_item;
    7785
    78 
     86  static const int zoom_step = 5;
    7987};
    8088
  • gui/main_win.cc

    r1435 r1441  
    11#include <main_win.h>
    22
    3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
     3MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
     4    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
    45{
    56  set_title (title);
     
    89
    910  ag=Gtk::ActionGroup::create();
     11
     12  ag->add( Gtk::Action::create("FileMenu", "_File") );
     13  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
     14      sigc::mem_fun(*this, &MainWin::newFile));
     15  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
     16      sigc::mem_fun(*this, &MainWin::openFile));
     17  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
     18      sigc::mem_fun(*this, &MainWin::saveFile));
     19  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
     20      sigc::mem_fun(*this, &MainWin::saveFileAs));
     21  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
     22      sigc::mem_fun(*this, &MainWin::quit));
     23
     24  ag->add( Gtk::Action::create("ViewMenu", "_View") );
     25  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
     26      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
     27  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
     28      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
     29  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
     30      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
     31  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
     32      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
     33 
    1034  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
    11   ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps));
    12   ag->add( Gtk::Action::create("FileMenu", "_File") );
    13   ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit));
    14   ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") );
    15   ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!!
     35  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
     36      sigc::mem_fun(*this, &MainWin::showMaps));
    1637
    1738  uim=Gtk::UIManager::create();
     
    2647      "  <menubar name='MenuBar'>"
    2748      "    <menu action='FileMenu'>"
     49      "      <menuitem action='FileNew'/>"
     50      "      <menuitem action='FileOpen'/>"
     51      "      <menuitem action='FileSave'/>"
     52      "      <menuitem action='FileSaveAs'/>"
    2853      "      <menuitem action='FileQuit'/>"
     54      "    </menu>"
     55      "    <menu action='ViewMenu'>"
     56      "      <menuitem action='ViewZoomIn' />"
     57      "      <menuitem action='ViewZoomOut' />"
     58      "      <menuitem action='ViewZoomFit' />"
     59      "      <menuitem action='ViewZoom100' />"
    2960      "    </menu>"
    3061      "    <menu action='ShowMenu'>"
    3162      "      <menuitem action='ShowMaps'/>"
    3263      "    </menu>"
    33       "    <menu action='ZoomMenu'>"
    34       "      <menuitem action='ZoomRezoom'/>"
    35       "    </menu>"
    3664      "  </menubar>"
     65      "  <toolbar name='ToolBar'>"
     66      "    <toolitem action='FileNew' />"
     67      "    <toolitem action='FileOpen' />"
     68      "    <toolitem action='FileSave' />"
     69      "    <separator />"
     70      "    <toolitem action='ViewZoomIn' />"
     71      "    <toolitem action='ViewZoomOut' />"
     72      "    <toolitem action='ViewZoomFit' />"
     73      "    <toolitem action='ViewZoom100' />"
     74      "  </toolbar>"
    3775      "</ui>";
    3876
     
    4684
    4785  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
    48   if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
     86  if (menubar){
     87    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
     88  }
    4989
    50   vbox.pack_start(gd_canvas);
     90  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
     91  if (toolbar)
     92  {
     93    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
     94    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
     95  }
     96
     97  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
     98  pScrolledWindow->add(gd_canvas);
     99  vbox.pack_start(*pScrolledWindow);
     100  //vbox.pack_start(gd_canvas);
    51101
    52102  show_all_children();
     
    63113}
    64114
    65 void MainWin::rezoom()
     115void MainWin::newFile()
    66116{
    67   gd_canvas.rezoom();
     117  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
    68118}
    69119
     120void MainWin::openFile()
     121{
     122  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
     123}
     124
     125void MainWin::saveFile()
     126{
     127  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
     128}
     129
     130void MainWin::saveFileAs()
     131{
     132  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
     133}
  • gui/main_win.h

    r1440 r1441  
    4040  ///This function makes map-setup window popped up.
    4141  virtual void showMaps();
    42 
    43   ///Exit
     42  ///Callback for 'FileNew' action.
     43  virtual void newFile();
     44  ///Callback for 'FileOpen' action.
     45  virtual void openFile();
     46  ///Callback for 'FileSave' action.
     47  virtual void saveFile();
     48  ///Callback for 'FileSaveAs' action.
     49  virtual void saveFileAs();
     50  ///Callback for 'Quit' action.
    4451  virtual void quit();
    45 
    46   ///Refit screen to be able to show the whole graph.
    47   virtual void rezoom();
    48 
    4952};
    5053
Note: See TracChangeset for help on using the changeset viewer.