COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
07/29/05 14:01:37 (15 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2111
Message:

added support for saving files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas.cc

    r1599 r1606  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
    5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw)
     5GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) :
     6  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
     7  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
     8  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
     9  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
    610{
    7  
    8   //Initializing values.
    9   active_node=INVALID;
    10   active_edge=INVALID;
    11   forming_edge=INVALID;
     11  //base event handler is move tool
     12  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
     13  actual_tool=MOVE;
    1214
    1315  //setting event handler for the editor widget
    1416  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
    1517
    16   //base event handler is move tool
    17   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    18   actual_tool=MOVE;
     18  active_node=INVALID;
     19  active_edge=INVALID;
     20  forming_edge=INVALID;
     21}
    1922
    20   //set_center_scroll_region(true);
     23GraphDisplayerCanvas::~GraphDisplayerCanvas()
     24{
     25  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
     26  {
     27    delete nodesmap[n];
     28    delete nodetextmap[n];
     29  }
    2130
     31  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
     32  {
     33    delete edgesmap[e];
     34    delete edgetextmap[e];
     35  }
     36
     37  if(canvasentrywidget)
     38  {
     39    delete(canvasentrywidget);
     40  }
     41}
     42
     43void GraphDisplayerCanvas::drawGraph()
     44{
    2245  //first edges are drawn, to hide joining with nodes later
    2346
    24   for (EdgeIt i(g); i!=INVALID; ++i)
     47  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    2548  {
    2649
    27     //drawing green lines, coordinates are from cm
     50    //drawing green lines, coordinates are from mapstorage.coords
    2851
    2952    Gnome::Canvas::Points coos;
    30     coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    31     coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
     53    coos.push_back(Gnome::Art::Point(
     54          mapstorage.coords[mapstorage.graph.source(i)].x,
     55          mapstorage.coords[mapstorage.graph.source(i)].y));
     56    coos.push_back(Gnome::Art::Point(
     57          mapstorage.coords[mapstorage.graph.target(i)].x,
     58          mapstorage.coords[mapstorage.graph.target(i)].y));
    3259   
    3360    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
     
    4774  //afterwards nodes come to be drawn
    4875
    49   NodeIt i(g);
    50   int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
    51 
    52   for (; i!=INVALID; ++i)
     76  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    5377  {
    54     //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
    55 
    56     if(cm[i].x>maxx)maxx=(int)cm[i].x;
    57     if(cm[i].y>maxy)maxy=(int)cm[i].y;
    58     if(cm[i].x<minx)minx=(int)cm[i].x;
    59     if(cm[i].y<miny)miny=(int)cm[i].y;
    60 
    6178    //drawing bule nodes, with black line around them
    6279
    63     nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
     80    nodesmap[i]=new Gnome::Canvas::Ellipse(
     81        displayed_graph,
     82        mapstorage.coords[i].x-20,
     83        mapstorage.coords[i].y-20,
     84        mapstorage.coords[i].x+20,
     85        mapstorage.coords[i].y+20);
    6486    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    6587    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
     
    6789    //initializing edge-text as well, to empty string
    6890
    69     xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
     91    xy<double> text_pos(
     92        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
     93        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
    7094
    71     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
     95    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
     96        text_pos.x, text_pos.y, "");
    7297    nodetextmap[i]->property_fill_color().set_value("darkblue");
    7398    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
     
    77102}
    78103
    79 GraphDisplayerCanvas::~GraphDisplayerCanvas()
     104void GraphDisplayerCanvas::clear()
    80105{
    81   if(canvasentrywidget)
    82     {
    83       delete(canvasentrywidget);
    84     }
     106  active_node=INVALID;
     107  active_edge=INVALID;
     108  forming_edge=INVALID;
    85109
    86   //writing out the end state of the graph
    87   //\todo all the maps has to be write out!
    88 
    89   Graph::NodeMap <int> id(g);
    90   Graph::NodeMap <double> xc(g);
    91   Graph::NodeMap <double> yc(g);
    92  
    93   int j=1;
    94  
    95   for (NodeIt i(g); i!=INVALID; ++i)
     110  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    96111  {
    97     double x1,y1,x2,y2;
    98     nodesmap[i]->get_bounds(x1, y1, x2, y2);
    99    
    100     id[i]=j++;
    101     xc[i]=(x1+x2)/2;
    102     yc[i]=(y1+y2)/2;
     112    delete nodesmap[n];
     113    delete nodetextmap[n];
    103114  }
    104115
    105   GraphWriter<Graph> writer(std::cout,g);
    106  
    107   writer.writeNodeMap("id", id);
    108   writer.writeNodeMap("coordinates_x", xc);
    109   writer.writeNodeMap("coordinates_y", yc);
    110   writer.run();
     116  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
     117  {
     118    delete edgesmap[e];
     119    delete edgetextmap[e];
     120  }
    111121}
Note: See TracChangeset for help on using the changeset viewer.