- runningTimeTest(): a tool to measure running times more precisely.
- TimeStamp now uses double to count cpu-times
- 'get's removed from the query functions of Times and TimeStamp
1 #include "broken_edge.h"
4 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false)
6 my_points=new Gnome::Art::Point[3];
8 arrow=new Gnome::Canvas::Polygon(g);
9 *arrow << Gnome::Canvas::Properties::fill_color("red");
10 arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler));
11 arrow->lower_to_bottom();
15 BrokenEdge::~BrokenEdge()
17 if(arrow)delete(arrow);
20 void BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
23 //red arrow losts its position-right button
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);
38 property_points().set_value(p);
47 //arrow keeps its position-left button
51 Gnome::Canvas::Points points;
56 points.push_back(my_points[i]);
58 property_points().set_value(points);
62 //////////////////////////////////////////////////////////////////////////////////////////////////////
63 /////////// kepps shape-with angles
64 //////////////////////////////////////////////////////////////////////////////////////////////////////
67 // //old vector from one to the other node
68 // xy<double> o_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
69 // //projection of the old vector to positive x axis
70 // xy<double> o_x_p2p(fabs(o_p2p.x),0);
71 // //length of p2p vector
72 // double o_l_p2p=sqrt( o_p2p.normSquare() );
77 // //length of projection of p2p vector
78 // double o_l_x_p2p=sqrt( o_x_p2p.normSquare() );
79 // //old angle of p2p vector to the x axis
80 // double o_a_p2p=acos(o_l_x_p2p/o_l_p2p);
83 // o_a_p2p=2*M_PI-o_a_p2p;
86 // //old vector from first node to the breakpoint
87 // xy<double> o_1b((my_points[1].get_x()-my_points[0].get_x()),(my_points[1].get_y()-my_points[0].get_y()));
88 // //projection of the old node-breakpoint vector to positive x axis
89 // xy<double> o_x_1b(fabs(o_1b.x),0);
90 // //length of 1b vector
91 // double o_l_1b=sqrt( o_1b.normSquare() );
96 // //length of projection of 1b vector
97 // double o_l_x_1b=sqrt( o_x_1b.normSquare() );
98 // //old angle of 1b vector to the x axis
99 // double o_a_1b=acos(o_l_x_1b/o_l_1b);
102 // o_a_1b=2*M_PI-o_a_1b;
109 // my_points[0]=p[0];
110 // my_points[2]=p[1];
112 // //new vector from one to the other node
113 // xy<double> n_p2p(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
114 // //projection of the new vector to positive x axis
115 // xy<double> n_x_p2p(fabs(n_p2p.x),0);
116 // //length of p2p vector
117 // double n_l_p2p=sqrt( n_p2p.normSquare() );
122 // //length of projection of p2p vector
123 // double n_l_x_p2p=sqrt( n_x_p2p.normSquare() );
124 // //new angle of p2p vector to the x axis
125 // double n_a_p2p=acos(n_l_x_p2p/n_l_p2p);
128 // n_a_p2p=2*M_PI-n_a_p2p;
131 // //new angle of 1b vector to the x axis
132 // double n_a_1b=o_a_1b+n_a_p2p-o_a_p2p;
134 // 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;
135 // 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;
137 // // std::cout << o_p2p << " " << n_p2p << std::endl;
139 // if((n_a_1b>M_PI*3/2)||(n_a_1b<M_PI/2))
141 // std::cout << "jobb terfel" << std::endl;
142 // 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);
144 // else if((n_a_1b<M_PI*3/2)&&(n_a_1b>M_PI/2))
146 // std::cout << "bal terfel" << std::endl;
147 // 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);
151 // std::cout << "y tengely" << std::endl;
152 // double new_y=my_points[1].get_y();
153 // 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);
156 // 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;
159 // // if(o_1b.x*o_1b.y>0)
163 // // 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);
167 // // 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);
170 // // else if(o_1b.x*o_1b.y<0)
174 // // 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);
178 // // 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);
185 //////////////////////////////////////////////////////////////////////////////////////////////////////
186 /////////// kepps shape-with scalar multiplication
187 //////////////////////////////////////////////////////////////////////////////////////////////////////
191 // //old vector from one to the other node - a
192 // xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
193 // //new vector from one to the other node - b
194 // xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
196 // //old vector from one node to the breakpoint - c
197 // xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
199 // //new vector from one node to the breakpoint - d - we have to calculate this one
202 // //scalar product of a and b (old and new vector from first point to the other)
203 // double sab=a_v*b_v;
204 // //scalar product of c and d (old and new vector from first point to breakpoint)
205 // double scd=sab*c_v.normSquare()/a_v.normSquare();
207 // std::cout<<" a " << a_v<<" b " <<b_v<<" c " <<c_v<<" sab " <<sab<<" scd "<<scd<<std::endl;
209 // double a=c_v.normSquare();
210 // double b=2*scd*c_v.y;
211 // double c=scd*scd-b_v.normSquare()/a_v.normSquare()*c_v.normSquare()*c_v.x*c_v.x;
213 // std::cout<<" a " << a<<" b " <<b<<" c " <<c<<std::endl;
215 // d_v.y=(-b-sqrt(b*b-4*a*c))/2/a;
219 // d_v.x=(scd-c_v.y*d_v.y)/c_v.x;
223 // d_v.x=my_points[1].get_x();
226 // std::cout<<" d " << d_v<<std::endl;
228 // my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
230 // Gnome::Canvas::Points points;
231 // for(int i=0;i<3;i++)
233 // points.push_back(my_points[i]);
235 // property_points().set_value(points);
240 //calculating coordinates of the direction indicator arrow
242 xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
243 xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
245 xy<gdouble> unit_vector_in_dir(target-center);
246 // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <<unit_vector_in_dir.normSquare() ;
247 unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
248 // std::cout << " = " << unit_vector_in_dir << std::endl;
250 xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
251 // std::cout << unit_norm_vector << std::endl;
256 // - - // c(enter)l(eft), ccl, ccr, cr
258 // || // b(ottom)l, br
263 xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
264 xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
265 xy<gdouble> ccl(center + unit_vector_in_dir * size + unit_norm_vector * size );
266 xy<gdouble> ccr(center + unit_vector_in_dir * size - unit_norm_vector * size );
267 xy<gdouble> cl (center + unit_vector_in_dir * size + unit_norm_vector * 2 * size );
268 xy<gdouble> cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
269 xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
271 // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
273 Gnome::Canvas::Points arrow_points;
274 arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );
275 arrow_points.push_back(Gnome::Art::Point( br.x , br.y ) );
276 arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
277 arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y ) );
278 arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
279 arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y ) );
280 arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
282 arrow->property_points().set_value(arrow_points);
286 bool BrokenEdge::edgeFormerEventHandler(GdkEvent* e)
290 case GDK_BUTTON_PRESS:
291 //we mark the location of the event to be able to calculate parameters of dragging
292 if(gdc.getActualTool()!=CREATE_NODE)
294 gdc.toggleEdgeActivity(this, true);
295 clicked_x=e->button.x;
296 clicked_y=e->button.y;
300 case GDK_BUTTON_RELEASE:
301 if(gdc.getActualTool()!=CREATE_NODE)
303 gdc.toggleEdgeActivity(this, false);
307 case GDK_MOTION_NOTIFY:
308 //we only have to do sg. if the mouse button is pressed
311 //new coordinates will be the old values,
312 //because the item will be moved to the
313 //new coordinate therefore the new movement
314 //has to be calculated from here
316 double dx=e->motion.x-clicked_x;
317 double dy=e->motion.y-clicked_y;
319 Gnome::Canvas::Points points_new;
321 points_new.push_back(my_points[0]);
322 points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
323 points_new.push_back(my_points[2]);
325 setPoints(points_new);
326 gdc.textReposition(xy<double>(my_points[1].get_x(),my_points[1].get_y()));
328 clicked_x=e->motion.x;
329 clicked_y=e->motion.y;
338 xy<double> BrokenEdge::getArrowPos()
340 xy<double> ret_val(my_points[1].get_x(),my_points[1].get_y());