Little red arrows appear in breakpoints of edges.
authorhegyi
Thu, 16 Jun 2005 18:08:04 +0000
changeset 14999316dcc0a355
parent 1498 352b1ee13bc0
child 1500 a222eb109e52
Little red arrows appear in breakpoints of edges.
gui/broken_edge.cc
gui/broken_edge.h
gui/graph_displayer_canvas.cc
gui/graph_displayer_canvas.h
     1.1 --- a/gui/broken_edge.cc	Wed Jun 15 13:05:32 2005 +0000
     1.2 +++ b/gui/broken_edge.cc	Thu Jun 16 18:08:04 2005 +0000
     1.3 @@ -1,14 +1,131 @@
     1.4  #include <broken_edge.h>
     1.5 +#include <lemon/xy.h>
     1.6 +#include <math.h>
     1.7  
     1.8 -BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g)
     1.9 +BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g), isbutton(false)
    1.10  {
    1.11 +  my_points=new Gnome::Art::Point[3];
    1.12 +
    1.13 +  arrow=new Gnome::Canvas::Polygon(g);
    1.14 +  *arrow << Gnome::Canvas::Properties::fill_color("red");
    1.15 +  arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edge_former_event_handler));
    1.16 +  set_points(p);
    1.17 +}
    1.18 +
    1.19 +BrokenEdge::~BrokenEdge()
    1.20 +{
    1.21 +  if(arrow)delete(arrow);
    1.22 +}
    1.23 +
    1.24 +void BrokenEdge::set_points(Gnome::Canvas::Points p)
    1.25 +{
    1.26 +  bool set_arrow=false;
    1.27    if(p.size()==2)
    1.28      {
    1.29 +      set_arrow=true;
    1.30        Gnome::Canvas::Points points_with_center;
    1.31 -      points_with_center.push_back(p[0]);
    1.32 -      points_with_center.push_back(Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+30 , (p[0].get_y()+p[1].get_y())/2 )+30 );
    1.33 -      points_with_center.push_back(p[1]);
    1.34 -      
    1.35 +      points_with_center.push_back(my_points[0]=p[0]);
    1.36 +      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 );
    1.37 +      points_with_center.push_back(my_points[2]=p[1]);
    1.38        property_points().set_value(points_with_center);
    1.39 +    }  
    1.40 +  if(p.size()==3)
    1.41 +    {
    1.42 +      set_arrow=true;
    1.43 +      property_points().set_value(p);
    1.44 +      for(int i=0;i<3;i++)
    1.45 +	{
    1.46 +	  my_points[i]=p[i];
    1.47 +	}
    1.48 +    }
    1.49 +
    1.50 +  if(set_arrow)
    1.51 +    {
    1.52 +      //calculating coordinates of the direction indicator arrow
    1.53 +
    1.54 +      xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
    1.55 +      xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
    1.56 +
    1.57 +      xy<gdouble> unit_vector_in_dir(target-center);
    1.58 +      //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
    1.59 +      unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
    1.60 +      //       std::cout << " = " << unit_vector_in_dir << std::endl;
    1.61 +
    1.62 +      xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
    1.63 +      //       std::cout << unit_norm_vector << std::endl;
    1.64 +
    1.65 +      {      
    1.66 +	//       /\             top
    1.67 +	//      /  \
    1.68 +	//      -  -      c(enter)l(eft), ccl, ccr, cr
    1.69 +	//       ||
    1.70 +	//       ||       b(ottom)l, br
    1.71 +      }
    1.72 +
    1.73 +      double size=3;
    1.74 +
    1.75 +      xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
    1.76 +      xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
    1.77 +      xy<gdouble> ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
    1.78 +      xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
    1.79 +      xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
    1.80 +      xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
    1.81 +      xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
    1.82 +	 
    1.83 +      //       std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
    1.84 +
    1.85 +      Gnome::Canvas::Points arrow_points;
    1.86 +      arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
    1.87 +      arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
    1.88 +      arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
    1.89 +      arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
    1.90 +      arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
    1.91 +      arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
    1.92 +      arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
    1.93 +
    1.94 +      arrow->property_points().set_value(arrow_points);
    1.95      }
    1.96  }
    1.97 +
    1.98 +bool BrokenEdge::edge_former_event_handler(GdkEvent* e)
    1.99 +{
   1.100 +  switch(e->type)
   1.101 +    {
   1.102 +    case GDK_BUTTON_PRESS:
   1.103 +      //we mark the location of the event to be able to calculate parameters of dragging
   1.104 +      clicked_x=e->button.x;
   1.105 +      clicked_y=e->button.y;
   1.106 +      isbutton=true;
   1.107 +      break;
   1.108 +    case GDK_BUTTON_RELEASE:
   1.109 +      isbutton=false;
   1.110 +      break;
   1.111 +    case GDK_MOTION_NOTIFY:
   1.112 +      //we only have to do sg. if the mouse button is pressed
   1.113 +      if(isbutton)
   1.114 +	{
   1.115 +	  //new coordinates will be the old values,
   1.116 +	  //because the item will be moved to the
   1.117 +	  //new coordinate therefore the new movement
   1.118 +	  //has to be calculated from here
   1.119 +
   1.120 +	  double dx=e->motion.x-clicked_x;
   1.121 +	  double dy=e->motion.y-clicked_y;
   1.122 +
   1.123 +	  Gnome::Canvas::Points points_new;
   1.124 +
   1.125 +	  points_new.push_back(my_points[0]);
   1.126 +	  points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
   1.127 +	  points_new.push_back(my_points[2]);
   1.128 +
   1.129 +	  set_points(points_new);
   1.130 +
   1.131 +	  clicked_x=e->motion.x;
   1.132 +	  clicked_y=e->motion.y;
   1.133 +
   1.134 +	}
   1.135 +    default: break;
   1.136 +    }
   1.137 +
   1.138 +  return true;
   1.139 +}
     2.1 --- a/gui/broken_edge.h	Wed Jun 15 13:05:32 2005 +0000
     2.2 +++ b/gui/broken_edge.h	Thu Jun 16 18:08:04 2005 +0000
     2.3 @@ -9,8 +9,22 @@
     2.4  
     2.5  class BrokenEdge : public Gnome::Canvas::Line
     2.6  {
     2.7 +  Gnome::Canvas::Polygon * arrow;
     2.8 +  Gnome::Art::Point * my_points;
     2.9 +
    2.10 +  ///Indicates whether the button of mouse is pressed or not
    2.11 +  bool isbutton;
    2.12 +
    2.13 +  ///At this location was the mousebutton pressed.
    2.14 +  ///It helps to calculate the distance of dragging.
    2.15 +  double clicked_x, clicked_y;
    2.16 +
    2.17 +  ///event handler for forming edges
    2.18 +  bool edge_former_event_handler(GdkEvent*);
    2.19   public:
    2.20    BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points);
    2.21 +  ~BrokenEdge();
    2.22 +  void set_points(Gnome::Canvas::Points);
    2.23  };
    2.24  
    2.25  
     3.1 --- a/gui/graph_displayer_canvas.cc	Wed Jun 15 13:05:32 2005 +0000
     3.2 +++ b/gui/graph_displayer_canvas.cc	Thu Jun 16 18:08:04 2005 +0000
     3.3 @@ -23,7 +23,6 @@
     3.4      coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
     3.5      coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
     3.6      
     3.7 -    //edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
     3.8      edgesmap[i]=new BrokenEdge(displayed_graph, coos);
     3.9      *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    3.10      edgesmap[i]->property_width_pixels().set_value(10);    
    3.11 @@ -392,7 +391,7 @@
    3.12              nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
    3.13              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    3.14  
    3.15 -            edgesmap[e]->property_points().set_value(coos);
    3.16 +            edgesmap[e]->set_points(coos);
    3.17  
    3.18  	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
    3.19  
    3.20 @@ -412,7 +411,7 @@
    3.21              nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
    3.22              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    3.23  
    3.24 -            edgesmap[e]->property_points().set_value(coos);
    3.25 +            edgesmap[e]->set_points(coos);
    3.26  
    3.27  	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
    3.28  
    3.29 @@ -543,7 +542,7 @@
    3.30  		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    3.31  
    3.32  		  //drawing new edge
    3.33 -		  edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);
    3.34 +		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos);
    3.35  		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
    3.36  		  edgesmap[active_edge]->property_width_pixels().set_value(10);
    3.37  
     4.1 --- a/gui/graph_displayer_canvas.h	Wed Jun 15 13:05:32 2005 +0000
     4.2 +++ b/gui/graph_displayer_canvas.h	Thu Jun 16 18:08:04 2005 +0000
     4.3 @@ -5,6 +5,7 @@
     4.4  
     4.5  #include <all_include.h>
     4.6  #include <mapstorage.h>
     4.7 +#include <broken_edge.h>
     4.8  #include <libgnomecanvasmm.h>
     4.9  #include <libgnomecanvasmm/polygon.h>
    4.10  
    4.11 @@ -83,7 +84,7 @@
    4.12    Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
    4.13  
    4.14    ///Map of edges of graph
    4.15 -  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
    4.16 +  Graph::EdgeMap<BrokenEdge *> edgesmap;
    4.17  
    4.18    ///Map of texts to write on edges
    4.19    Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
    4.20 @@ -110,6 +111,7 @@
    4.21    Graph::EdgeIt active_edge;
    4.22  
    4.23    static const int zoom_step = 5;
    4.24 +
    4.25  };
    4.26  
    4.27  #endif //GRAPH_DISPLAYER_CANVAS_H