COIN-OR::LEMON - Graph Library

Changeset 98:f60f89147531 in glemon-0.x for graph_displayer_canvas-event.cc


Ignore:
Timestamp:
12/17/05 21:55:41 (18 years ago)
Author:
Akos Ladanyi
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2432
Message:

Save and load the coordinates of the arrows on the edges.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r96 r98  
    148148        double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y);
    149149
     150        // write back the new coordinates to the coords map
     151        (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
     152
    150153        clicked_x=new_x;
    151154        clicked_y=new_y;
    152 
    153         // write back the new coordinates to the coords map
    154         (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
    155155
    156156        // reposition the coordinates text
     
    184184        for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
    185185        {
    186             Gnome::Canvas::Points coos;
    187             double x1, x2, y1, y2;
    188 
    189             nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    190             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    191 
    192             nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    193             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    194 
     186            XY moved_node_1(coord_x - dx, coord_y - dy);
     187            XY moved_node_2(coord_x, coord_y);
     188            Node target = mytab.mapstorage.graph.target(ei);
     189            XY fix_node(mytab.mapstorage.coords[target].x,
     190                        mytab.mapstorage.coords[target].y);
     191            XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
     192
     193            XY arrow_pos;
    195194            if(isbutton==3)
    196               {
    197                 edgesmap[ei]->setPoints(coos);
    198               }
     195              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    199196            else
    200               {
    201                 edgesmap[ei]->setPoints(coos,true);
    202               }
     197              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
     198
     199            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
     200            edgesmap[ei]->draw();
    203201
    204202            //reposition of edgetext
    205             xy<double> text_pos=edgesmap[ei]->getArrowPos();
    206             text_pos+=(xy<double>(10,10));
     203            XY text_pos=mytab.mapstorage.arrow_pos[ei];
     204            text_pos+=(XY(10,10));
    207205            edgetextmap[ei]->property_x().set_value(text_pos.x);
    208206            edgetextmap[ei]->property_y().set_value(text_pos.y);
     
    211209        for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
    212210        {
    213             Gnome::Canvas::Points coos;
    214             double x1, x2, y1, y2;
    215 
    216             nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    217             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    218 
    219             nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    220             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    221 
     211            XY moved_node_1(coord_x - dx, coord_y - dy);
     212            XY moved_node_2(coord_x, coord_y);
     213            Node source = mytab.mapstorage.graph.source(ei);
     214            XY fix_node(mytab.mapstorage.coords[source].x,
     215                        mytab.mapstorage.coords[source].y);
     216            XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
     217
     218            XY arrow_pos;
    222219            if(isbutton==3)
    223               {
    224                 edgesmap[ei]->setPoints(coos);
    225               }
     220              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    226221            else
    227               {
    228                 edgesmap[ei]->setPoints(coos,true);
    229               }
    230 
    231             xy<double> text_pos=edgesmap[ei]->getArrowPos();
    232             text_pos+=(xy<double>(10,10));
     222              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
     223
     224            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
     225            edgesmap[ei]->draw();
     226
     227            //reposition of edgetext
     228            XY text_pos=mytab.mapstorage.arrow_pos[ei];
     229            text_pos+=(XY(10,10));
    233230            edgetextmap[ei]->property_x().set_value(text_pos.x);
    234231            edgetextmap[ei]->property_y().set_value(text_pos.y);
     
    239236
    240237  return false;
     238}
     239
     240XY 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))
     261    {
     262      return old_arrow_pos;
     263    }
     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  }
    241290}
    242291
     
    406455
    407456              //drawing new edge
    408               edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
     457              edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
    409458                  *this);
    410459              *(edgesmap[active_edge]) <<
     
    415464
    416465              //initializing edge-text as well, to empty string
    417               xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
    418               text_pos+=(xy<double>(10,10));
     466              XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
     467              text_pos+=(XY(10,10));
    419468
    420469              edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
Note: See TracChangeset for help on using the changeset viewer.