COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
05/27/05 12:34:20 (19 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1915
Message:

Small documentation is added to GUI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas.cc

    r1435 r1440  
    11#include <graph_displayer_canvas.h>
     2#include <math.h>
    23
    34GraphDisplayerCanvas::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)
    45{
    56
     7  //first edges are drawn, to hide joining with nodes later
     8
    69  for (EdgeIt i(g); i!=INVALID; ++i)
    710  {
     11
     12    //drawing green lines, coordinates are from cm
     13
    814    Gnome::Canvas::Points coos;
    915    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
     
    1218    edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
    1319    *(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);   
    1521   
    16    
     22    //initializing edge-text as well, to empty string
     23
    1724    double x1, x2, y1, y2;
    1825    edgesmap[i]->get_bounds(x1, y1, x2, y2);
     
    2229  }
    2330
     31  //afterwards nodes come to be drawn
     32
    2433  NodeIt i(g);
    2534  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
     
    2736  for (; i!=INVALID; ++i)
    2837  {
     38    //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
     39
    2940    if(cm[i].x>maxx)maxx=(int)cm[i].x;
    3041    if(cm[i].y>maxy)maxy=(int)cm[i].y;
     
    3243    if(cm[i].y<miny)miny=(int)cm[i].y;
    3344
     45    //drawing bule nodes, with black line around them
     46
    3447    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
    3548    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
     
    3851  }
    3952
     53  //setting zoom to be able to see the whole graph on the canvas
     54
    4055  double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    4156  double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
     
    5065GraphDisplayerCanvas::~GraphDisplayerCanvas()
    5166{
    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();
    7493}
    7594
     
    86105int GraphDisplayerCanvas::changeColor (std::string mapname)
    87106
     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
    88112  for (EdgeIt i(g); i!=INVALID; ++i)
    89113  {
     
    110134int GraphDisplayerCanvas::changeText (std::string mapname)
    111135{
     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
    112143  for (EdgeIt i(g); i!=INVALID; ++i)
    113144  {
     
    146177int GraphDisplayerCanvas::rezoom ()
    147178{
     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
    148186  double x1, x2, y1, y2;
    149187  int x,y;
     
    178216
    179217
    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.
    183218bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
    184219{
     
    186221  {
    187222    case GDK_BUTTON_PRESS:
     223      //we mark the location of the event to be able to calculate parameters of dragging
    188224      clicked_x=e->button.x;
    189225      clicked_y=e->button.y;
     
    196232      break;
    197233    case GDK_MOTION_NOTIFY:
     234      //we only have to do sg. if the mouse button is pressed
    198235      if(isbutton)
    199236      {
     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
    200242        double dx=e->motion.x-clicked_x;
    201243        double dy=e->motion.y-clicked_y;
     
    204246        clicked_y=e->motion.y;
    205247
     248        //all the edges connected to the moved point has to be redrawn
     249
    206250        EdgeIt e;
    207 
    208251        g.firstOut(e,n);
    209252        for(;e!=INVALID;g.nextOut(e))
Note: See TracChangeset for help on using the changeset viewer.