COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas.cc @ 1606:dc4ea2010dee

Last change on this file since 1606:dc4ea2010dee was 1606:dc4ea2010dee, checked in by Akos Ladanyi, 15 years ago

added support for saving files

  • Property exe set to *
File size: 3.7 KB
Line 
1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
3#include <math.h>
4
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)
10{
11  //base event handler is move tool
12  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
13  actual_tool=MOVE;
14
15  //setting event handler for the editor widget
16  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
17
18  active_node=INVALID;
19  active_edge=INVALID;
20  forming_edge=INVALID;
21}
22
23GraphDisplayerCanvas::~GraphDisplayerCanvas()
24{
25  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
26  {
27    delete nodesmap[n];
28    delete nodetextmap[n];
29  }
30
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{
45  //first edges are drawn, to hide joining with nodes later
46
47  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
48  {
49
50    //drawing green lines, coordinates are from mapstorage.coords
51
52    Gnome::Canvas::Points coos;
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));
59   
60    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
61    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
62    edgesmap[i]->property_width_units().set_value(10);   
63   
64    //initializing edge-text as well, to empty string
65
66    xy<double> text_pos=edgesmap[i]->getArrowPos();
67    text_pos+=(xy<double>(10,10));
68
69    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
70    edgetextmap[i]->property_fill_color().set_value("darkgreen");
71    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
72  }
73
74  //afterwards nodes come to be drawn
75
76  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
77  {
78    //drawing bule nodes, with black line around them
79
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);
86    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
87    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
88
89    //initializing edge-text as well, to empty string
90
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));
94
95    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
96        text_pos.x, text_pos.y, "");
97    nodetextmap[i]->property_fill_color().set_value("darkblue");
98    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
99  }
100
101  updateScrollRegion();
102}
103
104void GraphDisplayerCanvas::clear()
105{
106  active_node=INVALID;
107  active_edge=INVALID;
108  forming_edge=INVALID;
109
110  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
111  {
112    delete nodesmap[n];
113    delete nodetextmap[n];
114  }
115
116  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
117  {
118    delete edgesmap[e];
119    delete edgetextmap[e];
120  }
121}
Note: See TracBrowser for help on using the repository browser.