97 //has to be calculated from here |
97 //has to be calculated from here |
98 |
98 |
99 double dx=e->motion.x-clicked_x; |
99 double dx=e->motion.x-clicked_x; |
100 double dy=e->motion.y-clicked_y; |
100 double dy=e->motion.y-clicked_y; |
101 |
101 |
|
102 //repositioning node and its text |
102 active_item->move(dx, dy); |
103 active_item->move(dx, dy); |
|
104 nodetextmap[active_node]->move(dx, dy); |
103 |
105 |
104 clicked_x=e->motion.x; |
106 clicked_x=e->motion.x; |
105 clicked_y=e->motion.y; |
107 clicked_y=e->motion.y; |
106 |
108 |
107 //all the edges connected to the moved point has to be redrawn |
109 //all the edges connected to the moved point has to be redrawn |
187 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
190 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
188 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
191 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
189 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); |
192 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); |
190 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); |
193 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); |
191 (nodesmap[active_node])->show(); |
194 (nodesmap[active_node])->show(); |
|
195 |
|
196 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, ""); |
|
197 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); |
|
198 |
|
199 mapwin->update_node(active_node); |
|
200 |
192 break; |
201 break; |
193 |
202 |
194 //move the new node |
203 //move the new node |
195 case GDK_MOTION_NOTIFY: |
204 case GDK_MOTION_NOTIFY: |
196 { |
205 { |
270 } |
279 } |
271 } |
280 } |
272 //the clicked item is a node, the edge can be drawn |
281 //the clicked item is a node, the edge can be drawn |
273 if(target_node!=INVALID) |
282 if(target_node!=INVALID) |
274 { |
283 { |
275 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); |
284 if(target_node!=active_node) |
276 |
285 { |
277 //creating new edge |
286 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); |
278 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
287 |
279 |
288 //creating new edge |
280 //initiating values corresponding to new edge in maps |
289 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
281 mapstorage.init_maps_for_edge(active_edge); |
290 |
|
291 //initiating values corresponding to new edge in maps |
|
292 mapstorage.init_maps_for_edge(active_edge); |
282 |
293 |
283 //calculating coordinates of new edge |
294 //calculating coordinates of new edge |
284 Gnome::Canvas::Points coos; |
295 Gnome::Canvas::Points coos; |
285 double x1, x2, y1, y2; |
296 double x1, x2, y1, y2; |
286 |
297 |
287 active_item->get_bounds(x1, y1, x2, y2); |
298 active_item->get_bounds(x1, y1, x2, y2); |
288 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
299 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
289 |
300 |
290 target_item->get_bounds(x1, y1, x2, y2); |
301 target_item->get_bounds(x1, y1, x2, y2); |
291 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
302 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
292 |
303 |
293 //drawing new edge |
304 //drawing new edge |
294 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this); |
305 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this); |
295 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); |
306 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); |
296 edgesmap[active_edge]->property_width_pixels().set_value(10); |
307 edgesmap[active_edge]->property_width_pixels().set_value(10); |
297 |
308 |
298 //redraw nodes to blank terminations of the new edge |
309 //redraw nodes to blank terminations of the new edge |
299 target_item->raise_to_top(); |
310 target_item->raise_to_top(); |
300 active_item->raise_to_top(); |
311 active_item->raise_to_top(); |
301 |
312 |
302 //initializing edge-text as well, to empty string |
313 //initializing edge-text as well, to empty string |
303 xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos(); |
314 xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos(); |
304 text_pos+=(xy<double>(10,10)); |
315 text_pos+=(xy<double>(10,10)); |
305 |
316 |
306 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); |
317 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); |
307 edgetextmap[active_edge]->property_fill_color().set_value("black"); |
318 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); |
|
319 |
|
320 //updating its properties |
|
321 mapwin->update_edge(active_edge); |
|
322 } |
|
323 else |
|
324 { |
|
325 target_node=INVALID; |
|
326 std::cout << "Loop edge is not yet implemented!" << std::endl; |
|
327 } |
308 } |
328 } |
309 //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. |
329 //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. |
310 else |
330 else |
311 { |
331 { |
312 target_item=NULL; |
332 target_item=NULL; |
433 return true; |
453 return true; |
434 } |
454 } |
435 |
455 |
436 void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete) |
456 void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete) |
437 { |
457 { |
|
458 delete(nodetextmap[node_to_delete]); |
438 delete(nodesmap[node_to_delete]); |
459 delete(nodesmap[node_to_delete]); |
439 g.erase(node_to_delete); |
460 g.erase(node_to_delete); |
440 } |
461 } |
441 |
462 |
442 void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete) |
463 void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete) |
443 { |
464 { |
|
465 delete(edgetextmap[edge_to_delete]); |
444 delete(edgesmap[edge_to_delete]); |
466 delete(edgesmap[edge_to_delete]); |
445 g.erase(edge_to_delete); |
467 g.erase(edge_to_delete); |
446 } |
468 } |
447 |
469 |
448 void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete) |
470 void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete) |
449 { |
471 { |
|
472 delete(edgetextmap[edge_to_delete]); |
450 delete(edgesmap[edge_to_delete]); |
473 delete(edgesmap[edge_to_delete]); |
451 g.erase(edge_to_delete); |
474 g.erase(edge_to_delete); |
452 } |
475 } |
453 |
476 |
454 void GraphDisplayerCanvas::text_reposition(xy<double> new_place) |
477 void GraphDisplayerCanvas::text_reposition(xy<double> new_place) |