Changeset 1645:4a04bb856ac7 in lemon-0.x for gui/graph_displayer_canvas-event.cc
- Timestamp:
- 08/23/05 09:36:09 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2158
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/graph_displayer_canvas-event.cc
r1643 r1645 215 215 { 216 216 switch(e->type) 217 { 218 219 //draw the new node in red at the clicked place 220 case GDK_2BUTTON_PRESS: 221 //std::cout << "double click" << std::endl; 222 break; 223 case GDK_BUTTON_PRESS: 217 { 218 //move the new node 219 case GDK_MOTION_NOTIFY: 220 { 221 GdkEvent * generated=new GdkEvent(); 222 generated->motion.x=e->motion.x; 223 generated->motion.y=e->motion.y; 224 generated->type=GDK_MOTION_NOTIFY; 225 moveEventHandler(generated); 226 break; 227 } 228 229 case GDK_BUTTON_RELEASE: 224 230 mapstorage.modified = true; 225 231 … … 232 238 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 233 239 240 // update coordinates 234 241 mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); 242 243 // update id map 235 244 (*mapstorage.nodemap_storage["id"])[active_node] = 236 245 mapstorage.graph.id(active_node); 237 246 247 // update all other maps 248 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 249 mapstorage.nodemap_storage.begin(); it != 250 mapstorage.nodemap_storage.end(); ++it) 251 { 252 if ((it->first != "id") && 253 (it->first != "coordinates_x") && 254 (it->first != "coordiantes_y")) 255 { 256 (*(it->second))[active_node] = 257 mapstorage.nodemap_default[it->first]; 258 } 259 } 260 238 261 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, 239 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);262 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); 240 263 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); 241 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 242 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); 264 *(nodesmap[active_node]) << 265 Gnome::Canvas::Properties::fill_color("blue"); 266 *(nodesmap[active_node]) << 267 Gnome::Canvas::Properties::outline_color("black"); 268 active_item->raise_to_top(); 269 243 270 (nodesmap[active_node])->show(); 244 271 245 272 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, 246 clicked_x+node_property_defaults[N_RADIUS]+5,247 clicked_y+node_property_defaults[N_RADIUS]+5, "");273 clicked_x+node_property_defaults[N_RADIUS]+5, 274 clicked_y+node_property_defaults[N_RADIUS]+5, ""); 248 275 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); 276 nodetextmap[active_node]->raise_to_top(); 249 277 250 278 mapwin.updateNode(active_node); 251 279 252 break;253 254 //move the new node255 case GDK_MOTION_NOTIFY:256 {257 GdkEvent * generated=new GdkEvent();258 generated->motion.x=e->motion.x;259 generated->motion.y=e->motion.y;260 generated->type=GDK_MOTION_NOTIFY;261 moveEventHandler(generated);262 break;263 }264 265 //finalize the new node266 case GDK_BUTTON_RELEASE:267 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);268 269 active_item->lower_to_bottom();270 271 target_item=NULL;272 target_item=get_item_at(clicked_x, clicked_y);273 274 active_item->raise_to_top();275 276 280 isbutton=0; 277 if(target_item==active_item)278 {279 //Its appropriate color is given by update.280 *active_item << Gnome::Canvas::Properties::fill_color("blue");281 }282 else283 {284 //In this case the given color has to be overwritten, because the noe covers an other item.285 *active_item << Gnome::Canvas::Properties::fill_color("lightblue");286 }287 281 target_item=NULL; 288 282 active_item=NULL; 289 283 active_node=INVALID; 284 290 285 break; 291 286 default: 292 287 break; 293 288 } 294 289 return false; 295 290 } … … 298 293 { 299 294 switch(e->type) 300 295 { 301 296 case GDK_BUTTON_PRESS: 302 297 //in edge creation right button has special meaning 303 298 if(e->button.button!=3) 304 { 305 //there is not yet selected node 306 if(active_node==INVALID) 307 { 308 //we mark the location of the event to be able to calculate parameters of dragging 309 310 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 311 312 active_item=(get_item_at(clicked_x, clicked_y)); 313 active_node=INVALID; 314 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 315 { 316 if(nodesmap[i]==active_item) 317 { 318 active_node=i; 319 } 320 } 321 //the clicked item is really a node 322 if(active_node!=INVALID) 323 { 324 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 325 isbutton=1; 326 } 327 //clicked item was not a node. It could be e.g. edge. 328 else 329 { 330 active_item=NULL; 331 } 332 } 333 //we only have to do sg. if the mouse button 334 // is pressed already once AND the click was 335 // on a node that was found in the set of 336 //nodes, and now we only search for the second 337 //node 338 else 339 { 340 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 341 target_item=(get_item_at(clicked_x, clicked_y)); 342 Node target_node=INVALID; 343 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 344 { 345 if(nodesmap[i]==target_item) 346 { 347 target_node=i; 348 } 349 } 350 //the clicked item is a node, the edge can be drawn 351 if(target_node!=INVALID) 352 { 353 if(target_node!=active_node) 354 { 355 mapstorage.modified = true; 356 357 *(nodesmap[target_node]) << 358 Gnome::Canvas::Properties::fill_color("red"); 359 360 //creating new edge 361 active_edge=mapstorage.graph.addEdge(active_node, 362 target_node); 363 364 //initiating values corresponding to new edge in maps 365 mapstorage.initMapsForEdge(active_edge); 366 (*mapstorage.edgemap_storage["id"])[active_edge] = 367 mapstorage.graph.id(active_edge); 368 369 //calculating coordinates of new edge 370 Gnome::Canvas::Points coos; 371 double x1, x2, y1, y2; 372 373 active_item->get_bounds(x1, y1, x2, y2); 374 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 375 376 target_item->get_bounds(x1, y1, x2, y2); 377 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 378 379 //drawing new edge 380 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this); 381 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); 382 edgesmap[active_edge]->property_width_pixels().set_value(10); 383 384 //redraw nodes to blank terminations of the new edge 385 target_item->raise_to_top(); 386 active_item->raise_to_top(); 387 388 //initializing edge-text as well, to empty string 389 xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); 390 text_pos+=(xy<double>(10,10)); 391 392 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); 393 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); 394 395 //updating its properties 396 mapwin.updateEdge(active_edge); 397 } 398 else 399 { 400 target_node=INVALID; 401 std::cerr << "Loop edge is not yet implemented!" << std::endl; 402 } 403 } 404 //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. 405 else 406 { 407 target_item=NULL; 408 } 409 } 410 } 299 { 300 //there is not yet selected node 301 if(active_node==INVALID) 302 { 303 //we mark the location of the event to be able to calculate parameters of dragging 304 305 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 306 307 active_item=(get_item_at(clicked_x, clicked_y)); 308 active_node=INVALID; 309 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 310 { 311 if(nodesmap[i]==active_item) 312 { 313 active_node=i; 314 } 315 } 316 //the clicked item is really a node 317 if(active_node!=INVALID) 318 { 319 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 320 isbutton=1; 321 } 322 //clicked item was not a node. It could be e.g. edge. 323 else 324 { 325 active_item=NULL; 326 } 327 } 328 //we only have to do sg. if the mouse button 329 // is pressed already once AND the click was 330 // on a node that was found in the set of 331 //nodes, and now we only search for the second 332 //node 333 else 334 { 335 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 336 target_item=(get_item_at(clicked_x, clicked_y)); 337 Node target_node=INVALID; 338 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 339 { 340 if(nodesmap[i]==target_item) 341 { 342 target_node=i; 343 } 344 } 345 //the clicked item is a node, the edge can be drawn 346 if(target_node!=INVALID) 347 { 348 if(target_node!=active_node) 349 { 350 mapstorage.modified = true; 351 352 *(nodesmap[target_node]) << 353 Gnome::Canvas::Properties::fill_color("red"); 354 355 //creating new edge 356 active_edge=mapstorage.graph.addEdge(active_node, 357 target_node); 358 359 // update id map 360 (*mapstorage.edgemap_storage["id"])[active_edge] = 361 mapstorage.graph.id(active_edge); 362 363 // update all other maps 364 for (std::map<std::string, 365 Graph::EdgeMap<double>*>::const_iterator it = 366 mapstorage.edgemap_storage.begin(); it != 367 mapstorage.edgemap_storage.end(); ++it) 368 { 369 if (it->first != "id") 370 { 371 (*(it->second))[active_edge] = 372 mapstorage.edgemap_default[it->first]; 373 } 374 } 375 376 //calculating coordinates of new edge 377 Gnome::Canvas::Points coos; 378 double x1, x2, y1, y2; 379 380 active_item->get_bounds(x1, y1, x2, y2); 381 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 382 383 target_item->get_bounds(x1, y1, x2, y2); 384 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 385 386 //drawing new edge 387 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, 388 *this); 389 *(edgesmap[active_edge]) << 390 Gnome::Canvas::Properties::fill_color("green"); 391 edgesmap[active_edge]->property_width_pixels().set_value(10); 392 393 edgesmap[active_edge]->lower_to_bottom(); 394 395 //initializing edge-text as well, to empty string 396 xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); 397 text_pos+=(xy<double>(10,10)); 398 399 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, 400 text_pos.x, text_pos.y, ""); 401 edgetextmap[active_edge]->property_fill_color().set_value( 402 "darkgreen"); 403 edgetextmap[active_edge]->raise_to_top(); 404 405 //updating its properties 406 mapwin.updateEdge(active_edge); 407 } 408 else 409 { 410 target_node=INVALID; 411 std::cerr << "Loop edge is not yet implemented!" << std::endl; 412 } 413 } 414 //clicked item was not a node. it could be an e.g. edge. we do not 415 //deal with it furthermore. 416 else 417 { 418 target_item=NULL; 419 } 420 } 421 } 411 422 break; 412 423 case GDK_BUTTON_RELEASE: … … 416 427 //2: the edge creation is cancelled with right button 417 428 if((target_item)||(e->button.button==3)) 418 419 420 421 422 423 424 425 426 427 428 429 430 431 429 { 430 if(active_item) 431 { 432 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 433 active_item=NULL; 434 } 435 if(target_item) 436 { 437 *target_item << Gnome::Canvas::Properties::fill_color("blue"); 438 target_item=NULL; 439 } 440 active_node=INVALID; 441 active_edge=INVALID; 442 } 432 443 break; 433 444 default: 434 445 break; 435 446 } 436 447 return false; 437 448 } … … 589 600 if(clicked_edge!=INVALID) 590 601 { 602 // the id map is not editable 603 if (nodemap_to_edit == "id") return 0; 591 604 //If there is already edited edge, it has to be saved first 592 605 if(entrywidget.is_visible()) … … 712 725 if(clicked_node!=INVALID) 713 726 { 727 // the id map is not editable 728 if (nodemap_to_edit == "id") return 0; 714 729 //If there is already edited edge, it has to be saved first 715 730 if(entrywidget.is_visible()) … … 914 929 //if addition was not successful addEdgeMap returns one. 915 930 //cause can be that there is already a map named like the new one 916 if(mapstorage.addEdgeMap(mapname,emptr ))931 if(mapstorage.addEdgeMap(mapname,emptr, default_value)) 917 932 { 918 933 return 1; … … 936 951 //if addition was not successful addNodeMap returns one. 937 952 //cause can be that there is already a map named like the new one 938 if(mapstorage.addNodeMap(mapname,emptr ))953 if(mapstorage.addNodeMap(mapname,emptr, default_value)) 939 954 { 940 955 return 1;
Note: See TracChangeset
for help on using the changeset viewer.