ladanyi@53
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@53
|
2 |
#include "broken_edge.h"
|
alpar@59
|
3 |
#include <cmath>
|
ladanyi@6
|
4 |
|
hegyi@55
|
5 |
GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
|
ladanyi@53
|
6 |
nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
|
ladanyi@53
|
7 |
nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
|
ladanyi@53
|
8 |
canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
|
ladanyi@53
|
9 |
target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
|
ladanyi@6
|
10 |
{
|
hegyi@55
|
11 |
parentwin=mainwin;
|
hegyi@55
|
12 |
|
ladanyi@53
|
13 |
//base event handler is move tool
|
ladanyi@53
|
14 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
ladanyi@53
|
15 |
actual_tool=MOVE;
|
hegyi@34
|
16 |
|
hegyi@34
|
17 |
//setting event handler for the editor widget
|
hegyi@34
|
18 |
entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
|
hegyi@34
|
19 |
|
ladanyi@53
|
20 |
active_node=INVALID;
|
ladanyi@53
|
21 |
active_edge=INVALID;
|
ladanyi@53
|
22 |
forming_edge=INVALID;
|
ladanyi@53
|
23 |
}
|
hegyi@9
|
24 |
|
ladanyi@53
|
25 |
GraphDisplayerCanvas::~GraphDisplayerCanvas()
|
ladanyi@53
|
26 |
{
|
ladanyi@53
|
27 |
for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
|
ladanyi@53
|
28 |
{
|
ladanyi@53
|
29 |
delete nodesmap[n];
|
ladanyi@53
|
30 |
delete nodetextmap[n];
|
ladanyi@53
|
31 |
}
|
ladanyi@6
|
32 |
|
ladanyi@53
|
33 |
for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
|
ladanyi@53
|
34 |
{
|
ladanyi@53
|
35 |
delete edgesmap[e];
|
ladanyi@53
|
36 |
delete edgetextmap[e];
|
ladanyi@53
|
37 |
}
|
ladanyi@53
|
38 |
|
ladanyi@53
|
39 |
if(canvasentrywidget)
|
ladanyi@53
|
40 |
{
|
ladanyi@53
|
41 |
delete(canvasentrywidget);
|
ladanyi@53
|
42 |
}
|
ladanyi@53
|
43 |
}
|
ladanyi@53
|
44 |
|
ladanyi@53
|
45 |
void GraphDisplayerCanvas::drawGraph()
|
ladanyi@53
|
46 |
{
|
ladanyi@6
|
47 |
//first edges are drawn, to hide joining with nodes later
|
ladanyi@6
|
48 |
|
ladanyi@53
|
49 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@6
|
50 |
{
|
ladanyi@6
|
51 |
|
ladanyi@53
|
52 |
//drawing green lines, coordinates are from mapstorage.coords
|
ladanyi@6
|
53 |
|
ladanyi@6
|
54 |
Gnome::Canvas::Points coos;
|
ladanyi@53
|
55 |
coos.push_back(Gnome::Art::Point(
|
ladanyi@53
|
56 |
mapstorage.coords[mapstorage.graph.source(i)].x,
|
ladanyi@53
|
57 |
mapstorage.coords[mapstorage.graph.source(i)].y));
|
ladanyi@53
|
58 |
coos.push_back(Gnome::Art::Point(
|
ladanyi@53
|
59 |
mapstorage.coords[mapstorage.graph.target(i)].x,
|
ladanyi@53
|
60 |
mapstorage.coords[mapstorage.graph.target(i)].y));
|
ladanyi@6
|
61 |
|
hegyi@21
|
62 |
edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
|
ladanyi@6
|
63 |
*(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@47
|
64 |
edgesmap[i]->property_width_units().set_value(10);
|
ladanyi@6
|
65 |
|
ladanyi@6
|
66 |
//initializing edge-text as well, to empty string
|
ladanyi@6
|
67 |
|
hegyi@30
|
68 |
xy<double> text_pos=edgesmap[i]->getArrowPos();
|
hegyi@25
|
69 |
text_pos+=(xy<double>(10,10));
|
hegyi@25
|
70 |
|
hegyi@25
|
71 |
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@28
|
72 |
edgetextmap[i]->property_fill_color().set_value("darkgreen");
|
hegyi@48
|
73 |
edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
ladanyi@6
|
74 |
}
|
ladanyi@6
|
75 |
|
ladanyi@6
|
76 |
//afterwards nodes come to be drawn
|
ladanyi@6
|
77 |
|
ladanyi@53
|
78 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@6
|
79 |
{
|
ladanyi@6
|
80 |
//drawing bule nodes, with black line around them
|
ladanyi@6
|
81 |
|
ladanyi@53
|
82 |
nodesmap[i]=new Gnome::Canvas::Ellipse(
|
ladanyi@53
|
83 |
displayed_graph,
|
ladanyi@53
|
84 |
mapstorage.coords[i].x-20,
|
ladanyi@53
|
85 |
mapstorage.coords[i].y-20,
|
ladanyi@53
|
86 |
mapstorage.coords[i].x+20,
|
ladanyi@53
|
87 |
mapstorage.coords[i].y+20);
|
ladanyi@6
|
88 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@6
|
89 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@28
|
90 |
|
hegyi@28
|
91 |
//initializing edge-text as well, to empty string
|
hegyi@28
|
92 |
|
ladanyi@53
|
93 |
xy<double> text_pos(
|
ladanyi@53
|
94 |
(mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
|
ladanyi@53
|
95 |
(mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
|
hegyi@28
|
96 |
|
ladanyi@53
|
97 |
nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@53
|
98 |
text_pos.x, text_pos.y, "");
|
hegyi@28
|
99 |
nodetextmap[i]->property_fill_color().set_value("darkblue");
|
hegyi@48
|
100 |
nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
ladanyi@6
|
101 |
}
|
ladanyi@6
|
102 |
|
ladanyi@6
|
103 |
updateScrollRegion();
|
ladanyi@6
|
104 |
}
|
ladanyi@6
|
105 |
|
ladanyi@53
|
106 |
void GraphDisplayerCanvas::clear()
|
ladanyi@6
|
107 |
{
|
ladanyi@53
|
108 |
active_node=INVALID;
|
ladanyi@53
|
109 |
active_edge=INVALID;
|
ladanyi@53
|
110 |
forming_edge=INVALID;
|
ladanyi@6
|
111 |
|
ladanyi@53
|
112 |
for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
|
ladanyi@6
|
113 |
{
|
ladanyi@53
|
114 |
delete nodesmap[n];
|
ladanyi@53
|
115 |
delete nodetextmap[n];
|
ladanyi@6
|
116 |
}
|
ladanyi@6
|
117 |
|
ladanyi@53
|
118 |
for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
|
ladanyi@53
|
119 |
{
|
ladanyi@53
|
120 |
delete edgesmap[e];
|
ladanyi@53
|
121 |
delete edgetextmap[e];
|
ladanyi@53
|
122 |
}
|
ladanyi@6
|
123 |
}
|