gui/broken_edge.cc
changeset 1601 70d169a8313a
parent 1524 587a823bcdd0
child 1602 c0d7a9247963
equal deleted inserted replaced
6:f225b041569c 7:fea8a6e69a15
    17 }
    17 }
    18 
    18 
    19 void BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
    19 void BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
    20 {
    20 {
    21   bool set_arrow=false;
    21   bool set_arrow=false;
       
    22   //red arrow losts its position-right button
    22   if(!move)
    23   if(!move)
    23     {
    24     {
    24       if(p.size()==2)
    25       if(p.size()==2)
    25 	{
    26 	{
    26 	  set_arrow=true;
    27 	  set_arrow=true;
    40 	    }
    41 	    }
    41 	}
    42 	}
    42     }
    43     }
    43   else
    44   else
    44     {
    45     {
       
    46       //arrow keeps its position-left button
       
    47 
       
    48       //       if(p.size()==2)
       
    49       // 	{
       
    50       // 	  Gnome::Canvas::Points points;
       
    51       // 	  my_points[0]=p[0];
       
    52       // 	  my_points[2]=p[1];
       
    53       // 	  for(int i=0;i<3;i++)
       
    54       // 	    {
       
    55       // 	      points.push_back(my_points[i]);
       
    56       // 	    }
       
    57       // 	  property_points().set_value(points);
       
    58       // 	}
       
    59 
       
    60       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    61       /////////// kepps shape-with angles
       
    62       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
    63 
       
    64 
       
    65 //       //old vector from one to the other node
       
    66 //       xy<double> o_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
    67 //       //projection of the old vector to positive x axis
       
    68 //       xy<double> o_x_p2p(fabs(o_p2p.x),0);
       
    69 //       //length of p2p vector
       
    70 //       double o_l_p2p=sqrt( o_p2p.normSquare() );
       
    71 //       if(o_p2p.x<0)
       
    72 // 	{
       
    73 // 	  o_l_p2p*=-1;
       
    74 // 	}
       
    75 //       //length of projection of p2p vector
       
    76 //       double o_l_x_p2p=sqrt( o_x_p2p.normSquare() );
       
    77 //       //old angle of p2p vector to the x axis
       
    78 //       double o_a_p2p=acos(o_l_x_p2p/o_l_p2p);
       
    79 //       if(o_p2p.y>0)
       
    80 // 	{
       
    81 // 	  o_a_p2p=2*M_PI-o_a_p2p;
       
    82 // 	}
       
    83 
       
    84 //       //old vector from first node to the breakpoint
       
    85 //       xy<double> o_1b((my_points[1].get_x()-my_points[0].get_x()),(my_points[1].get_y()-my_points[0].get_y()));
       
    86 //       //projection of the old node-breakpoint vector to positive x axis
       
    87 //       xy<double> o_x_1b(fabs(o_1b.x),0);
       
    88 //       //length of 1b vector
       
    89 //       double o_l_1b=sqrt( o_1b.normSquare() );
       
    90 //       if(o_1b.x<0)
       
    91 // 	{
       
    92 // 	  o_l_1b*=-1;
       
    93 // 	}
       
    94 //       //length of projection of 1b vector
       
    95 //       double o_l_x_1b=sqrt( o_x_1b.normSquare() );
       
    96 //       //old angle of 1b vector to the x axis
       
    97 //       double o_a_1b=acos(o_l_x_1b/o_l_1b);
       
    98 //       if(o_1b.y>0)
       
    99 // 	{
       
   100 // 	  o_a_1b=2*M_PI-o_a_1b;
       
   101 // 	}
       
   102 
       
   103 //       if(p.size()==2)
       
   104 //       	{
       
   105 // 	  set_arrow=true;
       
   106 
       
   107 //       	  my_points[0]=p[0];
       
   108 //       	  my_points[2]=p[1];
       
   109 
       
   110 // 	  //new vector from one to the other node
       
   111 // 	  xy<double> n_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
   112 // 	  //projection of the new vector to positive x axis
       
   113 // 	  xy<double> n_x_p2p(fabs(n_p2p.x),0);
       
   114 // 	  //length of p2p vector
       
   115 // 	  double n_l_p2p=sqrt( n_p2p.normSquare() );
       
   116 // 	  if(n_p2p.x<0)
       
   117 // 	    {
       
   118 // 	      n_l_p2p*=-1;
       
   119 // 	    }
       
   120 // 	  //length of projection of p2p vector
       
   121 // 	  double n_l_x_p2p=sqrt( n_x_p2p.normSquare() );
       
   122 // 	  //new angle of p2p vector to the x axis
       
   123 // 	  double n_a_p2p=acos(n_l_x_p2p/n_l_p2p);
       
   124 // 	  if(n_p2p.y>0)
       
   125 // 	    {
       
   126 // 	      n_a_p2p=2*M_PI-n_a_p2p;
       
   127 // 	    }
       
   128 
       
   129 // 	  //new angle of 1b vector to the x axis
       
   130 // 	  double n_a_1b=o_a_1b+n_a_p2p-o_a_p2p;
       
   131 
       
   132 // 	  std::cout << " p2p regi: " << o_a_p2p/M_PI*180 << " uj: " << n_a_p2p/M_PI*180-(int)n_a_p2p/M_PI*180 << std::endl;
       
   133 // 	  std::cout << " 1b regi: " << o_a_1b/M_PI*180 << " uj: " << n_a_1b/M_PI*180-(int)n_a_1b/M_PI*180 << std::endl;
       
   134 
       
   135 // // 	  std::cout << o_p2p << " " << n_p2p << std::endl;
       
   136 
       
   137 // 	  if((n_a_1b>M_PI*3/2)||(n_a_1b<M_PI/2))
       
   138 // 	    {
       
   139 // 	      std::cout << "jobb terfel" << std::endl;
       
   140 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   141 // 	    }
       
   142 // 	  else if((n_a_1b<M_PI*3/2)&&(n_a_1b>M_PI/2))
       
   143 // 	    {
       
   144 // 	      std::cout << "bal terfel" << std::endl;
       
   145 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   146 // 	    }
       
   147 // 	  else
       
   148 // 	    {
       
   149 // 	      std::cout << "y tengely" << std::endl;
       
   150 // 	      double new_y=my_points[1].get_y();
       
   151 // 	      my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,new_y);
       
   152 // 	    }
       
   153 
       
   154 // 	  std::cout << "alap: " << p[0] << " eredeti hossz: " << o_l_1b << " nagy uj: " << n_l_p2p << " nagy regi: " << o_l_p2p << " a*b/c " << o_l_1b*n_l_p2p/o_l_p2p << " eredmeny: " << my_points[1] << std::endl;
       
   155 
       
   156 
       
   157 // // 	  if(o_1b.x*o_1b.y>0)
       
   158 // // 	    {
       
   159 // // 	      if(n_p2p.x>0)
       
   160 // // 		{
       
   161 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   162 // // 		}
       
   163 // // 	      else
       
   164 // // 		{
       
   165 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   166 // // 		}
       
   167 // // 	    }
       
   168 // // 	  else if(o_1b.x*o_1b.y<0)
       
   169 // // 	    {
       
   170 // // 	      if(n_p2p.x>0)
       
   171 // // 		{
       
   172 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()+cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()-sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   173 // // 		}
       
   174 // // 	      else
       
   175 // // 		{
       
   176 // // 		  my_points[1]=Gnome::Art::Point(p[0].get_x()-cos(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p,p[0].get_y()+sin(n_a_1b)*o_l_1b*n_l_p2p/o_l_p2p);
       
   177 // // 		}
       
   178 // // 	    }
       
   179 // // 	  else
       
   180 // // 	    {
       
   181 // // 	    }
       
   182 
       
   183       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   184       /////////// kepps shape-with scalar multiplication
       
   185       //////////////////////////////////////////////////////////////////////////////////////////////////////
       
   186 
    45       if(p.size()==2)
   187       if(p.size()==2)
    46 	{
   188       	{
       
   189 	  //old vector from one to the other node - a
       
   190 	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
       
   191 	  //new vector from one to the other node - b
       
   192 	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
       
   193 
       
   194 	  //old vector from one node to the breakpoint - c
       
   195 	  xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
       
   196 
       
   197 	  //new vector from one node to the breakpoint - d - we have to calculate this one
       
   198 	  xy<double> d_v;
       
   199 
       
   200 	  //scalar product of a and b (old and new vector from first point to the other)
       
   201 	  double sab=a_v*b_v;
       
   202 	  //scalar product of c and d (old and new vector from first point to breakpoint)
       
   203 	  double scd=sab*c_v.normSquare()/a_v.normSquare();
       
   204 
       
   205 	  std::cout<<" a " << a_v<<" b " <<b_v<<" c " <<c_v<<" sab " <<sab<<" scd "<<scd<<std::endl;
       
   206 
       
   207 	  double a=c_v.normSquare();
       
   208 	  double b=2*scd*c_v.y;
       
   209 	  double c=scd*scd-b_v.normSquare()/a_v.normSquare()*c_v.normSquare()*c_v.x*c_v.x;
       
   210 
       
   211 	  std::cout<<" a " << a<<" b " <<b<<" c " <<c<<std::endl;
       
   212 
       
   213 	  d_v.y=(-b-sqrt(b*b-4*a*c))/2/a;
       
   214 
       
   215 	  if(c_v.x!=0)
       
   216 	    {
       
   217 	      d_v.x=(scd-c_v.y*d_v.y)/c_v.x;
       
   218 	    }
       
   219 	  else
       
   220 	    {
       
   221 	      d_v.x=my_points[1].get_x();
       
   222 	    }
       
   223 
       
   224 	  std::cout<<" d " << d_v<<std::endl;
       
   225 
       
   226 	  my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
       
   227 
    47 	  Gnome::Canvas::Points points;
   228 	  Gnome::Canvas::Points points;
    48 	  my_points[0]=p[0];
       
    49 	  my_points[2]=p[1];
       
    50 	  for(int i=0;i<3;i++)
   229 	  for(int i=0;i<3;i++)
    51 	    {
   230 	    {
    52 	      points.push_back(my_points[i]);
   231 	      points.push_back(my_points[i]);
    53 	    }
   232 	    }
    54 	  property_points().set_value(points);
   233 	  property_points().set_value(points);
    55 	}
   234 	}
    56     }
   235     }
    57 
       
    58   if(set_arrow)
   236   if(set_arrow)
    59     {
   237     {
    60       //calculating coordinates of the direction indicator arrow
   238       //calculating coordinates of the direction indicator arrow
    61 
   239 
    62       xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
   240       xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );