188 clicked_y=new_y; |
190 clicked_y=new_y; |
189 |
191 |
190 // reposition the coordinates text |
192 // reposition the coordinates text |
191 std::ostringstream ostr; |
193 std::ostringstream ostr; |
192 ostr << "(" << |
194 ostr << "(" << |
193 (mytab.mapstorage).coords[active_node].x << ", " << |
195 (mytab.mapstorage)->coords[active_node].x << ", " << |
194 (mytab.mapstorage).coords[active_node].y << ")"; |
196 (mytab.mapstorage)->coords[active_node].y << ")"; |
195 double radius = |
197 double radius = |
196 (nodesmap[active_node]->property_x2().get_value() - |
198 (nodesmap[active_node]->property_x2().get_value() - |
197 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
199 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
198 if (coord_text) |
200 if (coord_text) |
199 { |
201 { |
200 coord_text->property_text().set_value(ostr.str()); |
202 coord_text->property_text().set_value(ostr.str()); |
201 coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x + |
203 coord_text->property_x().set_value((mytab.mapstorage)->coords[active_node].x + |
202 radius); |
204 radius); |
203 coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y - |
205 coord_text->property_y().set_value((mytab.mapstorage)->coords[active_node].y - |
204 radius); |
206 radius); |
205 } |
207 } |
206 else |
208 else |
207 { |
209 { |
208 coord_text = new Gnome::Canvas::Text( |
210 coord_text = new Gnome::Canvas::Text( |
209 displayed_graph, |
211 displayed_graph, |
210 (mytab.mapstorage).coords[active_node].x + radius, |
212 (mytab.mapstorage)->coords[active_node].x + radius, |
211 (mytab.mapstorage).coords[active_node].y - radius, |
213 (mytab.mapstorage)->coords[active_node].y - radius, |
212 ostr.str()); |
214 ostr.str()); |
213 coord_text->property_fill_color().set_value("black"); |
215 coord_text->property_fill_color().set_value("black"); |
214 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
216 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
215 } |
217 } |
216 |
218 |
297 moveEventHandler(generated); |
299 moveEventHandler(generated); |
298 break; |
300 break; |
299 } |
301 } |
300 |
302 |
301 case GDK_BUTTON_RELEASE: |
303 case GDK_BUTTON_RELEASE: |
302 (mytab.mapstorage).modified = true; |
304 (mytab.mapstorage)->modified = true; |
303 |
305 |
304 is_drawn=true; |
306 is_drawn=true; |
305 |
307 |
306 isbutton=1; |
308 isbutton=1; |
307 |
309 |
308 active_node=(mytab.mapstorage).graph.addNode(); |
310 active_node=(mytab.mapstorage)->graph.addNode(); |
309 |
311 |
310 //initiating values corresponding to new node in maps |
312 //initiating values corresponding to new node in maps |
311 |
313 |
312 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
314 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
313 |
315 |
314 // update coordinates |
316 // update coordinates |
315 (mytab.mapstorage).coords.set(active_node, XY(clicked_x, clicked_y)); |
317 (mytab.mapstorage)->coords.set(active_node, XY(clicked_x, clicked_y)); |
316 |
318 |
317 // update all other maps |
319 // update all other maps |
318 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
320 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
319 (mytab.mapstorage).nodemap_storage.begin(); it != |
321 (mytab.mapstorage)->nodemap_storage.begin(); it != |
320 (mytab.mapstorage).nodemap_storage.end(); ++it) |
322 (mytab.mapstorage)->nodemap_storage.end(); ++it) |
321 { |
323 { |
322 if ((it->first != "coordinates_x") && |
324 if ((it->first != "coordinates_x") && |
323 (it->first != "coordinates_y")) |
325 (it->first != "coordinates_y")) |
324 { |
326 { |
325 (*(it->second))[active_node] = |
327 (*(it->second))[active_node] = |
326 (mytab.mapstorage).nodemap_default[it->first]; |
328 (mytab.mapstorage)->nodemap_default[it->first]; |
327 } |
329 } |
328 } |
330 } |
329 // increment the id map's default value |
331 // increment the id map's default value |
330 (mytab.mapstorage).nodemap_default["label"] += 1.0; |
332 (mytab.mapstorage)->nodemap_default["label"] += 1.0; |
331 |
333 |
332 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, |
334 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, |
333 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
335 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
334 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
336 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
335 *(nodesmap[active_node]) << |
337 *(nodesmap[active_node]) << |
404 else |
406 else |
405 { |
407 { |
406 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
408 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
407 target_item=(get_item_at(clicked_x, clicked_y)); |
409 target_item=(get_item_at(clicked_x, clicked_y)); |
408 Node target_node=INVALID; |
410 Node target_node=INVALID; |
409 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
411 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
410 { |
412 { |
411 if(nodesmap[i]==target_item) |
413 if(nodesmap[i]==target_item) |
412 { |
414 { |
413 target_node=i; |
415 target_node=i; |
414 } |
416 } |
415 } |
417 } |
416 //the clicked item is a node, the edge can be drawn |
418 //the clicked item is a node, the edge can be drawn |
417 if(target_node!=INVALID) |
419 if(target_node!=INVALID) |
418 { |
420 { |
419 (mytab.mapstorage).modified = true; |
421 (mytab.mapstorage)->modified = true; |
420 |
422 |
421 *(nodesmap[target_node]) << |
423 *(nodesmap[target_node]) << |
422 Gnome::Canvas::Properties::fill_color("red"); |
424 Gnome::Canvas::Properties::fill_color("red"); |
423 |
425 |
424 //creating new edge |
426 //creating new edge |
425 active_edge=(mytab.mapstorage).graph.addEdge(active_node, |
427 active_edge=(mytab.mapstorage)->graph.addEdge(active_node, |
426 target_node); |
428 target_node); |
427 |
429 |
428 // update maps |
430 // update maps |
429 for (std::map<std::string, |
431 for (std::map<std::string, |
430 Graph::EdgeMap<double>*>::const_iterator it = |
432 Graph::EdgeMap<double>*>::const_iterator it = |
431 (mytab.mapstorage).edgemap_storage.begin(); it != |
433 (mytab.mapstorage)->edgemap_storage.begin(); it != |
432 (mytab.mapstorage).edgemap_storage.end(); ++it) |
434 (mytab.mapstorage)->edgemap_storage.end(); ++it) |
433 { |
435 { |
434 (*(it->second))[active_edge] = |
436 (*(it->second))[active_edge] = |
435 (mytab.mapstorage).edgemap_default[it->first]; |
437 (mytab.mapstorage)->edgemap_default[it->first]; |
436 } |
438 } |
437 // increment the id map's default value |
439 // increment the id map's default value |
438 (mytab.mapstorage).edgemap_default["label"] += 1.0; |
440 (mytab.mapstorage)->edgemap_default["label"] += 1.0; |
439 |
441 |
440 if(target_node!=active_node) |
442 if(target_node!=active_node) |
441 { |
443 { |
442 // set the coordinates of the arrow on the new edge |
444 // set the coordinates of the arrow on the new edge |
443 MapStorage& ms = mytab.mapstorage; |
445 MapStorage& ms = *mytab.mapstorage; |
444 ms.arrow_pos.set(active_edge, |
446 ms.arrow_pos.set(active_edge, |
445 (ms.coords[ms.graph.source(active_edge)] + |
447 (ms.coords[ms.graph.source(active_edge)] + |
446 ms.coords[ms.graph.target(active_edge)])/ 2.0); |
448 ms.coords[ms.graph.target(active_edge)])/ 2.0); |
447 |
449 |
448 //drawing new edge |
450 //drawing new edge |
450 *this); |
452 *this); |
451 } |
453 } |
452 else |
454 else |
453 { |
455 { |
454 // set the coordinates of the arrow on the new edge |
456 // set the coordinates of the arrow on the new edge |
455 MapStorage& ms = mytab.mapstorage; |
457 MapStorage& ms = *mytab.mapstorage; |
456 ms.arrow_pos.set(active_edge, |
458 ms.arrow_pos.set(active_edge, |
457 (ms.coords[ms.graph.source(active_edge)] + |
459 (ms.coords[ms.graph.source(active_edge)] + |
458 XY(0.0, 80.0))); |
460 XY(0.0, 80.0))); |
459 |
461 |
460 //drawing new edge |
462 //drawing new edge |
461 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, |
463 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, |
462 *this); |
464 *this); |
463 } |
465 } |
464 |
466 |
465 //initializing edge-text as well, to empty string |
467 //initializing edge-text as well, to empty string |
466 XY text_pos=mytab.mapstorage.arrow_pos[active_edge]; |
468 XY text_pos=mytab.mapstorage->arrow_pos[active_edge]; |
467 text_pos+=(XY(10,10)); |
469 text_pos+=(XY(10,10)); |
468 |
470 |
469 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, |
471 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, |
470 text_pos.x, text_pos.y, ""); |
472 text_pos.x, text_pos.y, ""); |
471 edgetextmap[active_edge]->property_fill_color().set_value( |
473 edgetextmap[active_edge]->property_fill_color().set_value( |
849 //repositioning node and its text |
851 //repositioning node and its text |
850 moved_item->move(dx, dy); |
852 moved_item->move(dx, dy); |
851 nodetextmap[moved_node]->move(dx, dy); |
853 nodetextmap[moved_node]->move(dx, dy); |
852 |
854 |
853 // the new coordinates of the centre of the node |
855 // the new coordinates of the centre of the node |
854 double coord_x = dx + (mytab.mapstorage).coords[moved_node].x; |
856 double coord_x = dx + (mytab.mapstorage)->coords[moved_node].x; |
855 double coord_y = dy + (mytab.mapstorage).coords[moved_node].y; |
857 double coord_y = dy + (mytab.mapstorage)->coords[moved_node].y; |
856 |
858 |
857 // write back the new coordinates to the coords map |
859 // write back the new coordinates to the coords map |
858 (mytab.mapstorage).coords.set(moved_node, XY(coord_x, coord_y)); |
860 (mytab.mapstorage)->coords.set(moved_node, XY(coord_x, coord_y)); |
859 |
861 |
860 //all the edges connected to the moved point has to be redrawn |
862 //all the edges connected to the moved point has to be redrawn |
861 for(OutEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei) |
863 for(OutEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) |
862 { |
864 { |
863 XY arrow_pos; |
865 XY arrow_pos; |
864 |
866 |
865 if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei)) |
867 if (mytab.mapstorage->graph.source(ei) == mytab.mapstorage->graph.target(ei)) |
866 { |
868 { |
867 arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy); |
869 arrow_pos = mytab.mapstorage->arrow_pos[ei] + XY(dx, dy); |
868 } |
870 } |
869 else |
871 else |
870 { |
872 { |
871 XY moved_node_1(coord_x - dx, coord_y - dy); |
873 XY moved_node_1(coord_x - dx, coord_y - dy); |
872 XY moved_node_2(coord_x, coord_y); |
874 XY moved_node_2(coord_x, coord_y); |
873 Node target = mytab.mapstorage.graph.target(ei); |
875 Node target = mytab.mapstorage->graph.target(ei); |
874 XY fix_node(mytab.mapstorage.coords[target].x, |
876 XY fix_node(mytab.mapstorage->coords[target].x, |
875 mytab.mapstorage.coords[target].y); |
877 mytab.mapstorage->coords[target].y); |
876 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); |
878 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); |
877 |
879 |
878 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
880 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
879 } |
881 } |
880 |
882 |
881 mytab.mapstorage.arrow_pos.set(ei, arrow_pos); |
883 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); |
882 edgesmap[ei]->draw(); |
884 edgesmap[ei]->draw(); |
883 |
885 |
884 //reposition of edgetext |
886 //reposition of edgetext |
885 XY text_pos=mytab.mapstorage.arrow_pos[ei]; |
887 XY text_pos=mytab.mapstorage->arrow_pos[ei]; |
886 text_pos+=(XY(10,10)); |
888 text_pos+=(XY(10,10)); |
887 edgetextmap[ei]->property_x().set_value(text_pos.x); |
889 edgetextmap[ei]->property_x().set_value(text_pos.x); |
888 edgetextmap[ei]->property_y().set_value(text_pos.y); |
890 edgetextmap[ei]->property_y().set_value(text_pos.y); |
889 } |
891 } |
890 |
892 |
891 for(InEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei) |
893 for(InEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) |
892 { |
894 { |
893 if (mytab.mapstorage.graph.source(ei) != mytab.mapstorage.graph.target(ei)) |
895 if (mytab.mapstorage->graph.source(ei) != mytab.mapstorage->graph.target(ei)) |
894 { |
896 { |
895 XY moved_node_1(coord_x - dx, coord_y - dy); |
897 XY moved_node_1(coord_x - dx, coord_y - dy); |
896 XY moved_node_2(coord_x, coord_y); |
898 XY moved_node_2(coord_x, coord_y); |
897 Node source = mytab.mapstorage.graph.source(ei); |
899 Node source = mytab.mapstorage->graph.source(ei); |
898 XY fix_node(mytab.mapstorage.coords[source].x, |
900 XY fix_node(mytab.mapstorage->coords[source].x, |
899 mytab.mapstorage.coords[source].y); |
901 mytab.mapstorage->coords[source].y); |
900 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); |
902 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); |
901 |
903 |
902 XY arrow_pos; |
904 XY arrow_pos; |
903 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
905 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
904 |
906 |
905 mytab.mapstorage.arrow_pos.set(ei, arrow_pos); |
907 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); |
906 edgesmap[ei]->draw(); |
908 edgesmap[ei]->draw(); |
907 |
909 |
908 //reposition of edgetext |
910 //reposition of edgetext |
909 XY text_pos=mytab.mapstorage.arrow_pos[ei]; |
911 XY text_pos=mytab.mapstorage->arrow_pos[ei]; |
910 text_pos+=(XY(10,10)); |
912 text_pos+=(XY(10,10)); |
911 edgetextmap[ei]->property_x().set_value(text_pos.x); |
913 edgetextmap[ei]->property_x().set_value(text_pos.x); |
912 edgetextmap[ei]->property_y().set_value(text_pos.y); |
914 edgetextmap[ei]->property_y().set_value(text_pos.y); |
913 } |
915 } |
914 } |
916 } |