COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas.cc @ 1645:4a04bb856ac7

Last change on this file since 1645:4a04bb856ac7 was 1645:4a04bb856ac7, checked in by Akos Ladanyi, 19 years ago
  • id maps are not editable
  • handle exceptions thrown by the file reader
  • texts are always above the edges
  • store a default value for all maps, so that edges and nodes created after adding a new map receive the default value too
  • create node on button release, not on click (fixes a few oddities)
  • Property exe set to *
File size: 3.8 KB
Line 
1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
3#include <cmath>
4
5GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
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  parentwin=mainwin;
12
13  //base event handler is move tool
14  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
15  actual_tool=MOVE;
16
17  //setting event handler for the editor widget
18  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
19
20  active_node=INVALID;
21  active_edge=INVALID;
22  forming_edge=INVALID;
23}
24
25GraphDisplayerCanvas::~GraphDisplayerCanvas()
26{
27  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
28  {
29    delete nodesmap[n];
30    delete nodetextmap[n];
31  }
32
33  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
34  {
35    delete edgesmap[e];
36    delete edgetextmap[e];
37  }
38
39  if(canvasentrywidget)
40  {
41    delete(canvasentrywidget);
42  }
43}
44
45void GraphDisplayerCanvas::drawGraph()
46{
47  //first edges are drawn, to hide joining with nodes later
48
49  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
50  {
51
52    //drawing green lines, coordinates are from mapstorage.coords
53
54    Gnome::Canvas::Points coos;
55    coos.push_back(Gnome::Art::Point(
56          mapstorage.coords[mapstorage.graph.source(i)].x,
57          mapstorage.coords[mapstorage.graph.source(i)].y));
58    coos.push_back(Gnome::Art::Point(
59          mapstorage.coords[mapstorage.graph.target(i)].x,
60          mapstorage.coords[mapstorage.graph.target(i)].y));
61   
62    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
63    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
64    edgesmap[i]->property_width_units().set_value(10);   
65    edgesmap[i]->lower_to_bottom();
66   
67    //initializing edge-text as well, to empty string
68
69    xy<double> text_pos=edgesmap[i]->getArrowPos();
70    text_pos+=(xy<double>(10,10));
71
72    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
73    edgetextmap[i]->property_fill_color().set_value("darkgreen");
74    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
75    edgetextmap[i]->raise_to_top();
76  }
77
78  //afterwards nodes come to be drawn
79
80  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
81  {
82    //drawing bule nodes, with black line around them
83
84    nodesmap[i]=new Gnome::Canvas::Ellipse(
85        displayed_graph,
86        mapstorage.coords[i].x-20,
87        mapstorage.coords[i].y-20,
88        mapstorage.coords[i].x+20,
89        mapstorage.coords[i].y+20);
90    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
91    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
92    nodesmap[i]->raise_to_top();
93
94    //initializing edge-text as well, to empty string
95
96    xy<double> text_pos(
97        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
98        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
99
100    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
101        text_pos.x, text_pos.y, "");
102    nodetextmap[i]->property_fill_color().set_value("darkblue");
103    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
104    nodetextmap[i]->raise_to_top();
105  }
106
107  updateScrollRegion();
108}
109
110void GraphDisplayerCanvas::clear()
111{
112  active_node=INVALID;
113  active_edge=INVALID;
114  forming_edge=INVALID;
115
116  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
117  {
118    delete nodesmap[n];
119    delete nodetextmap[n];
120  }
121
122  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
123  {
124    delete edgesmap[e];
125    delete edgetextmap[e];
126  }
127}
Note: See TracBrowser for help on using the repository browser.