COIN-OR::LEMON - Graph Library

Changeset 4:e099638ff236 in glemon-0.x


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

Small documentation is added to GUI

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • graph-displayer.cc

    r1 r4  
    1313int main(int argc, char *argv[])
    1414{
     15
     16  //initializing
     17
    1518  property_strings=new std::string[PROPERTY_NUM];
    1619  property_strings[WIDTH]="Width";
     
    3538  CoordinatesMap cm(g);
    3639  Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
     40  Graph::NodeMap<double> nodedata (g);
    3741
    3842  //we create one object to read x coordinates
    3943  //and one to read y coordinate of nodes and write them to cm NodeMap.
    40 
    4144  XMap <CoordinatesMap> xreader (cm);
    4245  YMap <CoordinatesMap> yreader (cm);
    43   Graph::NodeMap<double> nodedata (g);
     46
     47  //reading in graph and its maps
    4448
    4549  std::ifstream is(argv[1]);
     
    5660  reader.run();
    5761
     62  //initializing MapStorage with the read data
     63
    5864  MapStorage ms(g);
    5965  ms.addNodeMap("data",&nodedata);
     
    6369  ms.addEdgeMap("map3",&map3);
    6470  ms.addEdgeMap("map4",&map4);
     71
     72  //initializing GUI
    6573
    6674  Gnome::Canvas::init();
  • graph_displayer_canvas.cc

    r1 r4  
    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))
  • graph_displayer_canvas.h

    r1 r4  
    99#include <libgnomecanvasmm/polygon.h>
    1010
     11///This class is the canvas, on which the graph can be drawn.
    1112class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    1213{
     
    1718  virtual ~GraphDisplayerCanvas();
    1819
     20  ///Changes the linewidth attribute according to the given map.
     21  ///\param mapname is the name of the map which contains the new values
    1922  int changeLineWidth (std::string mapname);
     23
     24  ///Changes the linecolor attribute according to the given map.
     25  ///\param mapname is the name of the map which contains the new values
    2026  int changeColor (std::string mapname);
     27
     28  ///Changes the text of line attribute according to the given map.
     29  ///\param mapname is the name of the map which contains the new values
    2130  int changeText (std::string mapname);
     31
     32  ///Changes the dot-pro-pixel to be able to show the whole graph.
    2233  int rezoom();
    2334
    2435protected:
    2536
     37  //maximizing, minimizing, restoring window, etc.
    2638  virtual bool on_expose_event(GdkEventExpose *);
    2739
    2840private:
    2941
    30   ///Event handler function that handles dragging nodes of displayed_graph
     42  ///This function is responsible for the correct
     43  ///reaction of any action happened in the territory
     44  ///of the canvas
    3145  bool event_handler(GdkEvent* e, Node n);
    3246
    3347  ///The graph, on which we work
    3448  Graph g;
    35   ///Map of nodes of planefigure
     49
     50  ///Map of nodes of graph
    3651  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
    37   ///Map of edges of planefigure
     52
     53  ///Map of edges of graph
    3854  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
    3955
  • main_win.h

    r1 r4  
    1010#include <libgnomecanvasmm/polygon.h>
    1111
     12///This class is the main window of GUI.
     13///It has menus, but the main part of it is the canvas.
    1214class MainWin : public Gtk::Window
    1315{
    1416public:
     17  ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
     18  ///\param title is the title of the window
     19  ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
     20  ///\param cm stores the coordinates of the nodes of the graph
     21  ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
    1522  MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
    1623
    1724protected:
    18   //Window of map-showing setup
     25  ///Window of map-showing setup. Its type is \ref MapWin
    1926  MapWin mapwin;
    2027
    21   //Member widgets:
     28  ///The graph will be drawn on this \ref GraphDisplayerCanvas
    2229  GraphDisplayerCanvas gd_canvas;
    2330
    24   //ActionGroup for menu
     31  ///ActionGroup for menu
    2532  Glib::RefPtr<Gtk::ActionGroup> ag;
    2633
    27   //UIManager for menu
     34  ///UIManager for menu
    2835  Glib::RefPtr<Gtk::UIManager> uim;
    2936
    30   //Container
     37  ///Container
    3138  Gtk::VBox vbox;
    3239
    33   //Pops up map-setup window
     40  ///This function makes map-setup window popped up.
    3441  virtual void showMaps();
    3542
    36   //Exit
     43  ///Exit
    3744  virtual void quit();
    3845
    39   //Refit screen
     46  ///Refit screen to be able to show the whole graph.
    4047  virtual void rezoom();
    4148
  • map_win.cc

    r1 r4  
    44MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
    55{
     6
     7  //most nem kommentezem fel, mert ugyis valtozik
     8
    69  set_title(title);
    710  set_default_size(400, 200);
     
    8992void MapWin::radio_click(int prop, int actpos)
    9093{
     94
     95  //most nem kommentezem fel, mert ugyis valtozik
     96
    9197  if(rb_array[prop][actpos].get_active())
    9298  {
  • map_win.h

    r1 r4  
    1010#include <libgnomecanvasmm/polygon.h>
    1111
     12///This class is responsible for creating a window,
     13///on which the visualization attributes can be
     14///assigned to maps.
    1215class MapWin : public Gtk::Window
    1316{
    1417protected:
     18  ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
     19  ///It has to be known for this class, because
     20  ///when a map assigned to a certain attribute
     21  ///a function of the \ref GraphDisplayerCanvas will be called.
    1522  GraphDisplayerCanvas & gdc;
     23
     24  ///The \ref MapStorage in which the visualizable maps are stored
    1625  MapStorage & ms;
    1726
     27 
    1828  Gtk::HBox * radios;
    1929  Gtk::RadioButton ** rb_array;
    2030
    2131  Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
     32
     33  ///The notebook has different pages for each attribute.
    2234  Gtk::Notebook notebook;
     35
    2336  Gtk::Label * labels;
    2437
    2538public:
     39  ///Constructor of MapWin creates the widgets shown in MapWin.
    2640  MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
     41
     42  ///If a radiobutton is clicked, this function determines
     43  ///which button was that and after that calls the
     44  ///appropriate function of the \ref GraphDisplayerCanvas
     45  ///to change the visible values of that attribute.
    2746  virtual void radio_click(int, int);
    2847};
  • mapstorage.cc

    r1 r4  
    1010    default_nodemaps.push_back(nmd);
    1111  }
    12 
    13   //std::string defaultstr="Default ";
    1412  for(int i=0;i<PROPERTY_NUM;i++)
    1513  {
     
    2826  return 0;
    2927}
     28
    3029int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
    3130{
  • mapstorage.h

    r1 r4  
    66#include <all_include.h>
    77
     8///Class MapStorage is responsible for storing
     9///NodeMaps and EdgeMaps that can be shown later
     10///on GUI. Therefore maps can be added to it,
     11///and datas over the added maps can be queried.
     12///The maps will be stored in an std::map,
     13///referenced with their names. Unfortunately at
     14///the moment it works only with double type maps
     15///
     16///\todo too many things are public!!
    817class MapStorage
    918{
     19public:
    1020
    11 public: ///!!!!!!!!
    1221  Graph g;
     22
     23  ///Stores double type NodeMaps
    1324  std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
     25
     26  ///Stores double type EdgeMaps
    1427  std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
    1528
     29  //Stores the default values for the different visualization node attributes
    1630  std::vector<Graph::NodeMap<double> > default_nodemaps;
     31
     32  //Stores the default values for the different visualization edge attributes
    1733  std::vector<Graph::EdgeMap<double> > default_edgemaps;
    1834
    1935public:
     36  ///Constructor of MapStorage. Expects the Graph of
     37  ///which maps will be stored in it.
     38  ///Its all activity is initializing default values
     39  ///for different visualization attributes
     40  ///
     41  ///\param graph is the graph for which the maps are stored in this object.
    2042  MapStorage(Graph &);
     43
     44  ///Adds given map to storage. A name and the map itself has to be provided.
     45  ///\param name is the name of map
     46  ///\nodemap is the pointer of the given nodemap
     47  ///\todo map should be given by reference!
    2148  int addNodeMap(const std::string &,Graph::NodeMap<double> *);
     49
     50  ///Adds given map to storage. A name and the map itself has to be provided.
     51  ///\param name is the name of map
     52  ///\edgemap is the pointer of the given edgemap
     53  ///\todo map should be given by reference!
    2254  int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
    2355
     56  ///Returns how much nodemaps is stored in \ref MapStorage
    2457  int numOfNodeMaps() {return nodemap_storage.size();};
     58
     59  ///Returns how much edgemaps is stored in \ref MapStorage
    2560  int numOfEdgeMaps() {return edgemap_storage.size();};
    2661
     62  ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
     63  ///\param name is the name of map of which maximum is searched
    2764  double maxOfNodeMap(const std::string &);
     65
     66  ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
     67  ///\param name is the name of map of which maximum is searched
    2868  double maxOfEdgeMap(const std::string &);
    2969
     70  ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
     71  ///\param name is the name of map of which minimum is searched
    3072  double minOfNodeMap(const std::string &);
     73
     74  ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
     75  ///\param name is the name of map of which minimum is searched
    3176  double minOfEdgeMap(const std::string &);
    3277
     78  ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
    3379  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
     80
     81  ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
    3482  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
    3583};
Note: See TracChangeset for help on using the changeset viewer.