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