132 // the new coordinates of the centre of the node |
132 // the new coordinates of the centre of the node |
133 double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x); |
133 double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x); |
134 double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y); |
134 double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y); |
135 |
135 |
136 // write back the new coordinates to the coords map |
136 // write back the new coordinates to the coords map |
137 (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y)); |
137 (mytab.mapstorage).coords.set(active_node, XY(coord_x, coord_y)); |
138 |
138 |
139 clicked_x=new_x; |
139 clicked_x=new_x; |
140 clicked_y=new_y; |
140 clicked_y=new_y; |
141 |
141 |
142 // reposition the coordinates text |
142 // reposition the coordinates text |
232 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
232 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
233 /////////// keeps shape-with scalar multiplication - version 2. |
233 /////////// keeps shape-with scalar multiplication - version 2. |
234 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
234 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
235 |
235 |
236 //old vector from one to the other node - a |
236 //old vector from one to the other node - a |
237 xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); |
237 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); |
238 //new vector from one to the other node - b |
238 //new vector from one to the other node - b |
239 xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); |
239 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); |
240 |
240 |
241 double absa=sqrt(a_v.normSquare()); |
241 double absa=sqrt(a_v.normSquare()); |
242 double absb=sqrt(b_v.normSquare()); |
242 double absb=sqrt(b_v.normSquare()); |
243 |
243 |
244 if ((absa == 0.0) || (absb == 0.0)) |
244 if ((absa == 0.0) || (absb == 0.0)) |
246 return old_arrow_pos; |
246 return old_arrow_pos; |
247 } |
247 } |
248 else |
248 else |
249 { |
249 { |
250 //old vector from one node to the breakpoint - c |
250 //old vector from one node to the breakpoint - c |
251 xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); |
251 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); |
252 |
252 |
253 //unit vector with the same direction to a_v |
253 //unit vector with the same direction to a_v |
254 xy<double> a_v_u(a_v.x/absa,a_v.y/absa); |
254 XY a_v_u(a_v.x/absa,a_v.y/absa); |
255 |
255 |
256 //normal vector of unit vector with the same direction to a_v |
256 //normal vector of unit vector with the same direction to a_v |
257 xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x); |
257 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x); |
258 |
258 |
259 //unit vector with the same direction to b_v |
259 //unit vector with the same direction to b_v |
260 xy<double> b_v_u(b_v.x/absb,b_v.y/absb); |
260 XY b_v_u(b_v.x/absb,b_v.y/absb); |
261 |
261 |
262 //normal vector of unit vector with the same direction to b_v |
262 //normal vector of unit vector with the same direction to b_v |
263 xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x); |
263 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x); |
264 |
264 |
265 //vector c in a_v_u and a_v_u_n co-ordinate system |
265 //vector c in a_v_u and a_v_u_n co-ordinate system |
266 xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n); |
266 XY c_a(c_v*a_v_u,c_v*a_v_u_n); |
267 |
267 |
268 //new vector from one node to the breakpoint - d - we have to calculate this one |
268 //new vector from one node to the breakpoint - d - we have to calculate this one |
269 xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); |
269 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); |
270 |
270 |
271 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); |
271 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); |
272 } |
272 } |
273 break; |
273 break; |
274 } |
274 } |
303 //initiating values corresponding to new node in maps |
303 //initiating values corresponding to new node in maps |
304 |
304 |
305 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
305 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
306 |
306 |
307 // update coordinates |
307 // update coordinates |
308 (mytab.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y)); |
308 (mytab.mapstorage).coords.set(active_node, XY(clicked_x, clicked_y)); |
309 |
309 |
310 // update all other maps |
310 // update all other maps |
311 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
311 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
312 (mytab.mapstorage).nodemap_storage.begin(); it != |
312 (mytab.mapstorage).nodemap_storage.begin(); it != |
313 (mytab.mapstorage).nodemap_storage.end(); ++it) |
313 (mytab.mapstorage).nodemap_storage.end(); ++it) |
788 delete(edgetextmap[edge_to_delete]); |
788 delete(edgetextmap[edge_to_delete]); |
789 delete(edgesmap[edge_to_delete]); |
789 delete(edgesmap[edge_to_delete]); |
790 (mytab.mapstorage).graph.erase(edge_to_delete); |
790 (mytab.mapstorage).graph.erase(edge_to_delete); |
791 } |
791 } |
792 |
792 |
793 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
793 void GraphDisplayerCanvas::textReposition(XY new_place) |
794 { |
794 { |
795 new_place+=(xy<double>(10,10)); |
795 new_place+=(XY(10,10)); |
796 edgetextmap[forming_edge]->property_x().set_value(new_place.x); |
796 edgetextmap[forming_edge]->property_x().set_value(new_place.x); |
797 edgetextmap[forming_edge]->property_y().set_value(new_place.y); |
797 edgetextmap[forming_edge]->property_y().set_value(new_place.y); |
798 } |
798 } |
799 |
799 |
800 void GraphDisplayerCanvas::toggleEdgeActivity(EdgeBase* active_bre, bool on) |
800 void GraphDisplayerCanvas::toggleEdgeActivity(EdgeBase* active_bre, bool on) |