ladanyi@53
|
1 |
#include "graph_displayer_canvas.h"
|
alpar@59
|
2 |
#include <cmath>
|
ladanyi@6
|
3 |
|
hegyi@96
|
4 |
GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
|
hegyi@94
|
5 |
nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
|
hegyi@94
|
6 |
nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
|
ladanyi@66
|
7 |
isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
|
hegyi@96
|
8 |
edgemap_to_edit(""), mytab(mainw)
|
ladanyi@6
|
9 |
{
|
ladanyi@53
|
10 |
//base event handler is move tool
|
ladanyi@53
|
11 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
ladanyi@53
|
12 |
actual_tool=MOVE;
|
hegyi@34
|
13 |
|
ladanyi@53
|
14 |
active_node=INVALID;
|
ladanyi@53
|
15 |
active_edge=INVALID;
|
ladanyi@53
|
16 |
forming_edge=INVALID;
|
ladanyi@53
|
17 |
}
|
hegyi@9
|
18 |
|
ladanyi@53
|
19 |
GraphDisplayerCanvas::~GraphDisplayerCanvas()
|
ladanyi@53
|
20 |
{
|
hegyi@96
|
21 |
for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
|
hegyi@94
|
22 |
{
|
hegyi@94
|
23 |
delete nodesmap[n];
|
hegyi@94
|
24 |
delete nodetextmap[n];
|
hegyi@94
|
25 |
}
|
hegyi@94
|
26 |
|
hegyi@96
|
27 |
for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
|
hegyi@94
|
28 |
{
|
hegyi@94
|
29 |
delete edgesmap[e];
|
hegyi@94
|
30 |
delete edgetextmap[e];
|
hegyi@94
|
31 |
}
|
hegyi@94
|
32 |
}
|
ladanyi@6
|
33 |
|
hegyi@94
|
34 |
void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop)
|
hegyi@94
|
35 |
{
|
hegyi@94
|
36 |
if(itisedge)
|
hegyi@94
|
37 |
{
|
hegyi@94
|
38 |
propertyUpdate(Edge(INVALID), prop);
|
hegyi@94
|
39 |
}
|
hegyi@94
|
40 |
else
|
hegyi@94
|
41 |
{
|
hegyi@94
|
42 |
propertyUpdate(Node(INVALID), prop);
|
hegyi@94
|
43 |
}
|
hegyi@94
|
44 |
}
|
hegyi@94
|
45 |
|
hegyi@94
|
46 |
void GraphDisplayerCanvas::propertyUpdate(Edge edge)
|
hegyi@94
|
47 |
{
|
hegyi@94
|
48 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@94
|
49 |
{
|
hegyi@94
|
50 |
propertyUpdate(edge, i);
|
hegyi@94
|
51 |
}
|
hegyi@94
|
52 |
}
|
hegyi@94
|
53 |
|
hegyi@94
|
54 |
void GraphDisplayerCanvas::propertyUpdate(Node node)
|
hegyi@94
|
55 |
{
|
hegyi@94
|
56 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@94
|
57 |
{
|
hegyi@94
|
58 |
propertyUpdate(node, i);
|
hegyi@94
|
59 |
}
|
hegyi@94
|
60 |
}
|
hegyi@94
|
61 |
|
hegyi@94
|
62 |
void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
|
hegyi@94
|
63 |
{
|
hegyi@94
|
64 |
dummy=dummy;
|
hegyi@94
|
65 |
|
hegyi@96
|
66 |
std::string mapname=mytab.getActiveNodeMap(prop);
|
hegyi@94
|
67 |
|
hegyi@94
|
68 |
if(mapname!="")
|
hegyi@94
|
69 |
{
|
hegyi@96
|
70 |
if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
|
hegyi@94
|
71 |
{
|
hegyi@94
|
72 |
switch(prop)
|
hegyi@94
|
73 |
{
|
hegyi@94
|
74 |
case N_RADIUS:
|
hegyi@94
|
75 |
changeNodeRadius(mapname, node);
|
hegyi@94
|
76 |
break;
|
hegyi@94
|
77 |
case N_COLOR:
|
hegyi@94
|
78 |
changeNodeColor(mapname, node);
|
hegyi@94
|
79 |
break;
|
hegyi@94
|
80 |
case N_TEXT:
|
hegyi@94
|
81 |
changeNodeText(mapname, node);
|
hegyi@94
|
82 |
break;
|
hegyi@94
|
83 |
default:
|
hegyi@94
|
84 |
std::cerr<<"Error\n";
|
hegyi@94
|
85 |
}
|
hegyi@94
|
86 |
}
|
hegyi@94
|
87 |
}
|
hegyi@94
|
88 |
else //mapname==""
|
hegyi@94
|
89 |
{
|
hegyi@94
|
90 |
Node node=INVALID;
|
hegyi@94
|
91 |
switch(prop)
|
hegyi@94
|
92 |
{
|
hegyi@94
|
93 |
case N_RADIUS:
|
hegyi@94
|
94 |
resetNodeRadius(node);
|
hegyi@94
|
95 |
break;
|
hegyi@94
|
96 |
case N_COLOR:
|
hegyi@94
|
97 |
resetNodeColor(node);
|
hegyi@94
|
98 |
break;
|
hegyi@94
|
99 |
case N_TEXT:
|
hegyi@94
|
100 |
resetNodeText(node);
|
hegyi@94
|
101 |
break;
|
hegyi@94
|
102 |
default:
|
hegyi@94
|
103 |
std::cerr<<"Error\n";
|
hegyi@94
|
104 |
}
|
hegyi@94
|
105 |
}
|
hegyi@94
|
106 |
|
hegyi@94
|
107 |
}
|
hegyi@94
|
108 |
|
hegyi@94
|
109 |
void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
|
hegyi@94
|
110 |
{
|
hegyi@94
|
111 |
dummy=dummy;
|
hegyi@94
|
112 |
|
hegyi@96
|
113 |
std::string mapname=mytab.getActiveEdgeMap(prop);
|
hegyi@94
|
114 |
|
hegyi@94
|
115 |
if(mapname!="")
|
hegyi@94
|
116 |
{
|
hegyi@96
|
117 |
if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
|
hegyi@94
|
118 |
{
|
hegyi@94
|
119 |
switch(prop)
|
hegyi@94
|
120 |
{
|
hegyi@94
|
121 |
case E_WIDTH:
|
hegyi@94
|
122 |
changeEdgeWidth(mapname, edge);
|
hegyi@94
|
123 |
break;
|
hegyi@94
|
124 |
case E_COLOR:
|
hegyi@94
|
125 |
changeEdgeColor(mapname, edge);
|
hegyi@94
|
126 |
break;
|
hegyi@94
|
127 |
case E_TEXT:
|
hegyi@94
|
128 |
changeEdgeText(mapname, edge);
|
hegyi@94
|
129 |
break;
|
hegyi@94
|
130 |
default:
|
hegyi@94
|
131 |
std::cerr<<"Error\n";
|
hegyi@94
|
132 |
}
|
hegyi@94
|
133 |
}
|
hegyi@94
|
134 |
}
|
hegyi@94
|
135 |
else //mapname==""
|
hegyi@94
|
136 |
{
|
hegyi@94
|
137 |
switch(prop)
|
hegyi@94
|
138 |
{
|
hegyi@94
|
139 |
case E_WIDTH:
|
hegyi@94
|
140 |
resetEdgeWidth(edge);
|
hegyi@94
|
141 |
break;
|
hegyi@94
|
142 |
case E_COLOR:
|
hegyi@94
|
143 |
resetEdgeColor(edge);
|
hegyi@94
|
144 |
break;
|
hegyi@94
|
145 |
case E_TEXT:
|
hegyi@94
|
146 |
resetEdgeText(edge);
|
hegyi@94
|
147 |
break;
|
hegyi@94
|
148 |
default:
|
hegyi@94
|
149 |
std::cerr<<"Error\n";
|
hegyi@94
|
150 |
}
|
hegyi@94
|
151 |
}
|
ladanyi@53
|
152 |
}
|
ladanyi@53
|
153 |
|
ladanyi@53
|
154 |
void GraphDisplayerCanvas::drawGraph()
|
ladanyi@53
|
155 |
{
|
ladanyi@6
|
156 |
//first edges are drawn, to hide joining with nodes later
|
ladanyi@6
|
157 |
|
hegyi@96
|
158 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
ladanyi@6
|
159 |
{
|
ladanyi@6
|
160 |
|
ladanyi@53
|
161 |
//drawing green lines, coordinates are from mapstorage.coords
|
ladanyi@6
|
162 |
|
ladanyi@6
|
163 |
Gnome::Canvas::Points coos;
|
ladanyi@53
|
164 |
coos.push_back(Gnome::Art::Point(
|
hegyi@96
|
165 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x,
|
hegyi@96
|
166 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y));
|
ladanyi@53
|
167 |
coos.push_back(Gnome::Art::Point(
|
hegyi@96
|
168 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
|
hegyi@96
|
169 |
(mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
|
ladanyi@6
|
170 |
|
ladanyi@98
|
171 |
edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
|
ladanyi@6
|
172 |
*(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@47
|
173 |
edgesmap[i]->property_width_units().set_value(10);
|
ladanyi@63
|
174 |
edgesmap[i]->lower_to_bottom();
|
ladanyi@6
|
175 |
|
ladanyi@6
|
176 |
//initializing edge-text as well, to empty string
|
ladanyi@6
|
177 |
|
ladanyi@98
|
178 |
XY text_pos=mytab.mapstorage.arrow_pos[i];
|
ladanyi@98
|
179 |
text_pos+=(XY(10,10));
|
hegyi@25
|
180 |
|
hegyi@25
|
181 |
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@28
|
182 |
edgetextmap[i]->property_fill_color().set_value("darkgreen");
|
hegyi@48
|
183 |
edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
ladanyi@63
|
184 |
edgetextmap[i]->raise_to_top();
|
ladanyi@6
|
185 |
}
|
ladanyi@6
|
186 |
|
ladanyi@6
|
187 |
//afterwards nodes come to be drawn
|
ladanyi@6
|
188 |
|
hegyi@96
|
189 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
ladanyi@6
|
190 |
{
|
ladanyi@6
|
191 |
//drawing bule nodes, with black line around them
|
ladanyi@6
|
192 |
|
ladanyi@53
|
193 |
nodesmap[i]=new Gnome::Canvas::Ellipse(
|
ladanyi@53
|
194 |
displayed_graph,
|
hegyi@96
|
195 |
(mytab.mapstorage).coords[i].x-20,
|
hegyi@96
|
196 |
(mytab.mapstorage).coords[i].y-20,
|
hegyi@96
|
197 |
(mytab.mapstorage).coords[i].x+20,
|
hegyi@96
|
198 |
(mytab.mapstorage).coords[i].y+20);
|
ladanyi@6
|
199 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@6
|
200 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
ladanyi@63
|
201 |
nodesmap[i]->raise_to_top();
|
hegyi@28
|
202 |
|
hegyi@28
|
203 |
//initializing edge-text as well, to empty string
|
hegyi@28
|
204 |
|
ladanyi@53
|
205 |
xy<double> text_pos(
|
hegyi@96
|
206 |
((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
|
hegyi@96
|
207 |
((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
|
hegyi@28
|
208 |
|
ladanyi@53
|
209 |
nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@53
|
210 |
text_pos.x, text_pos.y, "");
|
hegyi@28
|
211 |
nodetextmap[i]->property_fill_color().set_value("darkblue");
|
hegyi@48
|
212 |
nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
ladanyi@63
|
213 |
nodetextmap[i]->raise_to_top();
|
ladanyi@6
|
214 |
}
|
ladanyi@6
|
215 |
|
ladanyi@6
|
216 |
updateScrollRegion();
|
ladanyi@6
|
217 |
}
|
ladanyi@6
|
218 |
|
ladanyi@53
|
219 |
void GraphDisplayerCanvas::clear()
|
ladanyi@6
|
220 |
{
|
ladanyi@53
|
221 |
active_node=INVALID;
|
ladanyi@53
|
222 |
active_edge=INVALID;
|
ladanyi@53
|
223 |
forming_edge=INVALID;
|
ladanyi@6
|
224 |
|
hegyi@96
|
225 |
for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
|
ladanyi@6
|
226 |
{
|
ladanyi@53
|
227 |
delete nodesmap[n];
|
ladanyi@53
|
228 |
delete nodetextmap[n];
|
ladanyi@6
|
229 |
}
|
ladanyi@6
|
230 |
|
hegyi@96
|
231 |
for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
|
ladanyi@53
|
232 |
{
|
ladanyi@53
|
233 |
delete edgesmap[e];
|
ladanyi@53
|
234 |
delete edgetextmap[e];
|
ladanyi@53
|
235 |
}
|
ladanyi@6
|
236 |
}
|