Changeset 98:f60f89147531 in glemon-0.x for graph_displayer_canvas-event.cc
- Timestamp:
- 12/17/05 21:55:41 (19 years ago)
- Branch:
- gui
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2432
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graph_displayer_canvas-event.cc
r96 r98 148 148 double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y); 149 149 150 // write back the new coordinates to the coords map 151 (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y)); 152 150 153 clicked_x=new_x; 151 154 clicked_y=new_y; 152 153 // write back the new coordinates to the coords map154 (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));155 155 156 156 // reposition the coordinates text … … 184 184 for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) 185 185 { 186 Gnome::Canvas::Points coos; 187 double x1, x2, y1, y2; 188 189 nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); 190 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 191 192 nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); 193 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 194 186 XY moved_node_1(coord_x - dx, coord_y - dy); 187 XY moved_node_2(coord_x, coord_y); 188 Node target = mytab.mapstorage.graph.target(ei); 189 XY fix_node(mytab.mapstorage.coords[target].x, 190 mytab.mapstorage.coords[target].y); 191 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); 192 193 XY arrow_pos; 195 194 if(isbutton==3) 196 { 197 edgesmap[ei]->setPoints(coos); 198 } 195 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); 199 196 else 200 { 201 edgesmap[ei]->setPoints(coos,true); 202 } 197 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); 198 199 mytab.mapstorage.arrow_pos.set(ei, arrow_pos); 200 edgesmap[ei]->draw(); 203 201 204 202 //reposition of edgetext 205 xy<double> text_pos=edgesmap[ei]->getArrowPos();206 text_pos+=( xy<double>(10,10));203 XY text_pos=mytab.mapstorage.arrow_pos[ei]; 204 text_pos+=(XY(10,10)); 207 205 edgetextmap[ei]->property_x().set_value(text_pos.x); 208 206 edgetextmap[ei]->property_y().set_value(text_pos.y); … … 211 209 for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) 212 210 { 213 Gnome::Canvas::Points coos; 214 double x1, x2, y1, y2; 215 216 nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); 217 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 218 219 nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); 220 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 221 211 XY moved_node_1(coord_x - dx, coord_y - dy); 212 XY moved_node_2(coord_x, coord_y); 213 Node source = mytab.mapstorage.graph.source(ei); 214 XY fix_node(mytab.mapstorage.coords[source].x, 215 mytab.mapstorage.coords[source].y); 216 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); 217 218 XY arrow_pos; 222 219 if(isbutton==3) 223 { 224 edgesmap[ei]->setPoints(coos); 225 } 220 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); 226 221 else 227 { 228 edgesmap[ei]->setPoints(coos,true); 229 } 230 231 xy<double> text_pos=edgesmap[ei]->getArrowPos(); 232 text_pos+=(xy<double>(10,10)); 222 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); 223 224 mytab.mapstorage.arrow_pos.set(ei, arrow_pos); 225 edgesmap[ei]->draw(); 226 227 //reposition of edgetext 228 XY text_pos=mytab.mapstorage.arrow_pos[ei]; 229 text_pos+=(XY(10,10)); 233 230 edgetextmap[ei]->property_x().set_value(text_pos.x); 234 231 edgetextmap[ei]->property_y().set_value(text_pos.y); … … 239 236 240 237 return false; 238 } 239 240 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move) 241 { 242 if(!move) 243 { 244 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); 245 } 246 else 247 { 248 ////////////////////////////////////////////////////////////////////////////////////////////////////// 249 /////////// keeps shape-with scalar multiplication - version 2. 250 ////////////////////////////////////////////////////////////////////////////////////////////////////// 251 252 //old vector from one to the other node - a 253 xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); 254 //new vector from one to the other node - b 255 xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); 256 257 double absa=sqrt(a_v.normSquare()); 258 double absb=sqrt(b_v.normSquare()); 259 260 if ((absa == 0.0) || (absb == 0.0)) 261 { 262 return old_arrow_pos; 263 } 264 else 265 { 266 //old vector from one node to the breakpoint - c 267 xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); 268 269 //unit vector with the same direction to a_v 270 xy<double> a_v_u(a_v.x/absa,a_v.y/absa); 271 272 //normal vector of unit vector with the same direction to a_v 273 xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x); 274 275 //unit vector with the same direction to b_v 276 xy<double> b_v_u(b_v.x/absb,b_v.y/absb); 277 278 //normal vector of unit vector with the same direction to b_v 279 xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x); 280 281 //vector c in a_v_u and a_v_u_n co-ordinate system 282 xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n); 283 284 //new vector from one node to the breakpoint - d - we have to calculate this one 285 xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); 286 287 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); 288 } 289 } 241 290 } 242 291 … … 406 455 407 456 //drawing new edge 408 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,457 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, 409 458 *this); 410 459 *(edgesmap[active_edge]) << … … 415 464 416 465 //initializing edge-text as well, to empty string 417 xy<double> text_pos=edgesmap[active_edge]->getArrowPos();418 text_pos+=( xy<double>(10,10));466 XY text_pos=mytab.mapstorage.arrow_pos[active_edge]; 467 text_pos+=(XY(10,10)); 419 468 420 469 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
Note: See TracChangeset
for help on using the changeset viewer.