COIN-OR::LEMON - Graph Library

Changeset 1860:27a9a75b957b in lemon-0.x for gui


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

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

Location:
gui
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • gui/Makefile.am

    r1849 r1860  
    2929        new_map_win.h \
    3030        xymap.h \
     31        gui_reader.h \
     32        gui_reader.cc \
     33        gui_writer.h \
     34        gui_writer.cc \
    3135        icons/guipixbufs.h
    3236
  • gui/all_include.h

    r1731 r1860  
    3838using namespace lemon;
    3939
    40 typedef xy<double> Coordinates;
     40typedef xy<double> XY;
    4141typedef ListGraph Graph;
    42 typedef Graph::NodeMap<Coordinates> CoordinatesMap;
    4342typedef Graph::Node Node;
    4443typedef Graph::Edge Edge;
  • gui/gdc-broken_edge.cc

    r1831 r1860  
    22#include <cmath>
    33
    4 GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false)
     4GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc) : Line(g), edge(_edge), gdc(gc), isbutton(false)
    55{
    6   my_points=new Gnome::Art::Point[3];
    7 
    86  arrow=new Gnome::Canvas::Polygon(g);
    97  *arrow << Gnome::Canvas::Properties::fill_color("red");
    108  arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler));
    119  arrow->lower_to_bottom();
    12   setPoints(p);
     10  draw();
    1311}
    1412
     
    1816}
    1917
    20 void GraphDisplayerCanvas::BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
     18void GraphDisplayerCanvas::BrokenEdge::draw()
    2119{
    22   bool set_arrow=false;
    23   //red arrow losts its position-right button
    24   if(!move)
    25     {
    26       if(p.size()==2)
    27         {
    28           set_arrow=true;
    29           Gnome::Canvas::Points points_with_center;
    30           points_with_center.push_back(my_points[0]=p[0]);
    31           points_with_center.push_back(my_points[1]=Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+0 , (p[0].get_y()+p[1].get_y())/2 )+0 );
    32           points_with_center.push_back(my_points[2]=p[1]);
    33           property_points().set_value(points_with_center);
    34         } 
    35       if(p.size()==3)
    36         {
    37           set_arrow=true;
    38           property_points().set_value(p);
    39           for(int i=0;i<3;i++)
    40             {
    41               my_points[i]=p[i];
    42             }
    43         }
     20  MapStorage& ms = gdc.mytab.mapstorage;
     21
     22  // update the edge
     23  {
     24    Gnome::Canvas::Points points;
     25    Node source = ms.graph.source(edge);
     26    Node target = ms.graph.target(edge);
     27    points.push_back(Gnome::Art::Point(ms.coords[source].x,
     28          ms.coords[source].y));
     29    points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x,
     30          ms.arrow_pos[edge].y));
     31    points.push_back(Gnome::Art::Point(ms.coords[target].x,
     32          ms.coords[target].y));
     33    property_points().set_value(points);
     34  }
     35
     36  // update the arrow
     37  {
     38    //calculating coordinates of the direction indicator arrow
     39    XY target(ms.coords[ms.graph.target(edge)]);
     40    XY center(ms.arrow_pos[edge]);
     41
     42    XY unit_vector_in_dir(target-center);
     43    double length=sqrt( unit_vector_in_dir.normSquare() );
     44
     45    //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
     46    unit_vector_in_dir/=length;
     47    //       std::cout << " = " << unit_vector_in_dir << std::endl;
     48
     49    XY unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
     50    //       std::cout << unit_norm_vector << std::endl;
     51
     52    {     
     53      //       /\       // top
     54      //      /  \      //
     55      //      -  -      // c(enter)l(eft), ccl, ccr, cr
     56      //       ||       //
     57      //       ||       // b(ottom)l, br
    4458    }
    45   else
    46     {
    47       //arrow keeps its position-left button
    4859
    49 //       if(p.size()==2)
    50 //              {
    51 //                Gnome::Canvas::Points points;
    52 //                my_points[0]=p[0];
    53 //                my_points[2]=p[1];
    54 //                for(int i=0;i<3;i++)
    55 //                  {
    56 //                    points.push_back(my_points[i]);
    57 //                  }
    58 //                property_points().set_value(points);
    59 //              }
    60       set_arrow=true;
     60    double size=3;
    6161
    62       //////////////////////////////////////////////////////////////////////////////////////////////////////
    63       /////////// keeps shape-with scalar multiplication - version 2.
    64       //////////////////////////////////////////////////////////////////////////////////////////////////////
     62    XY bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
     63    XY br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
     64    XY ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
     65    XY ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
     66    XY cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
     67    XY cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
     68    XY top(center + unit_vector_in_dir * 3 * size);
    6569
    66       if(p.size()==2)
    67         {
    68           //old vector from one to the other node - a
    69           xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
    70           //new vector from one to the other node - b
    71           xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
     70    //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
    7271
    73           double absa=sqrt(a_v.normSquare());
    74           double absb=sqrt(b_v.normSquare());
     72    Gnome::Canvas::Points arrow_points;
     73    arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
     74    arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
     75    arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
     76    arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
     77    arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
     78    arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
     79    arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
    7580
    76           if((absa!=0)&&(absb!=0))
    77             {
    78               //old vector from one node to the breakpoint - c
    79               xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
    80 
    81               //unit vector with the same direction to a_v
    82               xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
    83 
    84               //normal vector of unit vector with the same direction to a_v
    85               xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
    86 
    87               //unit vector with the same direction to b_v
    88               xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
    89 
    90               //normal vector of unit vector with the same direction to b_v
    91               xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
    92 
    93               //vector c in a_v_u and a_v_u_n co-ordinate system
    94               xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
    95 
    96               //new vector from one node to the breakpoint - d - we have to calculate this one
    97               xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
    98 
    99               my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
    100 
    101               my_points[0]=p[0];
    102               my_points[2]=p[1];
    103          
    104               Gnome::Canvas::Points points;
    105               for(int i=0;i<3;i++)
    106                 {
    107                   points.push_back(my_points[i]);
    108                 }
    109               property_points().set_value(points);
    110             }
    111           else
    112             {
    113               //if distance is 0, segmentation would be occured
    114               //in calculations, because of division by zero
    115               //But we have luck: the edge cannot be seen in
    116               //this case, so no update needed
    117               set_arrow=false;
    118             }
    119         }
    120     }
    121   if(set_arrow)
    122     {
    123       //calculating coordinates of the direction indicator arrow
    124 
    125       xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
    126       xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
    127 
    128       xy<gdouble> unit_vector_in_dir(target-center);
    129       double length=sqrt( unit_vector_in_dir.normSquare() );
    130 
    131       //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
    132       unit_vector_in_dir/=length;
    133       //       std::cout << " = " << unit_vector_in_dir << std::endl;
    134 
    135       xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
    136       //       std::cout << unit_norm_vector << std::endl;
    137 
    138       {     
    139         //       /\       // top
    140         //      /  \      //
    141         //      -  -      // c(enter)l(eft), ccl, ccr, cr
    142         //       ||       //
    143         //       ||       // b(ottom)l, br
    144       }
    145 
    146       double size=3;
    147 
    148       xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
    149       xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
    150       xy<gdouble> ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
    151       xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
    152       xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
    153       xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
    154       xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
    155          
    156       //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
    157 
    158       Gnome::Canvas::Points arrow_points;
    159       arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
    160       arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
    161       arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
    162       arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
    163       arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
    164       arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
    165       arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
    166 
    167       arrow->property_points().set_value(arrow_points);
    168     }
     81    arrow->property_points().set_value(arrow_points);
     82  }
    16983}
    17084
     
    204118          Gnome::Canvas::Points points_new;
    205119
    206           points_new.push_back(my_points[0]);
    207           points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
    208           points_new.push_back(my_points[2]);
     120          gdc.mytab.mapstorage.arrow_pos.set(edge, gdc.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy));
    209121
    210           setPoints(points_new);
    211           gdc.textReposition(xy<double>(my_points[1].get_x(),my_points[1].get_y()));
     122          draw();
     123          gdc.textReposition(gdc.mytab.mapstorage.arrow_pos[edge]);
    212124
    213125          clicked_x=e->motion.x;
     
    220132  return true;
    221133}
    222 
    223 xy<double> GraphDisplayerCanvas::BrokenEdge::getArrowPos()
    224 {
    225   xy<double> ret_val(my_points[1].get_x(),my_points[1].get_y());
    226   return ret_val;
    227 }
  • gui/graph_displayer_canvas-event.cc

    r1849 r1860  
    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,
  • gui/graph_displayer_canvas.cc

    r1849 r1860  
    169169          (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
    170170   
    171     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
     171    edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
    172172    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    173173    edgesmap[i]->property_width_units().set_value(10);   
     
    176176    //initializing edge-text as well, to empty string
    177177
    178     xy<double> text_pos=edgesmap[i]->getArrowPos();
    179     text_pos+=(xy<double>(10,10));
     178    XY text_pos=mytab.mapstorage.arrow_pos[i];
     179    text_pos+=(XY(10,10));
    180180
    181181    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
  • gui/graph_displayer_canvas.h

    r1849 r1860  
    1515class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    1616{
     17  friend class BrokenEdge;
     18
    1719  class BrokenEdge : public Gnome::Canvas::Line
    1820  {
     21    Edge edge;
    1922    GraphDisplayerCanvas & gdc;
    2023    Gnome::Canvas::Polygon * arrow;
    21     Gnome::Art::Point * my_points;
    22 
    2324
    2425    ///Indicates whether the button of mouse is pressed or not
     
    3233    bool edgeFormerEventHandler(GdkEvent*);
    3334  public:
    34     BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
     35    BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
    3536    ~BrokenEdge();
    36     void setPoints(Gnome::Canvas::Points, bool move=false);
    37     xy<double> getArrowPos();
     37    void draw();
    3838  };
    3939  typedef Gnome::Canvas::CanvasAA Parent;
     
    201201  NoteBookTab & mytab;
    202202
     203  XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
    203204};
    204205
  • gui/mapstorage.cc

    r1837 r1860  
    11#include "mapstorage.h"
     2#include "gui_writer.h"
     3#include "gui_reader.h"
    24#include <gtkmm.h>
    35#include <cmath>
     
    57#include <cmath>
    68
    7 MapStorage::MapStorage() : modified(false), file_name("")
     9MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
    810{
    911  nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
     
    1113  nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    1214  coords.setYMap(*nodemap_storage["coordinates_y"]);
     15
     16  edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
     17  arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
     18  edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
     19  arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    1320
    1421  nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
     
    248255      greader.readEdgeMap(*it, *edgemap_storage[*it]);
    249256    }
     257    GuiReader gui_reader(greader, this);
    250258    greader.run();
    251259  } catch (DataFormatError& error) {
     
    284292  }
    285293
     294  if (!arrow_pos_read_ok)
     295  {
     296    arrow_pos_read_ok = false;
     297    for (EdgeIt e(graph); e != INVALID; ++e)
     298    {
     299      arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
     300    }
     301  }
     302
    286303  // fill in the default values for the maps
    287304  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
     
    339356  {
    340357    gwriter.writeNodeMap(it->first, *(it->second));
    341     //std::cout << "wrote " << it->first << " nodemap" << std::endl;
    342358  }
    343359  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    344360      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    345361  {
    346     gwriter.writeEdgeMap(it->first, *(it->second));
    347     //std::cout << "wrote " << it->first << " edgemap" << std::endl;
    348   }
     362    if ((it->first != "arrow_pos_x") &&
     363        (it->first != "arrow_pos_y"))
     364    {
     365      gwriter.writeEdgeMap(it->first, *(it->second));
     366    }
     367  }
     368
     369  GuiWriter gui_writer(gwriter, this);
     370
    349371  gwriter.run();
    350372}
     
    366388      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    367389  {
    368     if (it->first != "id")
     390    if ((it->first != "id") &&
     391        (it->first != "arrow_pos_x") &&
     392        (it->first != "arrow_pos_y"))
    369393    {
    370394      delete it->second;
     
    388412  modified = false;
    389413}
     414
     415void MapStorage::ArrowPosReadOK()
     416{
     417  arrow_pos_read_ok = true;
     418}
  • gui/mapstorage.h

    r1837 r1860  
    2424
    2525  Graph graph;
     26  /// the coordinates of the nodes
    2627  XYMap<Graph::NodeMap<double> > coords;
     28  /// the coordinates of the arrows on the edges
     29  XYMap<Graph::EdgeMap<double> > arrow_pos;
    2730
    2831  bool modified;
     
    5255  // Default values for the maps
    5356  std::map< std::string, double > edgemap_default;
     57
     58  bool arrow_pos_read_ok;
    5459
    5560protected:
     
    128133
    129134  void clear();
     135
     136  void ArrowPosReadOK();
    130137};
    131138
  • gui/xymap.h

    r1606 r1860  
    44#include <lemon/list_graph.h>
    55#include <lemon/xy.h>
    6 
    7 using lemon::ListGraph;
    8 using lemon::xy;
    96
    107template<class M>
     
    1613  public:
    1714    typedef typename M::Key Key;
    18     typedef xy<typename M::Value> Value;
     15    typedef lemon::xy<typename M::Value> Value;
    1916    XYMap() {}
    2017    XYMap(M &_xmap, M &_ymap) : xmap(&_xmap), ymap(&_ymap) {}
Note: See TracChangeset for help on using the changeset viewer.