ladanyi@53
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@53
|
2 |
#include "broken_edge.h"
|
hegyi@27
|
3 |
#include <math.h>
|
hegyi@27
|
4 |
|
hegyi@27
|
5 |
|
hegyi@27
|
6 |
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
|
hegyi@27
|
7 |
{
|
hegyi@27
|
8 |
Gnome::Canvas::CanvasAA::on_expose_event(event);
|
hegyi@27
|
9 |
//usleep(10000);
|
hegyi@27
|
10 |
//rezoom();
|
hegyi@27
|
11 |
return true;
|
hegyi@27
|
12 |
}
|
hegyi@27
|
13 |
|
hegyi@27
|
14 |
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
|
hegyi@27
|
15 |
{
|
hegyi@34
|
16 |
if(actual_tool!=newtool)
|
hegyi@34
|
17 |
{
|
hegyi@27
|
18 |
|
hegyi@34
|
19 |
actual_handler.disconnect();
|
hegyi@27
|
20 |
|
hegyi@34
|
21 |
switch(actual_tool)
|
hegyi@34
|
22 |
{
|
hegyi@34
|
23 |
case CREATE_EDGE:
|
hegyi@34
|
24 |
{
|
hegyi@34
|
25 |
GdkEvent * generated=new GdkEvent();
|
hegyi@34
|
26 |
generated->type=GDK_BUTTON_RELEASE;
|
hegyi@34
|
27 |
generated->button.button=3;
|
hegyi@34
|
28 |
createEdgeEventHandler(generated);
|
hegyi@34
|
29 |
break;
|
hegyi@34
|
30 |
}
|
hegyi@34
|
31 |
case EDGE_MAP_EDIT:
|
hegyi@35
|
32 |
//has to do the same thing as in the case of NODE_MAP_EDIT
|
hegyi@35
|
33 |
case NODE_MAP_EDIT:
|
hegyi@35
|
34 |
{
|
hegyi@35
|
35 |
GdkEvent * generated=new GdkEvent();
|
hegyi@35
|
36 |
generated->type=GDK_KEY_PRESS;
|
hegyi@35
|
37 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@35
|
38 |
entryWidgetChangeHandler(generated);
|
hegyi@35
|
39 |
entrywidget.hide();
|
hegyi@35
|
40 |
break;
|
hegyi@35
|
41 |
}
|
hegyi@34
|
42 |
default:
|
hegyi@34
|
43 |
break;
|
hegyi@34
|
44 |
}
|
hegyi@27
|
45 |
|
hegyi@34
|
46 |
active_item=NULL;
|
hegyi@34
|
47 |
target_item=NULL;
|
hegyi@34
|
48 |
active_edge=INVALID;
|
hegyi@34
|
49 |
active_node=INVALID;
|
hegyi@33
|
50 |
|
hegyi@27
|
51 |
|
hegyi@34
|
52 |
actual_tool=newtool;
|
hegyi@34
|
53 |
|
hegyi@34
|
54 |
switch(newtool)
|
hegyi@34
|
55 |
{
|
hegyi@34
|
56 |
case MOVE:
|
hegyi@34
|
57 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
hegyi@34
|
58 |
break;
|
hegyi@27
|
59 |
|
hegyi@34
|
60 |
case CREATE_NODE:
|
hegyi@34
|
61 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
|
hegyi@34
|
62 |
break;
|
hegyi@27
|
63 |
|
hegyi@34
|
64 |
case CREATE_EDGE:
|
hegyi@34
|
65 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
|
hegyi@34
|
66 |
break;
|
hegyi@27
|
67 |
|
hegyi@34
|
68 |
case ERASER:
|
hegyi@34
|
69 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
|
hegyi@34
|
70 |
break;
|
hegyi@32
|
71 |
|
hegyi@34
|
72 |
case EDGE_MAP_EDIT:
|
hegyi@34
|
73 |
grab_focus();
|
hegyi@34
|
74 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
hegyi@34
|
75 |
break;
|
hegyi@32
|
76 |
|
hegyi@34
|
77 |
case NODE_MAP_EDIT:
|
hegyi@34
|
78 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
hegyi@34
|
79 |
break;
|
hegyi@34
|
80 |
|
hegyi@34
|
81 |
default:
|
hegyi@34
|
82 |
break;
|
hegyi@34
|
83 |
}
|
hegyi@27
|
84 |
}
|
hegyi@27
|
85 |
}
|
hegyi@27
|
86 |
|
hegyi@30
|
87 |
int GraphDisplayerCanvas::getActualTool()
|
hegyi@27
|
88 |
{
|
hegyi@27
|
89 |
return actual_tool;
|
hegyi@27
|
90 |
}
|
hegyi@27
|
91 |
|
hegyi@30
|
92 |
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
|
hegyi@27
|
93 |
{
|
hegyi@27
|
94 |
switch(e->type)
|
hegyi@27
|
95 |
{
|
hegyi@27
|
96 |
case GDK_BUTTON_PRESS:
|
hegyi@27
|
97 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@31
|
98 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@31
|
99 |
|
hegyi@31
|
100 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@27
|
101 |
active_node=INVALID;
|
ladanyi@53
|
102 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
103 |
{
|
hegyi@27
|
104 |
if(nodesmap[i]==active_item)
|
hegyi@27
|
105 |
{
|
hegyi@27
|
106 |
active_node=i;
|
hegyi@27
|
107 |
}
|
hegyi@27
|
108 |
}
|
hegyi@27
|
109 |
switch(e->button.button)
|
hegyi@27
|
110 |
{
|
hegyi@27
|
111 |
case 3:
|
hegyi@27
|
112 |
isbutton=3;
|
hegyi@27
|
113 |
break;
|
hegyi@27
|
114 |
default:
|
hegyi@27
|
115 |
isbutton=1;
|
hegyi@27
|
116 |
break;
|
hegyi@27
|
117 |
}
|
hegyi@27
|
118 |
break;
|
hegyi@27
|
119 |
case GDK_BUTTON_RELEASE:
|
hegyi@27
|
120 |
isbutton=0;
|
hegyi@27
|
121 |
active_item=NULL;
|
hegyi@27
|
122 |
active_node=INVALID;
|
hegyi@27
|
123 |
break;
|
hegyi@27
|
124 |
case GDK_MOTION_NOTIFY:
|
hegyi@27
|
125 |
//we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
|
hegyi@27
|
126 |
if(active_node!=INVALID)
|
hegyi@27
|
127 |
{
|
ladanyi@53
|
128 |
mapstorage.modified = true;
|
ladanyi@53
|
129 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
hegyi@27
|
130 |
//new coordinates will be the old values,
|
hegyi@27
|
131 |
//because the item will be moved to the
|
hegyi@27
|
132 |
//new coordinate therefore the new movement
|
hegyi@27
|
133 |
//has to be calculated from here
|
hegyi@27
|
134 |
|
hegyi@31
|
135 |
double new_x, new_y;
|
hegyi@31
|
136 |
|
hegyi@31
|
137 |
window_to_world (e->motion.x, e->motion.y, new_x, new_y);
|
hegyi@31
|
138 |
|
hegyi@31
|
139 |
double dx=new_x-clicked_x;
|
hegyi@31
|
140 |
double dy=new_y-clicked_y;
|
hegyi@27
|
141 |
|
hegyi@28
|
142 |
//repositioning node and its text
|
hegyi@27
|
143 |
active_item->move(dx, dy);
|
hegyi@28
|
144 |
nodetextmap[active_node]->move(dx, dy);
|
hegyi@27
|
145 |
|
hegyi@31
|
146 |
clicked_x=new_x;
|
hegyi@31
|
147 |
clicked_y=new_y;
|
hegyi@27
|
148 |
|
hegyi@27
|
149 |
//all the edges connected to the moved point has to be redrawn
|
hegyi@27
|
150 |
EdgeIt ei;
|
hegyi@27
|
151 |
|
ladanyi@53
|
152 |
mapstorage.graph.firstOut(ei,active_node);
|
hegyi@27
|
153 |
|
ladanyi@53
|
154 |
for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
|
hegyi@27
|
155 |
{
|
hegyi@27
|
156 |
Gnome::Canvas::Points coos;
|
hegyi@27
|
157 |
double x1, x2, y1, y2;
|
hegyi@27
|
158 |
|
ladanyi@53
|
159 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@27
|
160 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
161 |
|
ladanyi@53
|
162 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@27
|
163 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
164 |
|
hegyi@27
|
165 |
if(isbutton==3)
|
hegyi@27
|
166 |
{
|
hegyi@30
|
167 |
edgesmap[ei]->setPoints(coos);
|
hegyi@27
|
168 |
}
|
hegyi@27
|
169 |
else
|
hegyi@27
|
170 |
{
|
hegyi@30
|
171 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@27
|
172 |
}
|
hegyi@27
|
173 |
|
hegyi@28
|
174 |
//reposition of edgetext
|
hegyi@30
|
175 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@27
|
176 |
text_pos+=(xy<double>(10,10));
|
hegyi@27
|
177 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@27
|
178 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@27
|
179 |
}
|
hegyi@27
|
180 |
|
ladanyi@53
|
181 |
mapstorage.graph.firstIn(ei,active_node);
|
ladanyi@53
|
182 |
for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
|
hegyi@27
|
183 |
{
|
hegyi@27
|
184 |
Gnome::Canvas::Points coos;
|
hegyi@27
|
185 |
double x1, x2, y1, y2;
|
hegyi@27
|
186 |
|
ladanyi@53
|
187 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@27
|
188 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
189 |
|
ladanyi@53
|
190 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@27
|
191 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
192 |
|
hegyi@27
|
193 |
if(isbutton==3)
|
hegyi@27
|
194 |
{
|
hegyi@30
|
195 |
edgesmap[ei]->setPoints(coos);
|
hegyi@27
|
196 |
}
|
hegyi@27
|
197 |
else
|
hegyi@27
|
198 |
{
|
hegyi@30
|
199 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@27
|
200 |
}
|
hegyi@27
|
201 |
|
hegyi@30
|
202 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@27
|
203 |
text_pos+=(xy<double>(10,10));
|
hegyi@27
|
204 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@27
|
205 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@27
|
206 |
}
|
hegyi@27
|
207 |
}
|
hegyi@27
|
208 |
default: break;
|
hegyi@27
|
209 |
}
|
hegyi@27
|
210 |
|
hegyi@31
|
211 |
return false;
|
hegyi@27
|
212 |
}
|
hegyi@27
|
213 |
|
hegyi@30
|
214 |
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
|
hegyi@27
|
215 |
{
|
hegyi@27
|
216 |
switch(e->type)
|
hegyi@27
|
217 |
{
|
hegyi@27
|
218 |
|
hegyi@27
|
219 |
//draw the new node in red at the clicked place
|
hegyi@31
|
220 |
case GDK_2BUTTON_PRESS:
|
hegyi@48
|
221 |
//std::cout << "double click" << std::endl;
|
hegyi@31
|
222 |
break;
|
hegyi@27
|
223 |
case GDK_BUTTON_PRESS:
|
ladanyi@53
|
224 |
mapstorage.modified = true;
|
ladanyi@53
|
225 |
|
hegyi@27
|
226 |
isbutton=1;
|
hegyi@27
|
227 |
|
ladanyi@53
|
228 |
active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
|
hegyi@27
|
229 |
|
hegyi@27
|
230 |
//initiating values corresponding to new node in maps
|
hegyi@27
|
231 |
|
hegyi@27
|
232 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@27
|
233 |
|
ladanyi@53
|
234 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
ladanyi@53
|
235 |
(*mapstorage.nodemap_storage["id"])[active_node] =
|
ladanyi@53
|
236 |
mapstorage.graph.id(active_node);
|
ladanyi@53
|
237 |
|
ladanyi@53
|
238 |
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
|
ladanyi@53
|
239 |
clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
|
hegyi@27
|
240 |
active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
|
hegyi@27
|
241 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@27
|
242 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@27
|
243 |
(nodesmap[active_node])->show();
|
hegyi@28
|
244 |
|
ladanyi@53
|
245 |
nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@53
|
246 |
clicked_x+node_property_defaults[N_RADIUS]+5,
|
ladanyi@53
|
247 |
clicked_y+node_property_defaults[N_RADIUS]+5, "");
|
hegyi@28
|
248 |
nodetextmap[active_node]->property_fill_color().set_value("darkblue");
|
hegyi@28
|
249 |
|
ladanyi@53
|
250 |
mapwin.updateNode(active_node);
|
hegyi@28
|
251 |
|
hegyi@27
|
252 |
break;
|
hegyi@27
|
253 |
|
hegyi@27
|
254 |
//move the new node
|
hegyi@27
|
255 |
case GDK_MOTION_NOTIFY:
|
hegyi@27
|
256 |
{
|
hegyi@27
|
257 |
GdkEvent * generated=new GdkEvent();
|
hegyi@31
|
258 |
generated->motion.x=e->motion.x;
|
hegyi@31
|
259 |
generated->motion.y=e->motion.y;
|
hegyi@27
|
260 |
generated->type=GDK_MOTION_NOTIFY;
|
hegyi@30
|
261 |
moveEventHandler(generated);
|
hegyi@27
|
262 |
break;
|
hegyi@27
|
263 |
}
|
hegyi@27
|
264 |
|
hegyi@27
|
265 |
//finalize the new node
|
hegyi@27
|
266 |
case GDK_BUTTON_RELEASE:
|
hegyi@35
|
267 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@35
|
268 |
|
hegyi@35
|
269 |
active_item->lower_to_bottom();
|
hegyi@35
|
270 |
|
hegyi@35
|
271 |
target_item=NULL;
|
hegyi@35
|
272 |
target_item=get_item_at(clicked_x, clicked_y);
|
hegyi@35
|
273 |
|
hegyi@35
|
274 |
active_item->raise_to_top();
|
hegyi@35
|
275 |
|
hegyi@27
|
276 |
isbutton=0;
|
hegyi@35
|
277 |
if(target_item==active_item)
|
hegyi@31
|
278 |
{
|
hegyi@31
|
279 |
//Its appropriate color is given by update.
|
hegyi@35
|
280 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@31
|
281 |
}
|
hegyi@31
|
282 |
else
|
hegyi@31
|
283 |
{
|
hegyi@31
|
284 |
//In this case the given color has to be overwritten, because the noe covers an other item.
|
hegyi@31
|
285 |
*active_item << Gnome::Canvas::Properties::fill_color("lightblue");
|
hegyi@31
|
286 |
}
|
hegyi@31
|
287 |
target_item=NULL;
|
hegyi@27
|
288 |
active_item=NULL;
|
hegyi@27
|
289 |
active_node=INVALID;
|
hegyi@27
|
290 |
break;
|
hegyi@27
|
291 |
default:
|
hegyi@27
|
292 |
break;
|
hegyi@27
|
293 |
}
|
hegyi@27
|
294 |
return false;
|
hegyi@27
|
295 |
}
|
hegyi@27
|
296 |
|
hegyi@30
|
297 |
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
|
hegyi@27
|
298 |
{
|
hegyi@27
|
299 |
switch(e->type)
|
hegyi@27
|
300 |
{
|
hegyi@27
|
301 |
case GDK_BUTTON_PRESS:
|
hegyi@27
|
302 |
//in edge creation right button has special meaning
|
hegyi@27
|
303 |
if(e->button.button!=3)
|
hegyi@27
|
304 |
{
|
hegyi@27
|
305 |
//there is not yet selected node
|
hegyi@27
|
306 |
if(active_node==INVALID)
|
hegyi@27
|
307 |
{
|
hegyi@27
|
308 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@31
|
309 |
|
hegyi@31
|
310 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@31
|
311 |
|
hegyi@31
|
312 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@27
|
313 |
active_node=INVALID;
|
ladanyi@53
|
314 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
315 |
{
|
hegyi@27
|
316 |
if(nodesmap[i]==active_item)
|
hegyi@27
|
317 |
{
|
hegyi@27
|
318 |
active_node=i;
|
hegyi@27
|
319 |
}
|
hegyi@27
|
320 |
}
|
hegyi@27
|
321 |
//the clicked item is really a node
|
hegyi@27
|
322 |
if(active_node!=INVALID)
|
hegyi@27
|
323 |
{
|
hegyi@27
|
324 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@27
|
325 |
isbutton=1;
|
hegyi@27
|
326 |
}
|
hegyi@27
|
327 |
//clicked item was not a node. It could be e.g. edge.
|
hegyi@27
|
328 |
else
|
hegyi@27
|
329 |
{
|
hegyi@27
|
330 |
active_item=NULL;
|
hegyi@27
|
331 |
}
|
hegyi@27
|
332 |
}
|
hegyi@27
|
333 |
//we only have to do sg. if the mouse button
|
hegyi@27
|
334 |
// is pressed already once AND the click was
|
hegyi@27
|
335 |
// on a node that was found in the set of
|
hegyi@27
|
336 |
//nodes, and now we only search for the second
|
hegyi@27
|
337 |
//node
|
hegyi@27
|
338 |
else
|
hegyi@27
|
339 |
{
|
hegyi@31
|
340 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@31
|
341 |
target_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@27
|
342 |
Graph::NodeIt target_node=INVALID;
|
ladanyi@53
|
343 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
344 |
{
|
hegyi@27
|
345 |
if(nodesmap[i]==target_item)
|
hegyi@27
|
346 |
{
|
hegyi@27
|
347 |
target_node=i;
|
hegyi@27
|
348 |
}
|
hegyi@27
|
349 |
}
|
hegyi@27
|
350 |
//the clicked item is a node, the edge can be drawn
|
hegyi@27
|
351 |
if(target_node!=INVALID)
|
hegyi@27
|
352 |
{
|
hegyi@28
|
353 |
if(target_node!=active_node)
|
hegyi@28
|
354 |
{
|
ladanyi@53
|
355 |
mapstorage.modified = true;
|
ladanyi@53
|
356 |
|
hegyi@28
|
357 |
*(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@27
|
358 |
|
hegyi@28
|
359 |
//creating new edge
|
ladanyi@53
|
360 |
active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
|
hegyi@27
|
361 |
|
hegyi@28
|
362 |
//initiating values corresponding to new edge in maps
|
hegyi@30
|
363 |
mapstorage.initMapsForEdge(active_edge);
|
ladanyi@53
|
364 |
(*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
|
hegyi@27
|
365 |
|
hegyi@28
|
366 |
//calculating coordinates of new edge
|
hegyi@28
|
367 |
Gnome::Canvas::Points coos;
|
hegyi@28
|
368 |
double x1, x2, y1, y2;
|
hegyi@27
|
369 |
|
hegyi@28
|
370 |
active_item->get_bounds(x1, y1, x2, y2);
|
hegyi@28
|
371 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
372 |
|
hegyi@28
|
373 |
target_item->get_bounds(x1, y1, x2, y2);
|
hegyi@28
|
374 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@27
|
375 |
|
hegyi@28
|
376 |
//drawing new edge
|
hegyi@28
|
377 |
edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
|
hegyi@28
|
378 |
*(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@28
|
379 |
edgesmap[active_edge]->property_width_pixels().set_value(10);
|
hegyi@27
|
380 |
|
hegyi@28
|
381 |
//redraw nodes to blank terminations of the new edge
|
hegyi@28
|
382 |
target_item->raise_to_top();
|
hegyi@28
|
383 |
active_item->raise_to_top();
|
hegyi@27
|
384 |
|
hegyi@28
|
385 |
//initializing edge-text as well, to empty string
|
hegyi@30
|
386 |
xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
|
hegyi@28
|
387 |
text_pos+=(xy<double>(10,10));
|
hegyi@27
|
388 |
|
hegyi@28
|
389 |
edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@28
|
390 |
edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
|
hegyi@28
|
391 |
|
hegyi@28
|
392 |
//updating its properties
|
ladanyi@53
|
393 |
mapwin.updateEdge(active_edge);
|
hegyi@28
|
394 |
}
|
hegyi@28
|
395 |
else
|
hegyi@28
|
396 |
{
|
hegyi@28
|
397 |
target_node=INVALID;
|
hegyi@48
|
398 |
std::cerr << "Loop edge is not yet implemented!" << std::endl;
|
hegyi@28
|
399 |
}
|
hegyi@27
|
400 |
}
|
hegyi@27
|
401 |
//clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
|
hegyi@27
|
402 |
else
|
hegyi@27
|
403 |
{
|
hegyi@27
|
404 |
target_item=NULL;
|
hegyi@27
|
405 |
}
|
hegyi@27
|
406 |
}
|
hegyi@27
|
407 |
}
|
hegyi@27
|
408 |
break;
|
hegyi@27
|
409 |
case GDK_BUTTON_RELEASE:
|
hegyi@27
|
410 |
isbutton=0;
|
hegyi@27
|
411 |
//we clear settings in two cases
|
hegyi@27
|
412 |
//1: the edge is ready (target_item has valid value)
|
hegyi@27
|
413 |
//2: the edge creation is cancelled with right button
|
hegyi@27
|
414 |
if((target_item)||(e->button.button==3))
|
hegyi@27
|
415 |
{
|
hegyi@27
|
416 |
if(active_item)
|
hegyi@27
|
417 |
{
|
hegyi@27
|
418 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@27
|
419 |
active_item=NULL;
|
hegyi@27
|
420 |
}
|
hegyi@27
|
421 |
if(target_item)
|
hegyi@27
|
422 |
{
|
hegyi@27
|
423 |
*target_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@27
|
424 |
target_item=NULL;
|
hegyi@27
|
425 |
}
|
hegyi@27
|
426 |
active_node=INVALID;
|
hegyi@27
|
427 |
active_edge=INVALID;
|
hegyi@27
|
428 |
}
|
hegyi@27
|
429 |
break;
|
hegyi@27
|
430 |
default:
|
hegyi@27
|
431 |
break;
|
hegyi@27
|
432 |
}
|
hegyi@27
|
433 |
return false;
|
hegyi@27
|
434 |
}
|
hegyi@27
|
435 |
|
hegyi@30
|
436 |
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
|
hegyi@27
|
437 |
{
|
hegyi@27
|
438 |
switch(e->type)
|
hegyi@27
|
439 |
{
|
hegyi@27
|
440 |
case GDK_BUTTON_PRESS:
|
hegyi@43
|
441 |
//finding the clicked items
|
hegyi@31
|
442 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@31
|
443 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@27
|
444 |
active_node=INVALID;
|
hegyi@27
|
445 |
active_edge=INVALID;
|
hegyi@43
|
446 |
//was it a node?
|
ladanyi@53
|
447 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
448 |
{
|
hegyi@27
|
449 |
if(nodesmap[i]==active_item)
|
hegyi@27
|
450 |
{
|
hegyi@27
|
451 |
active_node=i;
|
hegyi@27
|
452 |
}
|
hegyi@27
|
453 |
}
|
hegyi@43
|
454 |
//or was it an edge?
|
hegyi@27
|
455 |
if(active_node==INVALID)
|
hegyi@27
|
456 |
{
|
ladanyi@53
|
457 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
458 |
{
|
hegyi@27
|
459 |
if(edgesmap[i]==active_item)
|
hegyi@27
|
460 |
{
|
hegyi@27
|
461 |
active_edge=i;
|
hegyi@27
|
462 |
}
|
hegyi@27
|
463 |
}
|
hegyi@27
|
464 |
}
|
hegyi@43
|
465 |
|
hegyi@43
|
466 |
//recolor activated item
|
hegyi@31
|
467 |
if(active_item)
|
hegyi@31
|
468 |
{
|
hegyi@31
|
469 |
*active_item << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@31
|
470 |
}
|
hegyi@27
|
471 |
break;
|
hegyi@27
|
472 |
|
hegyi@27
|
473 |
case GDK_BUTTON_RELEASE:
|
hegyi@31
|
474 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@31
|
475 |
if(active_item)
|
hegyi@27
|
476 |
{
|
hegyi@43
|
477 |
//the cursor was not moved since pressing it
|
hegyi@31
|
478 |
if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
|
hegyi@27
|
479 |
{
|
hegyi@43
|
480 |
//a node was found
|
hegyi@31
|
481 |
if(active_node!=INVALID)
|
hegyi@31
|
482 |
{
|
ladanyi@53
|
483 |
mapstorage.modified = true;
|
hegyi@27
|
484 |
|
hegyi@31
|
485 |
//collecting edges to delete
|
hegyi@31
|
486 |
EdgeIt e;
|
hegyi@31
|
487 |
std::set<Graph::Edge> edges_to_delete;
|
hegyi@27
|
488 |
|
ladanyi@53
|
489 |
mapstorage.graph.firstOut(e,active_node);
|
ladanyi@53
|
490 |
for(;e!=INVALID;mapstorage.graph.nextOut(e))
|
hegyi@31
|
491 |
{
|
hegyi@31
|
492 |
edges_to_delete.insert(e);
|
hegyi@31
|
493 |
}
|
hegyi@31
|
494 |
|
ladanyi@53
|
495 |
mapstorage.graph.firstIn(e,active_node);
|
ladanyi@53
|
496 |
for(;e!=INVALID;mapstorage.graph.nextIn(e))
|
hegyi@31
|
497 |
{
|
hegyi@31
|
498 |
edges_to_delete.insert(e);
|
hegyi@31
|
499 |
}
|
hegyi@31
|
500 |
|
hegyi@31
|
501 |
//deleting collected edges
|
hegyi@31
|
502 |
for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
|
hegyi@31
|
503 |
{
|
hegyi@31
|
504 |
deleteItem(*edge_set_it);
|
hegyi@31
|
505 |
}
|
hegyi@31
|
506 |
deleteItem(active_node);
|
hegyi@31
|
507 |
}
|
hegyi@31
|
508 |
//a simple edge was chosen
|
hegyi@31
|
509 |
else
|
hegyi@27
|
510 |
{
|
hegyi@31
|
511 |
deleteItem(active_edge);
|
hegyi@27
|
512 |
}
|
hegyi@27
|
513 |
}
|
hegyi@31
|
514 |
//pointer was moved, deletion is cancelled
|
hegyi@27
|
515 |
else
|
hegyi@27
|
516 |
{
|
hegyi@31
|
517 |
if(active_node!=INVALID)
|
hegyi@31
|
518 |
{
|
hegyi@31
|
519 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@31
|
520 |
}
|
hegyi@31
|
521 |
else
|
hegyi@31
|
522 |
{
|
hegyi@31
|
523 |
*active_item << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@31
|
524 |
}
|
hegyi@27
|
525 |
}
|
hegyi@27
|
526 |
}
|
hegyi@27
|
527 |
//reseting datas
|
hegyi@27
|
528 |
active_item=NULL;
|
hegyi@27
|
529 |
active_edge=INVALID;
|
hegyi@27
|
530 |
active_node=INVALID;
|
hegyi@27
|
531 |
break;
|
hegyi@27
|
532 |
|
hegyi@27
|
533 |
case GDK_MOTION_NOTIFY:
|
hegyi@27
|
534 |
break;
|
hegyi@27
|
535 |
|
hegyi@27
|
536 |
default:
|
hegyi@27
|
537 |
break;
|
hegyi@27
|
538 |
}
|
hegyi@31
|
539 |
return false;
|
hegyi@27
|
540 |
}
|
hegyi@27
|
541 |
|
hegyi@32
|
542 |
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
|
hegyi@32
|
543 |
{
|
hegyi@48
|
544 |
if(actual_tool==EDGE_MAP_EDIT)
|
hegyi@32
|
545 |
{
|
hegyi@48
|
546 |
switch(e->type)
|
hegyi@48
|
547 |
{
|
hegyi@48
|
548 |
case GDK_KEY_PRESS:
|
hegyi@48
|
549 |
//for Escape or Enter hide the displayed widget
|
hegyi@48
|
550 |
{
|
hegyi@48
|
551 |
nodeMapEditEventHandler(e);
|
hegyi@48
|
552 |
break;
|
hegyi@48
|
553 |
}
|
hegyi@48
|
554 |
case GDK_BUTTON_PRESS:
|
hegyi@48
|
555 |
//If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
|
hegyi@48
|
556 |
{
|
hegyi@48
|
557 |
//for determine, whether it was an edge
|
hegyi@48
|
558 |
Graph::EdgeIt clicked_edge=INVALID;
|
hegyi@43
|
559 |
|
hegyi@48
|
560 |
//find the activated item between texts
|
hegyi@48
|
561 |
active_item=(get_item_at(e->button.x, e->button.y));
|
ladanyi@53
|
562 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@34
|
563 |
{
|
hegyi@48
|
564 |
if(edgetextmap[i]==active_item)
|
hegyi@48
|
565 |
{
|
hegyi@48
|
566 |
clicked_edge=i;
|
hegyi@48
|
567 |
}
|
hegyi@34
|
568 |
}
|
hegyi@48
|
569 |
|
hegyi@48
|
570 |
//if it was not between texts, search for it between edges
|
hegyi@48
|
571 |
if(clicked_edge==INVALID)
|
hegyi@34
|
572 |
{
|
hegyi@48
|
573 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@48
|
574 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@48
|
575 |
|
ladanyi@53
|
576 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@48
|
577 |
{
|
hegyi@48
|
578 |
//at the same time only one can be active
|
hegyi@48
|
579 |
if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
|
hegyi@48
|
580 |
{
|
hegyi@48
|
581 |
clicked_edge=i;
|
hegyi@48
|
582 |
}
|
hegyi@48
|
583 |
}
|
hegyi@48
|
584 |
}
|
hegyi@48
|
585 |
//if it was really an edge...
|
hegyi@48
|
586 |
if(clicked_edge!=INVALID)
|
hegyi@48
|
587 |
{
|
hegyi@48
|
588 |
//If there is already edited edge, it has to be saved first
|
hegyi@48
|
589 |
if(entrywidget.is_visible())
|
hegyi@48
|
590 |
{
|
hegyi@48
|
591 |
GdkEvent * generated=new GdkEvent();
|
hegyi@48
|
592 |
generated->type=GDK_KEY_PRESS;
|
hegyi@48
|
593 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@48
|
594 |
entryWidgetChangeHandler(generated);
|
hegyi@48
|
595 |
}
|
hegyi@48
|
596 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@48
|
597 |
if(!entrywidget.is_visible())
|
hegyi@48
|
598 |
{
|
hegyi@48
|
599 |
//and there is activated map
|
hegyi@48
|
600 |
if(edgetextmap[clicked_edge]->property_text().get_value()!="")
|
hegyi@48
|
601 |
{
|
hegyi@48
|
602 |
//activate the general variable for it
|
hegyi@48
|
603 |
active_edge=clicked_edge;
|
hegyi@48
|
604 |
//delete visible widget if there is
|
hegyi@48
|
605 |
if(canvasentrywidget)
|
hegyi@48
|
606 |
{
|
hegyi@48
|
607 |
delete(canvasentrywidget);
|
hegyi@48
|
608 |
}
|
hegyi@48
|
609 |
|
hegyi@48
|
610 |
//initialize the entry
|
hegyi@48
|
611 |
entrywidget.show();
|
hegyi@48
|
612 |
|
hegyi@48
|
613 |
//fill in the correct value
|
hegyi@48
|
614 |
entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
|
hegyi@48
|
615 |
|
hegyi@48
|
616 |
//replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
|
hegyi@48
|
617 |
xy<double> entry_coos;
|
hegyi@48
|
618 |
entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
|
hegyi@48
|
619 |
entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
|
hegyi@48
|
620 |
entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
|
hegyi@48
|
621 |
entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
|
hegyi@48
|
622 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@48
|
623 |
canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
|
hegyi@48
|
624 |
canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
|
hegyi@55
|
625 |
|
hegyi@55
|
626 |
//setting the focus to newly created widget
|
hegyi@55
|
627 |
parentwin->set_focus(entrywidget);
|
hegyi@55
|
628 |
parentwin->activate_focus();
|
hegyi@48
|
629 |
}
|
hegyi@48
|
630 |
}
|
hegyi@48
|
631 |
}
|
hegyi@48
|
632 |
//if it was not an edge...
|
hegyi@48
|
633 |
else
|
hegyi@48
|
634 |
{
|
hegyi@48
|
635 |
//In this case the click did not happen on an edge
|
hegyi@48
|
636 |
//if there is visible entry we save the value in it
|
hegyi@48
|
637 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@43
|
638 |
GdkEvent * generated=new GdkEvent();
|
hegyi@43
|
639 |
generated->type=GDK_KEY_PRESS;
|
hegyi@43
|
640 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@43
|
641 |
entryWidgetChangeHandler(generated);
|
hegyi@43
|
642 |
}
|
hegyi@48
|
643 |
break;
|
hegyi@34
|
644 |
}
|
hegyi@48
|
645 |
default:
|
hegyi@48
|
646 |
break;
|
hegyi@48
|
647 |
}
|
hegyi@32
|
648 |
}
|
hegyi@32
|
649 |
return false;
|
hegyi@32
|
650 |
}
|
hegyi@32
|
651 |
|
hegyi@32
|
652 |
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
|
hegyi@32
|
653 |
{
|
hegyi@48
|
654 |
if(actual_tool==NODE_MAP_EDIT)
|
hegyi@35
|
655 |
{
|
hegyi@48
|
656 |
switch(e->type)
|
hegyi@48
|
657 |
{
|
hegyi@48
|
658 |
case GDK_KEY_PRESS:
|
hegyi@48
|
659 |
//for Escape or Enter hide the displayed widget
|
hegyi@35
|
660 |
{
|
hegyi@48
|
661 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@48
|
662 |
{
|
hegyi@48
|
663 |
case GDK_Escape:
|
hegyi@48
|
664 |
entrywidget.hide();
|
hegyi@48
|
665 |
break;
|
hegyi@48
|
666 |
case GDK_Return:
|
hegyi@48
|
667 |
case GDK_KP_Enter:
|
hegyi@48
|
668 |
entrywidget.hide();
|
hegyi@48
|
669 |
break;
|
hegyi@48
|
670 |
default:
|
hegyi@48
|
671 |
break;
|
hegyi@48
|
672 |
}
|
hegyi@48
|
673 |
|
hegyi@35
|
674 |
break;
|
hegyi@35
|
675 |
}
|
hegyi@48
|
676 |
case GDK_BUTTON_PRESS:
|
hegyi@48
|
677 |
//If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
|
hegyi@48
|
678 |
{
|
hegyi@48
|
679 |
//for determine, whether it was a node
|
hegyi@48
|
680 |
Graph::NodeIt clicked_node=INVALID;
|
hegyi@43
|
681 |
|
hegyi@48
|
682 |
//find the activated item between texts
|
hegyi@48
|
683 |
active_item=(get_item_at(e->button.x, e->button.y));
|
ladanyi@53
|
684 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@35
|
685 |
{
|
hegyi@48
|
686 |
//at the same time only one can be active
|
hegyi@48
|
687 |
if(nodetextmap[i]==active_item)
|
hegyi@48
|
688 |
{
|
hegyi@48
|
689 |
clicked_node=i;
|
hegyi@48
|
690 |
}
|
hegyi@35
|
691 |
}
|
hegyi@43
|
692 |
|
hegyi@48
|
693 |
//if there was not, search for it between nodes
|
hegyi@48
|
694 |
if(clicked_node==INVALID)
|
hegyi@35
|
695 |
{
|
hegyi@48
|
696 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@48
|
697 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@48
|
698 |
|
ladanyi@53
|
699 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@48
|
700 |
{
|
hegyi@48
|
701 |
//at the same time only one can be active
|
hegyi@48
|
702 |
if(nodesmap[i]==active_item)
|
hegyi@48
|
703 |
{
|
hegyi@48
|
704 |
clicked_node=i;
|
hegyi@48
|
705 |
}
|
hegyi@48
|
706 |
}
|
hegyi@48
|
707 |
}
|
hegyi@48
|
708 |
//if it was really an edge...
|
hegyi@48
|
709 |
if(clicked_node!=INVALID)
|
hegyi@48
|
710 |
{
|
hegyi@48
|
711 |
//If there is already edited edge, it has to be saved first
|
hegyi@48
|
712 |
if(entrywidget.is_visible())
|
hegyi@48
|
713 |
{
|
hegyi@48
|
714 |
GdkEvent * generated=new GdkEvent();
|
hegyi@48
|
715 |
generated->type=GDK_KEY_PRESS;
|
hegyi@48
|
716 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@48
|
717 |
entryWidgetChangeHandler(generated);
|
hegyi@48
|
718 |
}
|
hegyi@48
|
719 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@48
|
720 |
if(!entrywidget.is_visible())
|
hegyi@48
|
721 |
{
|
hegyi@48
|
722 |
//and there is activated map
|
hegyi@48
|
723 |
if(nodetextmap[clicked_node]->property_text().get_value()!="")
|
hegyi@48
|
724 |
{
|
hegyi@48
|
725 |
//activate the general variable for it
|
hegyi@48
|
726 |
active_node=clicked_node;
|
hegyi@48
|
727 |
//delete visible widget if there is
|
hegyi@48
|
728 |
if(canvasentrywidget)
|
hegyi@48
|
729 |
{
|
hegyi@48
|
730 |
delete(canvasentrywidget);
|
hegyi@48
|
731 |
}
|
hegyi@48
|
732 |
|
hegyi@48
|
733 |
//initialize the entry
|
hegyi@48
|
734 |
entrywidget.show();
|
hegyi@48
|
735 |
|
hegyi@48
|
736 |
//fill in the correct value
|
hegyi@48
|
737 |
entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
|
hegyi@48
|
738 |
|
hegyi@48
|
739 |
//replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
|
hegyi@48
|
740 |
xy<double> entry_coos;
|
hegyi@48
|
741 |
entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
|
hegyi@48
|
742 |
entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
|
hegyi@48
|
743 |
entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
|
hegyi@48
|
744 |
entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
|
hegyi@48
|
745 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@48
|
746 |
canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
|
hegyi@48
|
747 |
canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
|
hegyi@48
|
748 |
}
|
hegyi@48
|
749 |
}
|
hegyi@48
|
750 |
}
|
hegyi@48
|
751 |
//if it was not an edge...
|
hegyi@48
|
752 |
else
|
hegyi@48
|
753 |
{
|
hegyi@48
|
754 |
//In this case the click did not happen on an edge
|
hegyi@48
|
755 |
//if there is visible entry we save the value in it
|
hegyi@48
|
756 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@35
|
757 |
GdkEvent * generated=new GdkEvent();
|
hegyi@35
|
758 |
generated->type=GDK_KEY_PRESS;
|
hegyi@35
|
759 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@35
|
760 |
entryWidgetChangeHandler(generated);
|
hegyi@35
|
761 |
}
|
hegyi@48
|
762 |
break;
|
hegyi@35
|
763 |
}
|
hegyi@48
|
764 |
default:
|
hegyi@48
|
765 |
break;
|
hegyi@48
|
766 |
}
|
hegyi@35
|
767 |
}
|
hegyi@35
|
768 |
return false;
|
hegyi@32
|
769 |
}
|
hegyi@32
|
770 |
|
hegyi@34
|
771 |
bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
|
hegyi@34
|
772 |
{
|
hegyi@35
|
773 |
if(entrywidget.is_visible())
|
hegyi@35
|
774 |
{
|
hegyi@35
|
775 |
if(e->type==GDK_KEY_PRESS)
|
hegyi@35
|
776 |
{
|
hegyi@35
|
777 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@35
|
778 |
{
|
hegyi@35
|
779 |
case GDK_Escape:
|
hegyi@35
|
780 |
entrywidget.hide();
|
hegyi@35
|
781 |
break;
|
hegyi@35
|
782 |
case GDK_KP_Enter:
|
hegyi@35
|
783 |
case GDK_Return:
|
hegyi@35
|
784 |
{
|
hegyi@43
|
785 |
//these variables check whether the text in the entry is valid
|
hegyi@41
|
786 |
bool valid_double=true;
|
hegyi@41
|
787 |
int point_num=0;
|
hegyi@43
|
788 |
|
hegyi@43
|
789 |
//getting the value from the entry and converting it to double
|
hegyi@41
|
790 |
Glib::ustring mapvalue_str = entrywidget.get_text();
|
hegyi@35
|
791 |
|
hegyi@41
|
792 |
char * mapvalue_ch=new char [mapvalue_str.length()];
|
hegyi@41
|
793 |
for(int i=0;i<(int)(mapvalue_str.length());i++)
|
hegyi@35
|
794 |
{
|
hegyi@41
|
795 |
if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
|
hegyi@35
|
796 |
{
|
hegyi@41
|
797 |
valid_double=false;
|
hegyi@35
|
798 |
}
|
hegyi@35
|
799 |
else
|
hegyi@35
|
800 |
{
|
hegyi@41
|
801 |
if(mapvalue_str[i]=='.')
|
hegyi@41
|
802 |
{
|
hegyi@41
|
803 |
point_num++;
|
hegyi@41
|
804 |
}
|
hegyi@35
|
805 |
}
|
hegyi@41
|
806 |
mapvalue_ch[i]=mapvalue_str[i];
|
hegyi@35
|
807 |
}
|
hegyi@45
|
808 |
|
hegyi@43
|
809 |
//if the text in the entry was correct
|
hegyi@41
|
810 |
if((point_num<=1)&&(valid_double))
|
hegyi@35
|
811 |
{
|
hegyi@45
|
812 |
double mapvalue_d=atof(mapvalue_ch);
|
hegyi@45
|
813 |
|
hegyi@45
|
814 |
//reconvert the double to string for the correct format
|
hegyi@45
|
815 |
std::ostringstream ostr;
|
hegyi@45
|
816 |
ostr << mapvalue_d;
|
hegyi@45
|
817 |
|
hegyi@43
|
818 |
//save the value to the correct place
|
hegyi@35
|
819 |
switch(actual_tool)
|
hegyi@35
|
820 |
{
|
hegyi@35
|
821 |
case EDGE_MAP_EDIT:
|
hegyi@45
|
822 |
edgetextmap[active_edge]->property_text().set_value(ostr.str());
|
hegyi@41
|
823 |
(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
|
ladanyi@53
|
824 |
mapwin.updateEdge(active_edge);
|
hegyi@35
|
825 |
break;
|
hegyi@35
|
826 |
case NODE_MAP_EDIT:
|
hegyi@45
|
827 |
nodetextmap[active_node]->property_text().set_value(ostr.str());
|
hegyi@41
|
828 |
(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
|
ladanyi@53
|
829 |
mapwin.updateNode(active_node);
|
hegyi@35
|
830 |
break;
|
hegyi@35
|
831 |
default:
|
hegyi@35
|
832 |
break;
|
hegyi@35
|
833 |
}
|
hegyi@35
|
834 |
entrywidget.hide();
|
hegyi@35
|
835 |
}
|
hegyi@43
|
836 |
//the text in the entry was not correct for a double
|
hegyi@35
|
837 |
else
|
hegyi@35
|
838 |
{
|
hegyi@48
|
839 |
std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
|
hegyi@35
|
840 |
}
|
hegyi@35
|
841 |
|
hegyi@35
|
842 |
break;
|
hegyi@35
|
843 |
}
|
hegyi@35
|
844 |
default:
|
hegyi@35
|
845 |
break;
|
hegyi@35
|
846 |
}
|
hegyi@35
|
847 |
}
|
hegyi@35
|
848 |
}
|
hegyi@34
|
849 |
return false;
|
hegyi@34
|
850 |
}
|
hegyi@34
|
851 |
|
hegyi@30
|
852 |
void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
|
hegyi@27
|
853 |
{
|
hegyi@28
|
854 |
delete(nodetextmap[node_to_delete]);
|
hegyi@27
|
855 |
delete(nodesmap[node_to_delete]);
|
ladanyi@53
|
856 |
mapstorage.graph.erase(node_to_delete);
|
hegyi@27
|
857 |
}
|
hegyi@27
|
858 |
|
hegyi@30
|
859 |
void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
|
hegyi@27
|
860 |
{
|
hegyi@28
|
861 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@27
|
862 |
delete(edgesmap[edge_to_delete]);
|
ladanyi@53
|
863 |
mapstorage.graph.erase(edge_to_delete);
|
hegyi@27
|
864 |
}
|
hegyi@27
|
865 |
|
hegyi@30
|
866 |
void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
|
hegyi@27
|
867 |
{
|
hegyi@28
|
868 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@27
|
869 |
delete(edgesmap[edge_to_delete]);
|
ladanyi@53
|
870 |
mapstorage.graph.erase(edge_to_delete);
|
hegyi@27
|
871 |
}
|
hegyi@27
|
872 |
|
hegyi@30
|
873 |
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
|
hegyi@27
|
874 |
{
|
hegyi@27
|
875 |
new_place+=(xy<double>(10,10));
|
hegyi@35
|
876 |
edgetextmap[forming_edge]->property_x().set_value(new_place.x);
|
hegyi@35
|
877 |
edgetextmap[forming_edge]->property_y().set_value(new_place.y);
|
hegyi@27
|
878 |
}
|
hegyi@27
|
879 |
|
hegyi@30
|
880 |
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
|
hegyi@27
|
881 |
{
|
hegyi@27
|
882 |
if(on)
|
hegyi@27
|
883 |
{
|
hegyi@35
|
884 |
if(forming_edge!=INVALID)
|
hegyi@27
|
885 |
{
|
hegyi@48
|
886 |
std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
|
hegyi@27
|
887 |
}
|
hegyi@27
|
888 |
else
|
hegyi@27
|
889 |
{
|
ladanyi@53
|
890 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@27
|
891 |
{
|
hegyi@27
|
892 |
if(edgesmap[i]==active_bre)
|
hegyi@27
|
893 |
{
|
hegyi@35
|
894 |
forming_edge=i;
|
hegyi@27
|
895 |
}
|
hegyi@27
|
896 |
}
|
hegyi@27
|
897 |
}
|
hegyi@27
|
898 |
}
|
hegyi@27
|
899 |
else
|
hegyi@27
|
900 |
{
|
hegyi@35
|
901 |
if(forming_edge!=INVALID)
|
hegyi@27
|
902 |
{
|
hegyi@35
|
903 |
forming_edge=INVALID;
|
hegyi@27
|
904 |
}
|
hegyi@27
|
905 |
else
|
hegyi@27
|
906 |
{
|
hegyi@48
|
907 |
std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
|
hegyi@27
|
908 |
}
|
hegyi@27
|
909 |
}
|
hegyi@27
|
910 |
|
hegyi@27
|
911 |
}
|
hegyi@32
|
912 |
|
hegyi@46
|
913 |
int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
|
hegyi@37
|
914 |
{
|
hegyi@43
|
915 |
//create the new map
|
ladanyi@53
|
916 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
|
hegyi@46
|
917 |
|
hegyi@46
|
918 |
//if addition was not successful addEdgeMap returns one.
|
hegyi@46
|
919 |
//cause can be that there is already a map named like the new one
|
hegyi@46
|
920 |
if(mapstorage.addEdgeMap(mapname,emptr))
|
hegyi@46
|
921 |
{
|
hegyi@46
|
922 |
return 1;
|
hegyi@46
|
923 |
}
|
hegyi@46
|
924 |
|
hegyi@43
|
925 |
|
hegyi@43
|
926 |
//add it to the list of the displayable maps
|
ladanyi@53
|
927 |
mapwin.registerNewEdgeMap(mapname);
|
hegyi@43
|
928 |
|
hegyi@43
|
929 |
//display it
|
hegyi@41
|
930 |
changeEdgeText(mapname);
|
hegyi@46
|
931 |
|
hegyi@46
|
932 |
return 0;
|
hegyi@37
|
933 |
}
|
hegyi@37
|
934 |
|
hegyi@46
|
935 |
int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
|
hegyi@37
|
936 |
{
|
hegyi@43
|
937 |
//create the new map
|
ladanyi@53
|
938 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
|
hegyi@46
|
939 |
|
hegyi@46
|
940 |
//if addition was not successful addNodeMap returns one.
|
hegyi@46
|
941 |
//cause can be that there is already a map named like the new one
|
hegyi@46
|
942 |
if(mapstorage.addNodeMap(mapname,emptr))
|
hegyi@46
|
943 |
{
|
hegyi@46
|
944 |
return 1;
|
hegyi@46
|
945 |
}
|
hegyi@43
|
946 |
|
hegyi@43
|
947 |
//add it to the list of the displayable maps
|
ladanyi@53
|
948 |
mapwin.registerNewNodeMap(mapname);
|
hegyi@43
|
949 |
|
hegyi@43
|
950 |
//display it
|
hegyi@41
|
951 |
changeNodeText(mapname);
|
hegyi@46
|
952 |
|
hegyi@46
|
953 |
return 0;
|
hegyi@37
|
954 |
}
|
hegyi@37
|
955 |
|