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@1594
|
427 |
//finding the clicked items
|
hegyi@1525
|
428 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
429 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
430 |
active_node=INVALID;
|
hegyi@1510
|
431 |
active_edge=INVALID;
|
hegyi@1594
|
432 |
|
hegyi@1594
|
433 |
//was it a node?
|
hegyi@1510
|
434 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
435 |
{
|
hegyi@1510
|
436 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
437 |
{
|
hegyi@1510
|
438 |
active_node=i;
|
hegyi@1510
|
439 |
}
|
hegyi@1510
|
440 |
}
|
hegyi@1594
|
441 |
//or was it an edge?
|
hegyi@1510
|
442 |
if(active_node==INVALID)
|
hegyi@1510
|
443 |
{
|
hegyi@1510
|
444 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
445 |
{
|
hegyi@1510
|
446 |
if(edgesmap[i]==active_item)
|
hegyi@1510
|
447 |
{
|
hegyi@1510
|
448 |
active_edge=i;
|
hegyi@1510
|
449 |
}
|
hegyi@1510
|
450 |
}
|
hegyi@1510
|
451 |
}
|
hegyi@1594
|
452 |
|
hegyi@1594
|
453 |
//recolor activated item
|
hegyi@1525
|
454 |
if(active_item)
|
hegyi@1525
|
455 |
{
|
hegyi@1525
|
456 |
*active_item << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1525
|
457 |
}
|
hegyi@1510
|
458 |
break;
|
hegyi@1510
|
459 |
|
hegyi@1510
|
460 |
case GDK_BUTTON_RELEASE:
|
hegyi@1525
|
461 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
462 |
if(active_item)
|
hegyi@1510
|
463 |
{
|
hegyi@1594
|
464 |
//the cursor was not moved since pressing it
|
hegyi@1525
|
465 |
if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
|
hegyi@1510
|
466 |
{
|
hegyi@1594
|
467 |
//a node was found
|
hegyi@1525
|
468 |
if(active_node!=INVALID)
|
hegyi@1525
|
469 |
{
|
hegyi@1510
|
470 |
|
hegyi@1525
|
471 |
//collecting edges to delete
|
hegyi@1525
|
472 |
EdgeIt e;
|
hegyi@1525
|
473 |
std::set<Graph::Edge> edges_to_delete;
|
hegyi@1510
|
474 |
|
hegyi@1525
|
475 |
g.firstOut(e,active_node);
|
hegyi@1525
|
476 |
for(;e!=INVALID;g.nextOut(e))
|
hegyi@1525
|
477 |
{
|
hegyi@1525
|
478 |
edges_to_delete.insert(e);
|
hegyi@1525
|
479 |
}
|
hegyi@1525
|
480 |
|
hegyi@1525
|
481 |
g.firstIn(e,active_node);
|
hegyi@1525
|
482 |
for(;e!=INVALID;g.nextIn(e))
|
hegyi@1525
|
483 |
{
|
hegyi@1525
|
484 |
edges_to_delete.insert(e);
|
hegyi@1525
|
485 |
}
|
hegyi@1525
|
486 |
|
hegyi@1525
|
487 |
//deleting collected edges
|
hegyi@1525
|
488 |
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
|
489 |
{
|
hegyi@1525
|
490 |
deleteItem(*edge_set_it);
|
hegyi@1525
|
491 |
}
|
hegyi@1525
|
492 |
deleteItem(active_node);
|
hegyi@1525
|
493 |
}
|
hegyi@1525
|
494 |
//a simple edge was chosen
|
hegyi@1525
|
495 |
else
|
hegyi@1510
|
496 |
{
|
hegyi@1525
|
497 |
deleteItem(active_edge);
|
hegyi@1510
|
498 |
}
|
hegyi@1510
|
499 |
}
|
hegyi@1525
|
500 |
//pointer was moved, deletion is cancelled
|
hegyi@1510
|
501 |
else
|
hegyi@1510
|
502 |
{
|
hegyi@1525
|
503 |
if(active_node!=INVALID)
|
hegyi@1525
|
504 |
{
|
hegyi@1525
|
505 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1525
|
506 |
}
|
hegyi@1525
|
507 |
else
|
hegyi@1525
|
508 |
{
|
hegyi@1525
|
509 |
*active_item << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@1525
|
510 |
}
|
hegyi@1510
|
511 |
}
|
hegyi@1510
|
512 |
}
|
hegyi@1510
|
513 |
//reseting datas
|
hegyi@1510
|
514 |
active_item=NULL;
|
hegyi@1510
|
515 |
active_edge=INVALID;
|
hegyi@1510
|
516 |
active_node=INVALID;
|
hegyi@1510
|
517 |
break;
|
hegyi@1510
|
518 |
|
hegyi@1510
|
519 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
520 |
break;
|
hegyi@1510
|
521 |
|
hegyi@1510
|
522 |
default:
|
hegyi@1510
|
523 |
break;
|
hegyi@1510
|
524 |
}
|
hegyi@1525
|
525 |
return false;
|
hegyi@1510
|
526 |
}
|
hegyi@1510
|
527 |
|
hegyi@1550
|
528 |
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
529 |
{
|
hegyi@1550
|
530 |
switch(e->type)
|
hegyi@1550
|
531 |
{
|
hegyi@1562
|
532 |
case GDK_KEY_PRESS:
|
hegyi@1594
|
533 |
//for Escape or Enter hide the displayed widget
|
hegyi@1562
|
534 |
{
|
hegyi@1579
|
535 |
nodeMapEditEventHandler(e);
|
hegyi@1562
|
536 |
break;
|
hegyi@1562
|
537 |
}
|
hegyi@1550
|
538 |
case GDK_BUTTON_PRESS:
|
hegyi@1594
|
539 |
//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@1562
|
540 |
{
|
hegyi@1594
|
541 |
//find the activated item
|
hegyi@1562
|
542 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1562
|
543 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1594
|
544 |
|
hegyi@1594
|
545 |
//determine, whether it was an edge
|
hegyi@1562
|
546 |
Graph::EdgeIt clicked_edge=INVALID;
|
hegyi@1562
|
547 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1562
|
548 |
{
|
hegyi@1562
|
549 |
if(edgesmap[i]==active_item)
|
hegyi@1562
|
550 |
{
|
hegyi@1562
|
551 |
clicked_edge=i;
|
hegyi@1562
|
552 |
}
|
hegyi@1562
|
553 |
}
|
hegyi@1594
|
554 |
//if it was really an edge...
|
hegyi@1562
|
555 |
if(clicked_edge!=INVALID)
|
hegyi@1562
|
556 |
{
|
hegyi@1594
|
557 |
//If there is already edited edge, it has to be saved first
|
hegyi@1594
|
558 |
if(entrywidget.is_visible())
|
hegyi@1562
|
559 |
{
|
hegyi@1594
|
560 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1594
|
561 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1594
|
562 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1594
|
563 |
entryWidgetChangeHandler(generated);
|
hegyi@1594
|
564 |
}
|
hegyi@1594
|
565 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@1594
|
566 |
if(!entrywidget.is_visible())
|
hegyi@1594
|
567 |
{
|
hegyi@1594
|
568 |
//and there is activated map
|
hegyi@1594
|
569 |
if(edgetextmap[clicked_edge]->property_text().get_value()!="")
|
hegyi@1562
|
570 |
{
|
hegyi@1594
|
571 |
//activate the general variable for it
|
hegyi@1594
|
572 |
active_edge=clicked_edge;
|
hegyi@1594
|
573 |
//delete visible widget if there is
|
hegyi@1594
|
574 |
if(canvasentrywidget)
|
hegyi@1594
|
575 |
{
|
hegyi@1594
|
576 |
delete(canvasentrywidget);
|
hegyi@1594
|
577 |
}
|
hegyi@1594
|
578 |
|
hegyi@1594
|
579 |
//initialize the entry
|
hegyi@1594
|
580 |
entrywidget.show();
|
hegyi@1594
|
581 |
|
hegyi@1594
|
582 |
//fill in the correct value
|
hegyi@1594
|
583 |
entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
|
hegyi@1594
|
584 |
|
hegyi@1594
|
585 |
//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@1594
|
586 |
xy<double> entry_coos;
|
hegyi@1594
|
587 |
entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
|
hegyi@1594
|
588 |
entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
|
hegyi@1594
|
589 |
entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
|
hegyi@1594
|
590 |
entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
|
hegyi@1594
|
591 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@1594
|
592 |
canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
|
hegyi@1594
|
593 |
canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
|
hegyi@1562
|
594 |
}
|
hegyi@1562
|
595 |
}
|
hegyi@1562
|
596 |
}
|
hegyi@1594
|
597 |
//if it was not an edge...
|
hegyi@1562
|
598 |
else
|
hegyi@1562
|
599 |
{
|
hegyi@1594
|
600 |
//In this case the click did not happen on an edge
|
hegyi@1594
|
601 |
//if there is visible entry we save the value in it
|
hegyi@1594
|
602 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@1579
|
603 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1579
|
604 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1579
|
605 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1579
|
606 |
entryWidgetChangeHandler(generated);
|
hegyi@1562
|
607 |
}
|
hegyi@1562
|
608 |
break;
|
hegyi@1562
|
609 |
}
|
hegyi@1550
|
610 |
default:
|
hegyi@1550
|
611 |
break;
|
hegyi@1550
|
612 |
}
|
hegyi@1550
|
613 |
return false;
|
hegyi@1550
|
614 |
}
|
hegyi@1550
|
615 |
|
hegyi@1550
|
616 |
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
617 |
{
|
hegyi@1579
|
618 |
switch(e->type)
|
hegyi@1579
|
619 |
{
|
hegyi@1579
|
620 |
case GDK_KEY_PRESS:
|
hegyi@1594
|
621 |
//for Escape or Enter hide the displayed widget
|
hegyi@1579
|
622 |
{
|
hegyi@1579
|
623 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@1579
|
624 |
{
|
hegyi@1579
|
625 |
case GDK_Escape:
|
hegyi@1579
|
626 |
entrywidget.hide();
|
hegyi@1579
|
627 |
break;
|
hegyi@1579
|
628 |
case GDK_Return:
|
hegyi@1579
|
629 |
case GDK_KP_Enter:
|
hegyi@1579
|
630 |
entrywidget.hide();
|
hegyi@1579
|
631 |
break;
|
hegyi@1579
|
632 |
default:
|
hegyi@1579
|
633 |
break;
|
hegyi@1579
|
634 |
}
|
hegyi@1579
|
635 |
|
hegyi@1579
|
636 |
break;
|
hegyi@1579
|
637 |
}
|
hegyi@1579
|
638 |
case GDK_BUTTON_PRESS:
|
hegyi@1594
|
639 |
//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@1579
|
640 |
{
|
hegyi@1594
|
641 |
//find the activated item
|
hegyi@1579
|
642 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1579
|
643 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1594
|
644 |
|
hegyi@1594
|
645 |
//determine, whether it was a node
|
hegyi@1579
|
646 |
Graph::NodeIt clicked_node=INVALID;
|
hegyi@1579
|
647 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1579
|
648 |
{
|
hegyi@1579
|
649 |
if(nodesmap[i]==active_item)
|
hegyi@1579
|
650 |
{
|
hegyi@1579
|
651 |
clicked_node=i;
|
hegyi@1579
|
652 |
}
|
hegyi@1579
|
653 |
}
|
hegyi@1594
|
654 |
|
hegyi@1594
|
655 |
//if it was really an edge...
|
hegyi@1579
|
656 |
if(clicked_node!=INVALID)
|
hegyi@1579
|
657 |
{
|
hegyi@1579
|
658 |
//If there is already edited edge, it has to be saved first
|
hegyi@1579
|
659 |
if(entrywidget.is_visible())
|
hegyi@1579
|
660 |
{
|
hegyi@1579
|
661 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1579
|
662 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1579
|
663 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1579
|
664 |
entryWidgetChangeHandler(generated);
|
hegyi@1579
|
665 |
}
|
hegyi@1579
|
666 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@1579
|
667 |
if(!entrywidget.is_visible())
|
hegyi@1579
|
668 |
{
|
hegyi@1594
|
669 |
//and there is activated map
|
hegyi@1579
|
670 |
if(nodetextmap[clicked_node]->property_text().get_value()!="")
|
hegyi@1579
|
671 |
{
|
hegyi@1594
|
672 |
//activate the general variable for it
|
hegyi@1579
|
673 |
active_node=clicked_node;
|
hegyi@1594
|
674 |
//delete visible widget if there is
|
hegyi@1579
|
675 |
if(canvasentrywidget)
|
hegyi@1579
|
676 |
{
|
hegyi@1579
|
677 |
delete(canvasentrywidget);
|
hegyi@1579
|
678 |
}
|
hegyi@1594
|
679 |
|
hegyi@1594
|
680 |
//initialize the entry
|
hegyi@1579
|
681 |
entrywidget.show();
|
hegyi@1594
|
682 |
|
hegyi@1594
|
683 |
//fill in the correct value
|
hegyi@1579
|
684 |
entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
|
hegyi@1594
|
685 |
|
hegyi@1594
|
686 |
//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@1579
|
687 |
xy<double> entry_coos;
|
hegyi@1579
|
688 |
entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
|
hegyi@1579
|
689 |
entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
|
hegyi@1579
|
690 |
entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
|
hegyi@1579
|
691 |
entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
|
hegyi@1579
|
692 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@1579
|
693 |
canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5);
|
hegyi@1579
|
694 |
canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
|
hegyi@1579
|
695 |
}
|
hegyi@1579
|
696 |
}
|
hegyi@1579
|
697 |
}
|
hegyi@1594
|
698 |
//if it was not an edge...
|
hegyi@1579
|
699 |
else
|
hegyi@1579
|
700 |
{
|
hegyi@1594
|
701 |
//In this case the click did not happen on an edge
|
hegyi@1594
|
702 |
//if there is visible entry we save the value in it
|
hegyi@1594
|
703 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@1579
|
704 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1579
|
705 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1579
|
706 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1579
|
707 |
entryWidgetChangeHandler(generated);
|
hegyi@1579
|
708 |
}
|
hegyi@1579
|
709 |
break;
|
hegyi@1579
|
710 |
}
|
hegyi@1579
|
711 |
default:
|
hegyi@1579
|
712 |
break;
|
hegyi@1579
|
713 |
}
|
hegyi@1579
|
714 |
return false;
|
hegyi@1550
|
715 |
}
|
hegyi@1550
|
716 |
|
hegyi@1562
|
717 |
bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
|
hegyi@1562
|
718 |
{
|
hegyi@1579
|
719 |
if(entrywidget.is_visible())
|
hegyi@1579
|
720 |
{
|
hegyi@1579
|
721 |
if(e->type==GDK_KEY_PRESS)
|
hegyi@1579
|
722 |
{
|
hegyi@1579
|
723 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@1579
|
724 |
{
|
hegyi@1579
|
725 |
case GDK_Escape:
|
hegyi@1579
|
726 |
entrywidget.hide();
|
hegyi@1579
|
727 |
break;
|
hegyi@1579
|
728 |
case GDK_KP_Enter:
|
hegyi@1579
|
729 |
case GDK_Return:
|
hegyi@1579
|
730 |
{
|
hegyi@1594
|
731 |
//these variables check whether the text in the entry is valid
|
hegyi@1592
|
732 |
bool valid_double=true;
|
hegyi@1592
|
733 |
int point_num=0;
|
hegyi@1594
|
734 |
|
hegyi@1594
|
735 |
//getting the value from the entry and converting it to double
|
hegyi@1592
|
736 |
Glib::ustring mapvalue_str = entrywidget.get_text();
|
hegyi@1579
|
737 |
|
hegyi@1592
|
738 |
char * mapvalue_ch=new char [mapvalue_str.length()];
|
hegyi@1592
|
739 |
for(int i=0;i<(int)(mapvalue_str.length());i++)
|
hegyi@1579
|
740 |
{
|
hegyi@1592
|
741 |
if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
|
hegyi@1579
|
742 |
{
|
hegyi@1592
|
743 |
valid_double=false;
|
hegyi@1579
|
744 |
}
|
hegyi@1579
|
745 |
else
|
hegyi@1579
|
746 |
{
|
hegyi@1592
|
747 |
if(mapvalue_str[i]=='.')
|
hegyi@1592
|
748 |
{
|
hegyi@1592
|
749 |
point_num++;
|
hegyi@1592
|
750 |
}
|
hegyi@1579
|
751 |
}
|
hegyi@1592
|
752 |
mapvalue_ch[i]=mapvalue_str[i];
|
hegyi@1579
|
753 |
}
|
hegyi@1596
|
754 |
|
hegyi@1594
|
755 |
//if the text in the entry was correct
|
hegyi@1592
|
756 |
if((point_num<=1)&&(valid_double))
|
hegyi@1579
|
757 |
{
|
hegyi@1596
|
758 |
double mapvalue_d=atof(mapvalue_ch);
|
hegyi@1596
|
759 |
|
hegyi@1596
|
760 |
//reconvert the double to string for the correct format
|
hegyi@1596
|
761 |
std::ostringstream ostr;
|
hegyi@1596
|
762 |
ostr << mapvalue_d;
|
hegyi@1596
|
763 |
|
hegyi@1594
|
764 |
//save the value to the correct place
|
hegyi@1579
|
765 |
switch(actual_tool)
|
hegyi@1579
|
766 |
{
|
hegyi@1579
|
767 |
case EDGE_MAP_EDIT:
|
hegyi@1596
|
768 |
edgetextmap[active_edge]->property_text().set_value(ostr.str());
|
hegyi@1592
|
769 |
(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
|
hegyi@1579
|
770 |
break;
|
hegyi@1579
|
771 |
case NODE_MAP_EDIT:
|
hegyi@1596
|
772 |
nodetextmap[active_node]->property_text().set_value(ostr.str());
|
hegyi@1592
|
773 |
(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
|
hegyi@1579
|
774 |
break;
|
hegyi@1579
|
775 |
default:
|
hegyi@1579
|
776 |
break;
|
hegyi@1579
|
777 |
}
|
hegyi@1579
|
778 |
entrywidget.hide();
|
hegyi@1579
|
779 |
}
|
hegyi@1594
|
780 |
//the text in the entry was not correct for a double
|
hegyi@1579
|
781 |
else
|
hegyi@1579
|
782 |
{
|
hegyi@1579
|
783 |
std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl;
|
hegyi@1579
|
784 |
}
|
hegyi@1579
|
785 |
|
hegyi@1579
|
786 |
break;
|
hegyi@1579
|
787 |
}
|
hegyi@1579
|
788 |
default:
|
hegyi@1579
|
789 |
break;
|
hegyi@1579
|
790 |
}
|
hegyi@1579
|
791 |
}
|
hegyi@1579
|
792 |
}
|
hegyi@1562
|
793 |
return false;
|
hegyi@1562
|
794 |
}
|
hegyi@1562
|
795 |
|
hegyi@1524
|
796 |
void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
|
hegyi@1510
|
797 |
{
|
hegyi@1512
|
798 |
delete(nodetextmap[node_to_delete]);
|
hegyi@1510
|
799 |
delete(nodesmap[node_to_delete]);
|
hegyi@1510
|
800 |
g.erase(node_to_delete);
|
hegyi@1510
|
801 |
}
|
hegyi@1510
|
802 |
|
hegyi@1524
|
803 |
void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
|
hegyi@1510
|
804 |
{
|
hegyi@1512
|
805 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
806 |
delete(edgesmap[edge_to_delete]);
|
hegyi@1510
|
807 |
g.erase(edge_to_delete);
|
hegyi@1510
|
808 |
}
|
hegyi@1510
|
809 |
|
hegyi@1524
|
810 |
void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
|
hegyi@1510
|
811 |
{
|
hegyi@1512
|
812 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
813 |
delete(edgesmap[edge_to_delete]);
|
hegyi@1510
|
814 |
g.erase(edge_to_delete);
|
hegyi@1510
|
815 |
}
|
hegyi@1510
|
816 |
|
hegyi@1524
|
817 |
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
|
hegyi@1510
|
818 |
{
|
hegyi@1510
|
819 |
new_place+=(xy<double>(10,10));
|
hegyi@1579
|
820 |
edgetextmap[forming_edge]->property_x().set_value(new_place.x);
|
hegyi@1579
|
821 |
edgetextmap[forming_edge]->property_y().set_value(new_place.y);
|
hegyi@1510
|
822 |
}
|
hegyi@1510
|
823 |
|
hegyi@1524
|
824 |
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
|
hegyi@1510
|
825 |
{
|
hegyi@1510
|
826 |
if(on)
|
hegyi@1510
|
827 |
{
|
hegyi@1579
|
828 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
829 |
{
|
hegyi@1510
|
830 |
std::cout << "ERROR!!!! Valid edge found!" << std::endl;
|
hegyi@1510
|
831 |
}
|
hegyi@1510
|
832 |
else
|
hegyi@1510
|
833 |
{
|
hegyi@1510
|
834 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
835 |
{
|
hegyi@1510
|
836 |
if(edgesmap[i]==active_bre)
|
hegyi@1510
|
837 |
{
|
hegyi@1579
|
838 |
forming_edge=i;
|
hegyi@1510
|
839 |
}
|
hegyi@1510
|
840 |
}
|
hegyi@1510
|
841 |
}
|
hegyi@1510
|
842 |
}
|
hegyi@1510
|
843 |
else
|
hegyi@1510
|
844 |
{
|
hegyi@1579
|
845 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
846 |
{
|
hegyi@1579
|
847 |
forming_edge=INVALID;
|
hegyi@1510
|
848 |
}
|
hegyi@1510
|
849 |
else
|
hegyi@1510
|
850 |
{
|
hegyi@1510
|
851 |
std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
|
hegyi@1510
|
852 |
}
|
hegyi@1510
|
853 |
}
|
hegyi@1510
|
854 |
|
hegyi@1510
|
855 |
}
|
hegyi@1550
|
856 |
|
hegyi@1592
|
857 |
void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
|
hegyi@1585
|
858 |
{
|
hegyi@1594
|
859 |
//create the new map
|
hegyi@1592
|
860 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
|
hegyi@1592
|
861 |
mapstorage.addEdgeMap(mapname,emptr);
|
hegyi@1594
|
862 |
|
hegyi@1594
|
863 |
//add it to the list of the displayable maps
|
hegyi@1592
|
864 |
mapwin->registerNewEdgeMap(mapname);
|
hegyi@1594
|
865 |
|
hegyi@1594
|
866 |
//display it
|
hegyi@1592
|
867 |
changeEdgeText(mapname);
|
hegyi@1585
|
868 |
}
|
hegyi@1585
|
869 |
|
hegyi@1592
|
870 |
void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
|
hegyi@1585
|
871 |
{
|
hegyi@1594
|
872 |
//create the new map
|
hegyi@1592
|
873 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
|
hegyi@1592
|
874 |
mapstorage.addNodeMap(mapname,emptr);
|
hegyi@1594
|
875 |
|
hegyi@1594
|
876 |
//add it to the list of the displayable maps
|
hegyi@1592
|
877 |
mapwin->registerNewNodeMap(mapname);
|
hegyi@1594
|
878 |
|
hegyi@1594
|
879 |
//display it
|
hegyi@1592
|
880 |
changeNodeText(mapname);
|
hegyi@1585
|
881 |
}
|
hegyi@1585
|
882 |
|