COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
09/18/06 18:02:20 (18 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@2949
Message:

When moving nodes with midbutton little red arrows keep their position.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r147 r148  
    102102            }
    103103        }
    104       switch(e->button.button)
    105         {
    106         case 3:     
    107           isbutton=3;
    108           break;
    109         default:
    110           isbutton=1;
    111           break;
    112         }
     104      isbutton=e->button.button;
    113105      break;
    114106    case GDK_BUTTON_RELEASE:
     
    192184
    193185            XY arrow_pos;
    194             if(isbutton==3)
    195               arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    196             else
    197               arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
     186            arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    198187
    199188            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
     
    217206
    218207            XY arrow_pos;
    219             if(isbutton==3)
    220               arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    221             else
    222               arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
     208            arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    223209
    224210            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
     
    238224}
    239225
    240 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move)
    241 {
    242   if(!move)
    243   {
    244     return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
    245   }
    246   else
    247   {
    248     //////////////////////////////////////////////////////////////////////////////////////////////////////
    249     /////////// keeps shape-with scalar multiplication - version 2.
    250     //////////////////////////////////////////////////////////////////////////////////////////////////////
    251 
    252     //old vector from one to the other node - a
    253     xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
    254     //new vector from one to the other node - b
    255     xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
    256 
    257     double absa=sqrt(a_v.normSquare());
    258     double absb=sqrt(b_v.normSquare());
    259 
    260     if ((absa == 0.0) || (absb == 0.0))
     226XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
     227{
     228  switch(move_code)
    261229    {
     230    case 1:
     231      return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
     232      break;
     233    case 2:
    262234      return old_arrow_pos;
     235      break;
     236    case 3:
     237      {
     238        //////////////////////////////////////////////////////////////////////////////////////////////////////
     239        /////////// keeps shape-with scalar multiplication - version 2.
     240        //////////////////////////////////////////////////////////////////////////////////////////////////////
     241
     242        //old vector from one to the other node - a
     243        xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
     244        //new vector from one to the other node - b
     245        xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
     246
     247        double absa=sqrt(a_v.normSquare());
     248        double absb=sqrt(b_v.normSquare());
     249
     250        if ((absa == 0.0) || (absb == 0.0))
     251          {
     252            return old_arrow_pos;
     253          }
     254        else
     255          {
     256            //old vector from one node to the breakpoint - c
     257            xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
     258
     259            //unit vector with the same direction to a_v
     260            xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
     261
     262            //normal vector of unit vector with the same direction to a_v
     263            xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
     264
     265            //unit vector with the same direction to b_v
     266            xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
     267
     268            //normal vector of unit vector with the same direction to b_v
     269            xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
     270
     271            //vector c in a_v_u and a_v_u_n co-ordinate system
     272            xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
     273
     274            //new vector from one node to the breakpoint - d - we have to calculate this one
     275            xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
     276
     277            return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
     278          }
     279        break;
     280      }
     281    default:
     282      break;
    263283    }
    264     else
    265     {
    266       //old vector from one node to the breakpoint - c
    267       xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
    268 
    269       //unit vector with the same direction to a_v
    270       xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
    271 
    272       //normal vector of unit vector with the same direction to a_v
    273       xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
    274 
    275       //unit vector with the same direction to b_v
    276       xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
    277 
    278       //normal vector of unit vector with the same direction to b_v
    279       xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
    280 
    281       //vector c in a_v_u and a_v_u_n co-ordinate system
    282       xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
    283 
    284       //new vector from one node to the breakpoint - d - we have to calculate this one
    285       xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
    286 
    287       return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
    288     }
    289   }
    290 }
     284}
     285
    291286
    292287bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
Note: See TracChangeset for help on using the changeset viewer.