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