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@1562
|
32 |
break;
|
hegyi@1562
|
33 |
default:
|
hegyi@1562
|
34 |
break;
|
hegyi@1562
|
35 |
}
|
hegyi@1510
|
36 |
|
hegyi@1562
|
37 |
active_item=NULL;
|
hegyi@1562
|
38 |
target_item=NULL;
|
hegyi@1562
|
39 |
active_edge=INVALID;
|
hegyi@1562
|
40 |
active_node=INVALID;
|
hegyi@1551
|
41 |
|
hegyi@1510
|
42 |
|
hegyi@1562
|
43 |
actual_tool=newtool;
|
hegyi@1562
|
44 |
|
hegyi@1562
|
45 |
switch(newtool)
|
hegyi@1562
|
46 |
{
|
hegyi@1562
|
47 |
case MOVE:
|
hegyi@1562
|
48 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
hegyi@1562
|
49 |
break;
|
hegyi@1510
|
50 |
|
hegyi@1562
|
51 |
case CREATE_NODE:
|
hegyi@1562
|
52 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
|
hegyi@1562
|
53 |
break;
|
hegyi@1510
|
54 |
|
hegyi@1562
|
55 |
case CREATE_EDGE:
|
hegyi@1562
|
56 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
|
hegyi@1562
|
57 |
break;
|
hegyi@1510
|
58 |
|
hegyi@1562
|
59 |
case ERASER:
|
hegyi@1562
|
60 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
|
hegyi@1562
|
61 |
break;
|
hegyi@1550
|
62 |
|
hegyi@1562
|
63 |
case EDGE_MAP_EDIT:
|
hegyi@1562
|
64 |
grab_focus();
|
hegyi@1562
|
65 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
hegyi@1562
|
66 |
break;
|
hegyi@1550
|
67 |
|
hegyi@1562
|
68 |
case NODE_MAP_EDIT:
|
hegyi@1562
|
69 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
hegyi@1562
|
70 |
break;
|
hegyi@1562
|
71 |
|
hegyi@1562
|
72 |
default:
|
hegyi@1562
|
73 |
break;
|
hegyi@1562
|
74 |
}
|
hegyi@1510
|
75 |
}
|
hegyi@1510
|
76 |
}
|
hegyi@1510
|
77 |
|
hegyi@1524
|
78 |
int GraphDisplayerCanvas::getActualTool()
|
hegyi@1510
|
79 |
{
|
hegyi@1510
|
80 |
return actual_tool;
|
hegyi@1510
|
81 |
}
|
hegyi@1510
|
82 |
|
hegyi@1524
|
83 |
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
|
hegyi@1510
|
84 |
{
|
hegyi@1510
|
85 |
switch(e->type)
|
hegyi@1510
|
86 |
{
|
hegyi@1510
|
87 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
88 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
89 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
90 |
|
hegyi@1525
|
91 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
92 |
active_node=INVALID;
|
hegyi@1510
|
93 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
94 |
{
|
hegyi@1510
|
95 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
96 |
{
|
hegyi@1510
|
97 |
active_node=i;
|
hegyi@1510
|
98 |
}
|
hegyi@1510
|
99 |
}
|
hegyi@1510
|
100 |
switch(e->button.button)
|
hegyi@1510
|
101 |
{
|
hegyi@1510
|
102 |
case 3:
|
hegyi@1510
|
103 |
isbutton=3;
|
hegyi@1510
|
104 |
break;
|
hegyi@1510
|
105 |
default:
|
hegyi@1510
|
106 |
isbutton=1;
|
hegyi@1510
|
107 |
break;
|
hegyi@1510
|
108 |
}
|
hegyi@1510
|
109 |
break;
|
hegyi@1510
|
110 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
111 |
isbutton=0;
|
hegyi@1510
|
112 |
active_item=NULL;
|
hegyi@1510
|
113 |
active_node=INVALID;
|
hegyi@1510
|
114 |
break;
|
hegyi@1510
|
115 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
116 |
//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
|
117 |
if(active_node!=INVALID)
|
hegyi@1510
|
118 |
{
|
hegyi@1510
|
119 |
//new coordinates will be the old values,
|
hegyi@1510
|
120 |
//because the item will be moved to the
|
hegyi@1510
|
121 |
//new coordinate therefore the new movement
|
hegyi@1510
|
122 |
//has to be calculated from here
|
hegyi@1510
|
123 |
|
hegyi@1525
|
124 |
double new_x, new_y;
|
hegyi@1525
|
125 |
|
hegyi@1525
|
126 |
window_to_world (e->motion.x, e->motion.y, new_x, new_y);
|
hegyi@1525
|
127 |
|
hegyi@1525
|
128 |
double dx=new_x-clicked_x;
|
hegyi@1525
|
129 |
double dy=new_y-clicked_y;
|
hegyi@1510
|
130 |
|
hegyi@1512
|
131 |
//repositioning node and its text
|
hegyi@1510
|
132 |
active_item->move(dx, dy);
|
hegyi@1512
|
133 |
nodetextmap[active_node]->move(dx, dy);
|
hegyi@1510
|
134 |
|
hegyi@1525
|
135 |
clicked_x=new_x;
|
hegyi@1525
|
136 |
clicked_y=new_y;
|
hegyi@1510
|
137 |
|
hegyi@1510
|
138 |
//all the edges connected to the moved point has to be redrawn
|
hegyi@1510
|
139 |
EdgeIt ei;
|
hegyi@1510
|
140 |
|
hegyi@1510
|
141 |
g.firstOut(ei,active_node);
|
hegyi@1510
|
142 |
|
hegyi@1510
|
143 |
for(;ei!=INVALID;g.nextOut(ei))
|
hegyi@1510
|
144 |
{
|
hegyi@1510
|
145 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
146 |
double x1, x2, y1, y2;
|
hegyi@1510
|
147 |
|
hegyi@1510
|
148 |
nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
149 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
150 |
|
hegyi@1510
|
151 |
nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
152 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
153 |
|
hegyi@1510
|
154 |
if(isbutton==3)
|
hegyi@1510
|
155 |
{
|
hegyi@1524
|
156 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
157 |
}
|
hegyi@1510
|
158 |
else
|
hegyi@1510
|
159 |
{
|
hegyi@1524
|
160 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
161 |
}
|
hegyi@1510
|
162 |
|
hegyi@1512
|
163 |
//reposition of edgetext
|
hegyi@1524
|
164 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
165 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
166 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
167 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
168 |
}
|
hegyi@1510
|
169 |
|
hegyi@1510
|
170 |
g.firstIn(ei,active_node);
|
hegyi@1510
|
171 |
for(;ei!=INVALID;g.nextIn(ei))
|
hegyi@1510
|
172 |
{
|
hegyi@1510
|
173 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
174 |
double x1, x2, y1, y2;
|
hegyi@1510
|
175 |
|
hegyi@1510
|
176 |
nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
177 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
178 |
|
hegyi@1510
|
179 |
nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
180 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
181 |
|
hegyi@1510
|
182 |
if(isbutton==3)
|
hegyi@1510
|
183 |
{
|
hegyi@1524
|
184 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
185 |
}
|
hegyi@1510
|
186 |
else
|
hegyi@1510
|
187 |
{
|
hegyi@1524
|
188 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
189 |
}
|
hegyi@1510
|
190 |
|
hegyi@1524
|
191 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
192 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
193 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
194 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
195 |
}
|
hegyi@1510
|
196 |
}
|
hegyi@1510
|
197 |
default: break;
|
hegyi@1510
|
198 |
}
|
hegyi@1510
|
199 |
|
hegyi@1525
|
200 |
return false;
|
hegyi@1510
|
201 |
}
|
hegyi@1510
|
202 |
|
hegyi@1524
|
203 |
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
|
hegyi@1510
|
204 |
{
|
hegyi@1510
|
205 |
switch(e->type)
|
hegyi@1510
|
206 |
{
|
hegyi@1510
|
207 |
|
hegyi@1510
|
208 |
//draw the new node in red at the clicked place
|
hegyi@1525
|
209 |
case GDK_2BUTTON_PRESS:
|
hegyi@1525
|
210 |
std::cout << "double click" << std::endl;
|
hegyi@1525
|
211 |
break;
|
hegyi@1510
|
212 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
213 |
isbutton=1;
|
hegyi@1510
|
214 |
|
hegyi@1510
|
215 |
active_node=NodeIt(g,g.addNode());
|
hegyi@1510
|
216 |
|
hegyi@1510
|
217 |
//initiating values corresponding to new node in maps
|
hegyi@1510
|
218 |
|
hegyi@1510
|
219 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1510
|
220 |
|
hegyi@1525
|
221 |
target_item=NULL;
|
hegyi@1525
|
222 |
target_item=get_item_at(clicked_x, clicked_y);
|
hegyi@1525
|
223 |
|
hegyi@1510
|
224 |
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
|
hegyi@1510
|
225 |
active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
|
hegyi@1510
|
226 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1510
|
227 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@1510
|
228 |
(nodesmap[active_node])->show();
|
hegyi@1512
|
229 |
|
hegyi@1512
|
230 |
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
|
231 |
nodetextmap[active_node]->property_fill_color().set_value("darkblue");
|
hegyi@1512
|
232 |
|
hegyi@1524
|
233 |
mapwin->updateNode(active_node);
|
hegyi@1512
|
234 |
|
hegyi@1510
|
235 |
break;
|
hegyi@1510
|
236 |
|
hegyi@1510
|
237 |
//move the new node
|
hegyi@1510
|
238 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
239 |
{
|
hegyi@1510
|
240 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1525
|
241 |
generated->motion.x=e->motion.x;
|
hegyi@1525
|
242 |
generated->motion.y=e->motion.y;
|
hegyi@1510
|
243 |
generated->type=GDK_MOTION_NOTIFY;
|
hegyi@1524
|
244 |
moveEventHandler(generated);
|
hegyi@1510
|
245 |
break;
|
hegyi@1510
|
246 |
}
|
hegyi@1510
|
247 |
|
hegyi@1510
|
248 |
//finalize the new node
|
hegyi@1510
|
249 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
250 |
isbutton=0;
|
hegyi@1525
|
251 |
if(!target_item)
|
hegyi@1525
|
252 |
{
|
hegyi@1525
|
253 |
//Its appropriate color is given by update.
|
hegyi@1525
|
254 |
//*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1525
|
255 |
}
|
hegyi@1525
|
256 |
else
|
hegyi@1525
|
257 |
{
|
hegyi@1525
|
258 |
//In this case the given color has to be overwritten, because the noe covers an other item.
|
hegyi@1525
|
259 |
*active_item << Gnome::Canvas::Properties::fill_color("lightblue");
|
hegyi@1525
|
260 |
}
|
hegyi@1525
|
261 |
target_item=NULL;
|
hegyi@1510
|
262 |
active_item=NULL;
|
hegyi@1510
|
263 |
active_node=INVALID;
|
hegyi@1510
|
264 |
break;
|
hegyi@1510
|
265 |
default:
|
hegyi@1510
|
266 |
break;
|
hegyi@1510
|
267 |
}
|
hegyi@1510
|
268 |
return false;
|
hegyi@1510
|
269 |
}
|
hegyi@1510
|
270 |
|
hegyi@1524
|
271 |
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
|
hegyi@1510
|
272 |
{
|
hegyi@1510
|
273 |
switch(e->type)
|
hegyi@1510
|
274 |
{
|
hegyi@1510
|
275 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
276 |
//in edge creation right button has special meaning
|
hegyi@1510
|
277 |
if(e->button.button!=3)
|
hegyi@1510
|
278 |
{
|
hegyi@1510
|
279 |
//there is not yet selected node
|
hegyi@1510
|
280 |
if(active_node==INVALID)
|
hegyi@1510
|
281 |
{
|
hegyi@1510
|
282 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
283 |
|
hegyi@1525
|
284 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
285 |
|
hegyi@1525
|
286 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
287 |
active_node=INVALID;
|
hegyi@1510
|
288 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
289 |
{
|
hegyi@1510
|
290 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
291 |
{
|
hegyi@1510
|
292 |
active_node=i;
|
hegyi@1510
|
293 |
}
|
hegyi@1510
|
294 |
}
|
hegyi@1510
|
295 |
//the clicked item is really a node
|
hegyi@1510
|
296 |
if(active_node!=INVALID)
|
hegyi@1510
|
297 |
{
|
hegyi@1510
|
298 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1510
|
299 |
isbutton=1;
|
hegyi@1510
|
300 |
}
|
hegyi@1510
|
301 |
//clicked item was not a node. It could be e.g. edge.
|
hegyi@1510
|
302 |
else
|
hegyi@1510
|
303 |
{
|
hegyi@1510
|
304 |
active_item=NULL;
|
hegyi@1510
|
305 |
}
|
hegyi@1510
|
306 |
}
|
hegyi@1510
|
307 |
//we only have to do sg. if the mouse button
|
hegyi@1510
|
308 |
// is pressed already once AND the click was
|
hegyi@1510
|
309 |
// on a node that was found in the set of
|
hegyi@1510
|
310 |
//nodes, and now we only search for the second
|
hegyi@1510
|
311 |
//node
|
hegyi@1510
|
312 |
else
|
hegyi@1510
|
313 |
{
|
hegyi@1525
|
314 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
315 |
target_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
316 |
Graph::NodeIt target_node=INVALID;
|
hegyi@1510
|
317 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
318 |
{
|
hegyi@1510
|
319 |
if(nodesmap[i]==target_item)
|
hegyi@1510
|
320 |
{
|
hegyi@1510
|
321 |
target_node=i;
|
hegyi@1510
|
322 |
}
|
hegyi@1510
|
323 |
}
|
hegyi@1510
|
324 |
//the clicked item is a node, the edge can be drawn
|
hegyi@1510
|
325 |
if(target_node!=INVALID)
|
hegyi@1510
|
326 |
{
|
hegyi@1512
|
327 |
if(target_node!=active_node)
|
hegyi@1512
|
328 |
{
|
hegyi@1512
|
329 |
*(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1510
|
330 |
|
hegyi@1512
|
331 |
//creating new edge
|
hegyi@1512
|
332 |
active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
|
hegyi@1510
|
333 |
|
hegyi@1512
|
334 |
//initiating values corresponding to new edge in maps
|
hegyi@1524
|
335 |
mapstorage.initMapsForEdge(active_edge);
|
hegyi@1510
|
336 |
|
hegyi@1512
|
337 |
//calculating coordinates of new edge
|
hegyi@1512
|
338 |
Gnome::Canvas::Points coos;
|
hegyi@1512
|
339 |
double x1, x2, y1, y2;
|
hegyi@1510
|
340 |
|
hegyi@1512
|
341 |
active_item->get_bounds(x1, y1, x2, y2);
|
hegyi@1512
|
342 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
343 |
|
hegyi@1512
|
344 |
target_item->get_bounds(x1, y1, x2, y2);
|
hegyi@1512
|
345 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
346 |
|
hegyi@1512
|
347 |
//drawing new edge
|
hegyi@1512
|
348 |
edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
|
hegyi@1512
|
349 |
*(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@1512
|
350 |
edgesmap[active_edge]->property_width_pixels().set_value(10);
|
hegyi@1510
|
351 |
|
hegyi@1512
|
352 |
//redraw nodes to blank terminations of the new edge
|
hegyi@1512
|
353 |
target_item->raise_to_top();
|
hegyi@1512
|
354 |
active_item->raise_to_top();
|
hegyi@1510
|
355 |
|
hegyi@1512
|
356 |
//initializing edge-text as well, to empty string
|
hegyi@1524
|
357 |
xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
|
hegyi@1512
|
358 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
359 |
|
hegyi@1512
|
360 |
edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@1512
|
361 |
edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
|
hegyi@1512
|
362 |
|
hegyi@1512
|
363 |
//updating its properties
|
hegyi@1524
|
364 |
mapwin->updateEdge(active_edge);
|
hegyi@1512
|
365 |
}
|
hegyi@1512
|
366 |
else
|
hegyi@1512
|
367 |
{
|
hegyi@1512
|
368 |
target_node=INVALID;
|
hegyi@1512
|
369 |
std::cout << "Loop edge is not yet implemented!" << std::endl;
|
hegyi@1512
|
370 |
}
|
hegyi@1510
|
371 |
}
|
hegyi@1510
|
372 |
//clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
|
hegyi@1510
|
373 |
else
|
hegyi@1510
|
374 |
{
|
hegyi@1510
|
375 |
target_item=NULL;
|
hegyi@1510
|
376 |
}
|
hegyi@1510
|
377 |
}
|
hegyi@1510
|
378 |
}
|
hegyi@1510
|
379 |
break;
|
hegyi@1510
|
380 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
381 |
isbutton=0;
|
hegyi@1510
|
382 |
//we clear settings in two cases
|
hegyi@1510
|
383 |
//1: the edge is ready (target_item has valid value)
|
hegyi@1510
|
384 |
//2: the edge creation is cancelled with right button
|
hegyi@1510
|
385 |
if((target_item)||(e->button.button==3))
|
hegyi@1510
|
386 |
{
|
hegyi@1510
|
387 |
if(active_item)
|
hegyi@1510
|
388 |
{
|
hegyi@1510
|
389 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1510
|
390 |
active_item=NULL;
|
hegyi@1510
|
391 |
}
|
hegyi@1510
|
392 |
if(target_item)
|
hegyi@1510
|
393 |
{
|
hegyi@1510
|
394 |
*target_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1510
|
395 |
target_item=NULL;
|
hegyi@1510
|
396 |
}
|
hegyi@1510
|
397 |
active_node=INVALID;
|
hegyi@1510
|
398 |
active_edge=INVALID;
|
hegyi@1510
|
399 |
}
|
hegyi@1510
|
400 |
break;
|
hegyi@1510
|
401 |
default:
|
hegyi@1510
|
402 |
break;
|
hegyi@1510
|
403 |
}
|
hegyi@1510
|
404 |
return false;
|
hegyi@1510
|
405 |
}
|
hegyi@1510
|
406 |
|
hegyi@1524
|
407 |
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
|
hegyi@1510
|
408 |
{
|
hegyi@1510
|
409 |
switch(e->type)
|
hegyi@1510
|
410 |
{
|
hegyi@1510
|
411 |
case GDK_BUTTON_PRESS:
|
hegyi@1525
|
412 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
413 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
414 |
active_node=INVALID;
|
hegyi@1510
|
415 |
active_edge=INVALID;
|
hegyi@1510
|
416 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
417 |
{
|
hegyi@1510
|
418 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
419 |
{
|
hegyi@1510
|
420 |
active_node=i;
|
hegyi@1510
|
421 |
}
|
hegyi@1510
|
422 |
}
|
hegyi@1510
|
423 |
if(active_node==INVALID)
|
hegyi@1510
|
424 |
{
|
hegyi@1510
|
425 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
426 |
{
|
hegyi@1510
|
427 |
if(edgesmap[i]==active_item)
|
hegyi@1510
|
428 |
{
|
hegyi@1510
|
429 |
active_edge=i;
|
hegyi@1510
|
430 |
}
|
hegyi@1510
|
431 |
}
|
hegyi@1510
|
432 |
}
|
hegyi@1525
|
433 |
if(active_item)
|
hegyi@1525
|
434 |
{
|
hegyi@1525
|
435 |
*active_item << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1525
|
436 |
}
|
hegyi@1510
|
437 |
break;
|
hegyi@1510
|
438 |
|
hegyi@1510
|
439 |
case GDK_BUTTON_RELEASE:
|
hegyi@1525
|
440 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
441 |
if(active_item)
|
hegyi@1510
|
442 |
{
|
hegyi@1525
|
443 |
if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
|
hegyi@1510
|
444 |
{
|
hegyi@1525
|
445 |
if(active_node!=INVALID)
|
hegyi@1525
|
446 |
{
|
hegyi@1510
|
447 |
|
hegyi@1525
|
448 |
//collecting edges to delete
|
hegyi@1525
|
449 |
EdgeIt e;
|
hegyi@1525
|
450 |
std::set<Graph::Edge> edges_to_delete;
|
hegyi@1510
|
451 |
|
hegyi@1525
|
452 |
g.firstOut(e,active_node);
|
hegyi@1525
|
453 |
for(;e!=INVALID;g.nextOut(e))
|
hegyi@1525
|
454 |
{
|
hegyi@1525
|
455 |
edges_to_delete.insert(e);
|
hegyi@1525
|
456 |
}
|
hegyi@1525
|
457 |
|
hegyi@1525
|
458 |
g.firstIn(e,active_node);
|
hegyi@1525
|
459 |
for(;e!=INVALID;g.nextIn(e))
|
hegyi@1525
|
460 |
{
|
hegyi@1525
|
461 |
edges_to_delete.insert(e);
|
hegyi@1525
|
462 |
}
|
hegyi@1525
|
463 |
|
hegyi@1525
|
464 |
//deleting collected edges
|
hegyi@1525
|
465 |
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
|
466 |
{
|
hegyi@1525
|
467 |
deleteItem(*edge_set_it);
|
hegyi@1525
|
468 |
}
|
hegyi@1525
|
469 |
deleteItem(active_node);
|
hegyi@1525
|
470 |
}
|
hegyi@1525
|
471 |
//a simple edge was chosen
|
hegyi@1525
|
472 |
else
|
hegyi@1510
|
473 |
{
|
hegyi@1525
|
474 |
deleteItem(active_edge);
|
hegyi@1510
|
475 |
}
|
hegyi@1510
|
476 |
}
|
hegyi@1525
|
477 |
//pointer was moved, deletion is cancelled
|
hegyi@1510
|
478 |
else
|
hegyi@1510
|
479 |
{
|
hegyi@1525
|
480 |
if(active_node!=INVALID)
|
hegyi@1525
|
481 |
{
|
hegyi@1525
|
482 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1525
|
483 |
}
|
hegyi@1525
|
484 |
else
|
hegyi@1525
|
485 |
{
|
hegyi@1525
|
486 |
*active_item << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@1525
|
487 |
}
|
hegyi@1510
|
488 |
}
|
hegyi@1510
|
489 |
}
|
hegyi@1510
|
490 |
//reseting datas
|
hegyi@1510
|
491 |
active_item=NULL;
|
hegyi@1510
|
492 |
active_edge=INVALID;
|
hegyi@1510
|
493 |
active_node=INVALID;
|
hegyi@1510
|
494 |
break;
|
hegyi@1510
|
495 |
|
hegyi@1510
|
496 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
497 |
break;
|
hegyi@1510
|
498 |
|
hegyi@1510
|
499 |
default:
|
hegyi@1510
|
500 |
break;
|
hegyi@1510
|
501 |
}
|
hegyi@1525
|
502 |
return false;
|
hegyi@1510
|
503 |
}
|
hegyi@1510
|
504 |
|
hegyi@1550
|
505 |
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
506 |
{
|
hegyi@1550
|
507 |
switch(e->type)
|
hegyi@1550
|
508 |
{
|
hegyi@1562
|
509 |
case GDK_KEY_PRESS:
|
hegyi@1562
|
510 |
{
|
hegyi@1562
|
511 |
std::cout << "Any button was pressed" << std::endl;
|
hegyi@1562
|
512 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@1562
|
513 |
{
|
hegyi@1562
|
514 |
case GDK_A:
|
hegyi@1562
|
515 |
std::cout << "A button was pressed" << std::endl;
|
hegyi@1562
|
516 |
break;
|
hegyi@1562
|
517 |
default:
|
hegyi@1562
|
518 |
break;
|
hegyi@1562
|
519 |
}
|
hegyi@1562
|
520 |
|
hegyi@1562
|
521 |
break;
|
hegyi@1562
|
522 |
}
|
hegyi@1550
|
523 |
case GDK_BUTTON_PRESS:
|
hegyi@1562
|
524 |
{
|
hegyi@1562
|
525 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1562
|
526 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1562
|
527 |
Graph::EdgeIt clicked_edge=INVALID;
|
hegyi@1562
|
528 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1562
|
529 |
{
|
hegyi@1562
|
530 |
if(edgesmap[i]==active_item)
|
hegyi@1562
|
531 |
{
|
hegyi@1562
|
532 |
clicked_edge=i;
|
hegyi@1562
|
533 |
}
|
hegyi@1562
|
534 |
}
|
hegyi@1562
|
535 |
if(clicked_edge!=INVALID)
|
hegyi@1562
|
536 |
{
|
hegyi@1562
|
537 |
if(edgetextmap[clicked_edge]->property_text().get_value()!="")
|
hegyi@1562
|
538 |
{
|
hegyi@1562
|
539 |
active_edge=clicked_edge;
|
hegyi@1562
|
540 |
if(canvasentrywidget)
|
hegyi@1562
|
541 |
{
|
hegyi@1562
|
542 |
delete(canvasentrywidget);
|
hegyi@1562
|
543 |
}
|
hegyi@1562
|
544 |
entrywidget.show();
|
hegyi@1562
|
545 |
entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
|
hegyi@1562
|
546 |
xy<double> entry_coos;
|
hegyi@1562
|
547 |
entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
|
hegyi@1562
|
548 |
entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
|
hegyi@1562
|
549 |
entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
|
hegyi@1562
|
550 |
entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
|
hegyi@1562
|
551 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@1562
|
552 |
canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
|
hegyi@1562
|
553 |
canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
|
hegyi@1562
|
554 |
}
|
hegyi@1562
|
555 |
}
|
hegyi@1562
|
556 |
else
|
hegyi@1562
|
557 |
{
|
hegyi@1562
|
558 |
//mentse el -> problema, hogy nem tudja melyik map-be
|
hegyi@1562
|
559 |
entrywidget.hide();
|
hegyi@1562
|
560 |
}
|
hegyi@1562
|
561 |
break;
|
hegyi@1562
|
562 |
}
|
hegyi@1550
|
563 |
default:
|
hegyi@1550
|
564 |
break;
|
hegyi@1550
|
565 |
}
|
hegyi@1550
|
566 |
return false;
|
hegyi@1550
|
567 |
}
|
hegyi@1550
|
568 |
|
hegyi@1550
|
569 |
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
570 |
{
|
hegyi@1550
|
571 |
e=e;
|
hegyi@1550
|
572 |
return false;
|
hegyi@1550
|
573 |
}
|
hegyi@1550
|
574 |
|
hegyi@1562
|
575 |
bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
|
hegyi@1562
|
576 |
{
|
hegyi@1562
|
577 |
Glib::ustring mapvalue = entrywidget.get_text();
|
hegyi@1562
|
578 |
std::cout << mapvalue << std::endl;
|
hegyi@1562
|
579 |
e=e;
|
hegyi@1562
|
580 |
return false;
|
hegyi@1562
|
581 |
}
|
hegyi@1562
|
582 |
|
hegyi@1524
|
583 |
void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
|
hegyi@1510
|
584 |
{
|
hegyi@1512
|
585 |
delete(nodetextmap[node_to_delete]);
|
hegyi@1510
|
586 |
delete(nodesmap[node_to_delete]);
|
hegyi@1510
|
587 |
g.erase(node_to_delete);
|
hegyi@1510
|
588 |
}
|
hegyi@1510
|
589 |
|
hegyi@1524
|
590 |
void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
|
hegyi@1510
|
591 |
{
|
hegyi@1512
|
592 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
593 |
delete(edgesmap[edge_to_delete]);
|
hegyi@1510
|
594 |
g.erase(edge_to_delete);
|
hegyi@1510
|
595 |
}
|
hegyi@1510
|
596 |
|
hegyi@1524
|
597 |
void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
|
hegyi@1510
|
598 |
{
|
hegyi@1512
|
599 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
600 |
delete(edgesmap[edge_to_delete]);
|
hegyi@1510
|
601 |
g.erase(edge_to_delete);
|
hegyi@1510
|
602 |
}
|
hegyi@1510
|
603 |
|
hegyi@1524
|
604 |
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
|
hegyi@1510
|
605 |
{
|
hegyi@1510
|
606 |
new_place+=(xy<double>(10,10));
|
hegyi@1510
|
607 |
edgetextmap[active_edge]->property_x().set_value(new_place.x);
|
hegyi@1510
|
608 |
edgetextmap[active_edge]->property_y().set_value(new_place.y);
|
hegyi@1510
|
609 |
}
|
hegyi@1510
|
610 |
|
hegyi@1524
|
611 |
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
|
hegyi@1510
|
612 |
{
|
hegyi@1510
|
613 |
if(on)
|
hegyi@1510
|
614 |
{
|
hegyi@1510
|
615 |
if(active_edge!=INVALID)
|
hegyi@1510
|
616 |
{
|
hegyi@1510
|
617 |
std::cout << "ERROR!!!! Valid edge found!" << std::endl;
|
hegyi@1510
|
618 |
}
|
hegyi@1510
|
619 |
else
|
hegyi@1510
|
620 |
{
|
hegyi@1510
|
621 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
hegyi@1510
|
622 |
{
|
hegyi@1510
|
623 |
if(edgesmap[i]==active_bre)
|
hegyi@1510
|
624 |
{
|
hegyi@1510
|
625 |
active_edge=i;
|
hegyi@1510
|
626 |
}
|
hegyi@1510
|
627 |
}
|
hegyi@1510
|
628 |
}
|
hegyi@1510
|
629 |
}
|
hegyi@1510
|
630 |
else
|
hegyi@1510
|
631 |
{
|
hegyi@1510
|
632 |
if(active_edge!=INVALID)
|
hegyi@1510
|
633 |
{
|
hegyi@1510
|
634 |
active_edge=INVALID;
|
hegyi@1510
|
635 |
}
|
hegyi@1510
|
636 |
else
|
hegyi@1510
|
637 |
{
|
hegyi@1510
|
638 |
std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
|
hegyi@1510
|
639 |
}
|
hegyi@1510
|
640 |
}
|
hegyi@1510
|
641 |
|
hegyi@1510
|
642 |
}
|
hegyi@1550
|
643 |
|