# HG changeset patch # User hegyi # Date 1158595340 0 # Node ID 5adf296623541c449c2463483a30255e3f831839 # Parent 10ef59f6633cfb28b6e71b4484df19513d84309c When moving nodes with midbutton little red arrows keep their position. diff -r 10ef59f6633c -r 5adf29662354 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Wed Sep 13 09:16:29 2006 +0000 +++ b/graph_displayer_canvas-event.cc Mon Sep 18 16:02:20 2006 +0000 @@ -101,15 +101,7 @@ active_node=i; } } - switch(e->button.button) - { - case 3: - isbutton=3; - break; - default: - isbutton=1; - break; - } + isbutton=e->button.button; break; case GDK_BUTTON_RELEASE: if (coord_text) @@ -191,10 +183,7 @@ XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); XY arrow_pos; - if(isbutton==3) - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); - else - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); + arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); mytab.mapstorage.arrow_pos.set(ei, arrow_pos); edgesmap[ei]->draw(); @@ -216,10 +205,7 @@ XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); XY arrow_pos; - if(isbutton==3) - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); - else - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); + arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); mytab.mapstorage.arrow_pos.set(ei, arrow_pos); edgesmap[ei]->draw(); @@ -237,57 +223,66 @@ return false; } -XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move) +XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code) { - if(!move) - { - return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); - } - else - { - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////// keeps shape-with scalar multiplication - version 2. - ////////////////////////////////////////////////////////////////////////////////////////////////////// + switch(move_code) + { + case 1: + return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); + break; + case 2: + return old_arrow_pos; + break; + case 3: + { + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////// keeps shape-with scalar multiplication - version 2. + ////////////////////////////////////////////////////////////////////////////////////////////////////// - //old vector from one to the other node - a - xy a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); - //new vector from one to the other node - b - xy b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); + //old vector from one to the other node - a + xy a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); + //new vector from one to the other node - b + xy b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); - double absa=sqrt(a_v.normSquare()); - double absb=sqrt(b_v.normSquare()); + double absa=sqrt(a_v.normSquare()); + double absb=sqrt(b_v.normSquare()); - if ((absa == 0.0) || (absb == 0.0)) - { - return old_arrow_pos; + if ((absa == 0.0) || (absb == 0.0)) + { + return old_arrow_pos; + } + else + { + //old vector from one node to the breakpoint - c + xy c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); + + //unit vector with the same direction to a_v + xy a_v_u(a_v.x/absa,a_v.y/absa); + + //normal vector of unit vector with the same direction to a_v + xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); + + //unit vector with the same direction to b_v + xy b_v_u(b_v.x/absb,b_v.y/absb); + + //normal vector of unit vector with the same direction to b_v + xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); + + //vector c in a_v_u and a_v_u_n co-ordinate system + xy c_a(c_v*a_v_u,c_v*a_v_u_n); + + //new vector from one node to the breakpoint - d - we have to calculate this one + xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); + + return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); + } + break; + } + default: + break; } - else - { - //old vector from one node to the breakpoint - c - xy c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); +} - //unit vector with the same direction to a_v - xy a_v_u(a_v.x/absa,a_v.y/absa); - - //normal vector of unit vector with the same direction to a_v - xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); - - //unit vector with the same direction to b_v - xy b_v_u(b_v.x/absb,b_v.y/absb); - - //normal vector of unit vector with the same direction to b_v - xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); - - //vector c in a_v_u and a_v_u_n co-ordinate system - xy c_a(c_v*a_v_u,c_v*a_v_u_n); - - //new vector from one node to the breakpoint - d - we have to calculate this one - xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); - - return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); - } - } -} bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) { diff -r 10ef59f6633c -r 5adf29662354 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Wed Sep 13 09:16:29 2006 +0000 +++ b/graph_displayer_canvas.h Mon Sep 18 16:02:20 2006 +0000 @@ -378,7 +378,7 @@ ///reference to the container, in which the canvas is NoteBookTab & mytab; - XY calcArrowPos(XY, XY, XY, XY, bool); + XY calcArrowPos(XY, XY, XY, XY, int); }; #endif //GRAPH_DISPLAYER_CANVAS_H