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