gui/graph_displayer_canvas.cc
author athos
Fri, 01 Jul 2005 10:33:27 +0000
changeset 1527 7ceab500e1f6
parent 1524 587a823bcdd0
child 1550 4dcbb4ab1d7a
permissions -rwxr-xr-x
Doc review+corrections in my own documentation according to the reviewers comments.
ladanyi@1442
     1
#include <graph_displayer_canvas.h>
hegyi@1497
     2
#include <broken_edge.h>
ladanyi@1442
     3
#include <math.h>
ladanyi@1442
     4
hegyi@1512
     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),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),mapwin(mw)
ladanyi@1442
     6
{
hegyi@1468
     7
  
hegyi@1525
     8
  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
hegyi@1501
     9
  actual_tool=CREATE_NODE;
hegyi@1468
    10
hegyi@1478
    11
  active_node=INVALID;
hegyi@1478
    12
  active_edge=INVALID;
hegyi@1478
    13
ladanyi@1442
    14
  //set_center_scroll_region(true);
ladanyi@1442
    15
ladanyi@1442
    16
  //first edges are drawn, to hide joining with nodes later
ladanyi@1442
    17
ladanyi@1442
    18
  for (EdgeIt i(g); i!=INVALID; ++i)
ladanyi@1442
    19
  {
ladanyi@1442
    20
ladanyi@1442
    21
    //drawing green lines, coordinates are from cm
ladanyi@1442
    22
ladanyi@1442
    23
    Gnome::Canvas::Points coos;
ladanyi@1442
    24
    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
ladanyi@1442
    25
    coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
ladanyi@1442
    26
    
hegyi@1501
    27
    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
ladanyi@1442
    28
    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
ladanyi@1442
    29
    edgesmap[i]->property_width_pixels().set_value(10);    
ladanyi@1442
    30
    
ladanyi@1442
    31
    //initializing edge-text as well, to empty string
ladanyi@1442
    32
hegyi@1524
    33
    xy<double> text_pos=edgesmap[i]->getArrowPos();
hegyi@1505
    34
    text_pos+=(xy<double>(10,10));
hegyi@1505
    35
hegyi@1505
    36
    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
hegyi@1512
    37
    edgetextmap[i]->property_fill_color().set_value("darkgreen");
ladanyi@1442
    38
  }
ladanyi@1442
    39
ladanyi@1442
    40
  //afterwards nodes come to be drawn
ladanyi@1442
    41
ladanyi@1442
    42
  NodeIt i(g);
ladanyi@1442
    43
  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
ladanyi@1442
    44
ladanyi@1442
    45
  for (; i!=INVALID; ++i)
ladanyi@1442
    46
  {
ladanyi@1442
    47
    //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
ladanyi@1442
    48
ladanyi@1442
    49
    if(cm[i].x>maxx)maxx=(int)cm[i].x;
ladanyi@1442
    50
    if(cm[i].y>maxy)maxy=(int)cm[i].y;
ladanyi@1442
    51
    if(cm[i].x<minx)minx=(int)cm[i].x;
ladanyi@1442
    52
    if(cm[i].y<miny)miny=(int)cm[i].y;
ladanyi@1442
    53
ladanyi@1442
    54
    //drawing bule nodes, with black line around them
ladanyi@1442
    55
ladanyi@1442
    56
    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
ladanyi@1442
    57
    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
ladanyi@1442
    58
    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@1512
    59
hegyi@1512
    60
    //initializing edge-text as well, to empty string
hegyi@1512
    61
hegyi@1512
    62
    xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
hegyi@1512
    63
hegyi@1512
    64
    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
hegyi@1512
    65
    nodetextmap[i]->property_fill_color().set_value("darkblue");
ladanyi@1442
    66
  }
ladanyi@1442
    67
ladanyi@1442
    68
  updateScrollRegion();
ladanyi@1442
    69
}
ladanyi@1442
    70
ladanyi@1442
    71
GraphDisplayerCanvas::~GraphDisplayerCanvas()
ladanyi@1442
    72
{
ladanyi@1442
    73
ladanyi@1442
    74
  //writing out the end state of the graph
ladanyi@1442
    75
  //\todo all the maps has to be write out!
ladanyi@1442
    76
ladanyi@1442
    77
  Graph::NodeMap <int> id(g);
ladanyi@1442
    78
  Graph::NodeMap <double> xc(g);
ladanyi@1442
    79
  Graph::NodeMap <double> yc(g);
ladanyi@1442
    80
  
ladanyi@1442
    81
  int j=1;
ladanyi@1442
    82
  
ladanyi@1442
    83
  for (NodeIt i(g); i!=INVALID; ++i)
ladanyi@1442
    84
  {
ladanyi@1442
    85
    double x1,y1,x2,y2;
ladanyi@1442
    86
    nodesmap[i]->get_bounds(x1, y1, x2, y2);
ladanyi@1442
    87
    
ladanyi@1442
    88
    id[i]=j++;
ladanyi@1442
    89
    xc[i]=(x1+x2)/2;
ladanyi@1442
    90
    yc[i]=(y1+y2)/2;
ladanyi@1442
    91
  }
ladanyi@1442
    92
ladanyi@1442
    93
  GraphWriter<Graph> writer(std::cout,g);
ladanyi@1442
    94
  
ladanyi@1442
    95
  writer.writeNodeMap("id", id);
ladanyi@1442
    96
  writer.writeNodeMap("coordinates_x", xc);
ladanyi@1442
    97
  writer.writeNodeMap("coordinates_y", yc);
ladanyi@1442
    98
  writer.run();
ladanyi@1442
    99
}