diff -r 075aaa0a4e6f -r 27a9a75b957b gui/gdc-broken_edge.cc --- a/gui/gdc-broken_edge.cc Wed Dec 14 18:11:03 2005 +0000 +++ b/gui/gdc-broken_edge.cc Sat Dec 17 20:55:41 2005 +0000 @@ -1,15 +1,13 @@ #include "graph_displayer_canvas.h" #include -GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false) +GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc) : Line(g), edge(_edge), gdc(gc), isbutton(false) { - my_points=new Gnome::Art::Point[3]; - arrow=new Gnome::Canvas::Polygon(g); *arrow << Gnome::Canvas::Properties::fill_color("red"); arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler)); arrow->lower_to_bottom(); - setPoints(p); + draw(); } GraphDisplayerCanvas::BrokenEdge::~BrokenEdge() @@ -17,155 +15,71 @@ if(arrow)delete(arrow); } -void GraphDisplayerCanvas::BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move) +void GraphDisplayerCanvas::BrokenEdge::draw() { - bool set_arrow=false; - //red arrow losts its position-right button - if(!move) - { - if(p.size()==2) - { - set_arrow=true; - Gnome::Canvas::Points points_with_center; - points_with_center.push_back(my_points[0]=p[0]); - 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 ); - points_with_center.push_back(my_points[2]=p[1]); - property_points().set_value(points_with_center); - } - if(p.size()==3) - { - set_arrow=true; - property_points().set_value(p); - for(int i=0;i<3;i++) - { - my_points[i]=p[i]; - } - } + MapStorage& ms = gdc.mytab.mapstorage; + + // update the edge + { + Gnome::Canvas::Points points; + Node source = ms.graph.source(edge); + Node target = ms.graph.target(edge); + points.push_back(Gnome::Art::Point(ms.coords[source].x, + ms.coords[source].y)); + points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x, + ms.arrow_pos[edge].y)); + points.push_back(Gnome::Art::Point(ms.coords[target].x, + ms.coords[target].y)); + property_points().set_value(points); + } + + // update the arrow + { + //calculating coordinates of the direction indicator arrow + XY target(ms.coords[ms.graph.target(edge)]); + XY center(ms.arrow_pos[edge]); + + XY unit_vector_in_dir(target-center); + double length=sqrt( unit_vector_in_dir.normSquare() ); + + // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " < c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_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); - - my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); - - my_points[0]=p[0]; - my_points[2]=p[1]; - - Gnome::Canvas::Points points; - for(int i=0;i<3;i++) - { - points.push_back(my_points[i]); - } - property_points().set_value(points); - } - else - { - //if distance is 0, segmentation would be occured - //in calculations, because of division by zero - //But we have luck: the edge cannot be seen in - //this case, so no update needed - set_arrow=false; - } - } - } - if(set_arrow) - { - //calculating coordinates of the direction indicator arrow - - xy target( my_points[2].get_x(), my_points[2].get_y() ); - xy center( my_points[1].get_x(), my_points[1].get_y() ); - - xy unit_vector_in_dir(target-center); - double length=sqrt( unit_vector_in_dir.normSquare() ); - - // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); - } + arrow->property_points().set_value(arrow_points); + } } bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e) @@ -203,12 +117,10 @@ Gnome::Canvas::Points points_new; - points_new.push_back(my_points[0]); - points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy)); - points_new.push_back(my_points[2]); + gdc.mytab.mapstorage.arrow_pos.set(edge, gdc.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy)); - setPoints(points_new); - gdc.textReposition(xy(my_points[1].get_x(),my_points[1].get_y())); + draw(); + gdc.textReposition(gdc.mytab.mapstorage.arrow_pos[edge]); clicked_x=e->motion.x; clicked_y=e->motion.y; @@ -219,9 +131,3 @@ return true; } - -xy GraphDisplayerCanvas::BrokenEdge::getArrowPos() -{ - xy ret_val(my_points[1].get_x(),my_points[1].get_y()); - return ret_val; -}