Changeset 201:879e47e5b731 in glemon-0.x for graph_displayer_canvas-event.cc
- Timestamp:
- 01/02/08 22:03:09 (16 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graph_displayer_canvas-event.cc
r200 r201 34 34 { 35 35 if(actual_tool!=newtool) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 36 { 37 38 actual_handler.disconnect(); 39 40 switch(actual_tool) 41 { 42 case CREATE_EDGE: 43 { 44 GdkEvent * generated=new GdkEvent(); 45 generated->type=GDK_BUTTON_RELEASE; 46 generated->button.button=3; 47 createEdgeEventHandler(generated); 48 break; 49 } 50 case MAP_EDIT: 51 { 52 break; 53 } 54 default: 55 break; 56 } 57 58 active_item=NULL; 59 target_item=NULL; 60 active_edge=INVALID; 61 active_node=INVALID; 62 63 64 actual_tool=newtool; 65 66 switch(newtool) 67 { 68 case MOVE: 69 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); 70 break; 71 72 case CREATE_NODE: 73 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false); 74 break; 75 76 case CREATE_EDGE: 77 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false); 78 break; 79 80 case ERASER: 81 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false); 82 break; 83 84 case MAP_EDIT: 85 grab_focus(); 86 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false); 87 break; 88 89 default: 90 break; 91 } 92 } 93 93 } 94 94 … … 139 139 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) 140 140 { 141 MapStorage& ms = *mytab.mapstorage; 142 141 143 static Gnome::Canvas::Text *coord_text = 0; 142 144 switch(e->type) 143 145 { 144 146 case GDK_BUTTON_PRESS: 145 147 //we mark the location of the event to be able to calculate parameters of dragging 146 148 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 147 149 148 150 active_item=(get_item_at(clicked_x, clicked_y)); 149 151 active_node=INVALID; 150 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)151 152 153 154 155 156 152 for (NodeIt i(ms.graph); i!=INVALID; ++i) 153 { 154 if(nodesmap[i]==active_item) 155 { 156 active_node=i; 157 } 158 } 157 159 isbutton=e->button.button; 158 160 break; 159 161 case GDK_BUTTON_RELEASE: 160 162 if (coord_text) 161 162 163 164 163 { 164 delete coord_text; 165 coord_text = 0; 166 } 165 167 isbutton=0; 166 168 active_item=NULL; … … 170 172 //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes 171 173 if(active_node!=INVALID) 172 173 (mytab.mapstorage)->modified = true;174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 (mytab.mapstorage)->coords[active_node].x << ", " <<196 (mytab.mapstorage)->coords[active_node].y << ")";197 198 199 200 201 202 203 coord_text->property_x().set_value((mytab.mapstorage)->coords[active_node].x + 204 205 coord_text->property_y().set_value((mytab.mapstorage)->coords[active_node].y - 206 207 208 209 210 211 212 (mytab.mapstorage)->coords[active_node].x + radius,213 (mytab.mapstorage)->coords[active_node].y - radius,214 215 216 217 218 219 220 174 { 175 ms.setModified(); 176 177 //new coordinates will be the old values, 178 //because the item will be moved to the 179 //new coordinate therefore the new movement 180 //has to be calculated from here 181 182 double new_x, new_y; 183 184 window_to_world (e->motion.x, e->motion.y, new_x, new_y); 185 186 double dx=new_x-clicked_x; 187 double dy=new_y-clicked_y; 188 189 moveNode(dx, dy); 190 191 clicked_x=new_x; 192 clicked_y=new_y; 193 194 // reposition the coordinates text 195 std::ostringstream ostr; 196 ostr << "(" << 197 ms.getNodeCoords(active_node).x << ", " << 198 ms.getNodeCoords(active_node).y << ")"; 199 double radius = 200 (nodesmap[active_node]->property_x2().get_value() - 201 nodesmap[active_node]->property_x1().get_value()) / 2.0; 202 if (coord_text) 203 { 204 coord_text->property_text().set_value(ostr.str()); 205 coord_text->property_x().set_value( 206 ms.getNodeCoords(active_node).x + radius); 207 coord_text->property_y().set_value( 208 ms.getNodeCoords(active_node).y - radius); 209 } 210 else 211 { 212 coord_text = new Gnome::Canvas::Text( 213 displayed_graph, 214 ms.getNodeCoords(active_node).x + radius, 215 ms.getNodeCoords(active_node).y - radius, 216 ostr.str()); 217 coord_text->property_fill_color().set_value("black"); 218 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); 219 } 220 221 222 } 221 223 default: break; 222 223 224 return false;224 } 225 226 return false; 225 227 } 226 228 … … 228 230 { 229 231 switch(move_code) 230 232 { 231 233 case 1: 232 234 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); … … 237 239 case 3: 238 240 { 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 241 ////////////////////////////////////////////////////////////////////////////////////////////////////// 242 /////////// keeps shape-with scalar multiplication - version 2. 243 ////////////////////////////////////////////////////////////////////////////////////////////////////// 244 245 //old vector from one to the other node - a 246 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); 247 //new vector from one to the other node - b 248 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); 249 250 double absa=sqrt(a_v.normSquare()); 251 double absb=sqrt(b_v.normSquare()); 252 253 if ((absa == 0.0) || (absb == 0.0)) 254 { 255 return old_arrow_pos; 256 } 257 else 258 { 259 //old vector from one node to the breakpoint - c 260 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); 261 262 //unit vector with the same direction to a_v 263 XY a_v_u(a_v.x/absa,a_v.y/absa); 264 265 //normal vector of unit vector with the same direction to a_v 266 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x); 267 268 //unit vector with the same direction to b_v 269 XY b_v_u(b_v.x/absb,b_v.y/absb); 270 271 //normal vector of unit vector with the same direction to b_v 272 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x); 273 274 //vector c in a_v_u and a_v_u_n co-ordinate system 275 XY c_a(c_v*a_v_u,c_v*a_v_u_n); 276 277 //new vector from one node to the breakpoint - d - we have to calculate this one 278 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); 279 280 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); 281 } 282 break; 281 283 } 282 284 default: 283 285 break; 284 286 } 285 287 } 286 288 … … 288 290 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) 289 291 { 292 MapStorage& ms = *mytab.mapstorage; 293 290 294 switch(e->type) 291 295 { … … 302 306 303 307 case GDK_BUTTON_RELEASE: 304 (mytab.mapstorage)->modified = true;308 ms.setModified(); 305 309 306 310 is_drawn=true; … … 308 312 isbutton=1; 309 313 310 active_node=(mytab.mapstorage)->graph.addNode();311 312 //initiating values corresponding to new node in maps313 314 314 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 315 315 316 // update coordinates 317 (mytab.mapstorage)->coords.set(active_node, XY(clicked_x, clicked_y)); 318 319 // update all other maps 320 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 321 (mytab.mapstorage)->nodemap_storage.begin(); it != 322 (mytab.mapstorage)->nodemap_storage.end(); ++it) 323 { 324 if ((it->first != "coordinates_x") && 325 (it->first != "coordinates_y")) 326 { 327 (*(it->second))[active_node] = 328 (mytab.mapstorage)->nodemap_default[it->first]; 329 } 330 } 331 // increment the id map's default value 332 (mytab.mapstorage)->nodemap_default["label"] += 1.0; 316 active_node = ms.addNode(XY(clicked_x, clicked_y)); 333 317 334 318 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, … … 349 333 nodetextmap[active_node]->raise_to_top(); 350 334 351 // mapwin.updateNode(active_node);335 // mapwin.updateNode(active_node); 352 336 propertyUpdate(active_node); 353 337 … … 365 349 bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e) 366 350 { 351 MapStorage& ms = *mytab.mapstorage; 352 367 353 switch(e->type) 368 354 { … … 380 366 active_item=(get_item_at(clicked_x, clicked_y)); 381 367 active_node=INVALID; 382 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)368 for (NodeIt i(ms.graph); i!=INVALID; ++i) 383 369 { 384 370 if(nodesmap[i]==active_item) … … 409 395 target_item=(get_item_at(clicked_x, clicked_y)); 410 396 Node target_node=INVALID; 411 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)397 for (NodeIt i(ms.graph); i!=INVALID; ++i) 412 398 { 413 399 if(nodesmap[i]==target_item) … … 419 405 if(target_node!=INVALID) 420 406 { 421 (mytab.mapstorage)->modified = true;407 ms.setModified(); 422 408 423 409 *(nodesmap[target_node]) << 424 410 Gnome::Canvas::Properties::fill_color("red"); 425 411 426 //creating new edge 427 active_edge=(mytab.mapstorage)->graph.addEdge(active_node, 428 target_node); 429 430 // update maps 431 for (std::map<std::string, 432 Graph::EdgeMap<double>*>::const_iterator it = 433 (mytab.mapstorage)->edgemap_storage.begin(); it != 434 (mytab.mapstorage)->edgemap_storage.end(); ++it) 435 { 436 (*(it->second))[active_edge] = 437 (mytab.mapstorage)->edgemap_default[it->first]; 438 } 439 // increment the id map's default value 440 (mytab.mapstorage)->edgemap_default["label"] += 1.0; 412 active_edge = ms.addEdge(active_node, target_node); 441 413 442 414 if(target_node!=active_node) 443 415 { 444 // set the coordinates of the arrow on the new edge 445 MapStorage& ms = *mytab.mapstorage; 446 ms.arrow_pos.set(active_edge, 447 (ms.coords[ms.graph.source(active_edge)] + 448 ms.coords[ms.graph.target(active_edge)])/ 2.0); 449 450 //drawing new edge 451 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, 452 *this); 416 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this); 453 417 } 454 418 else 455 419 { 456 // set the coordinates of the arrow on the new edge 457 MapStorage& ms = *mytab.mapstorage; 458 ms.arrow_pos.set(active_edge, 459 (ms.coords[ms.graph.source(active_edge)] + 460 XY(0.0, 80.0))); 461 462 //drawing new edge 463 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, 464 *this); 420 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, *this); 465 421 } 466 422 467 423 //initializing edge-text as well, to empty string 468 XY text_pos=m ytab.mapstorage->arrow_pos[active_edge];424 XY text_pos=ms.getArrowCoords(active_edge); 469 425 text_pos+=(XY(10,10)); 470 426 … … 495 451 if(active_item) 496 452 { 497 453 propertyUpdate(active_node,N_COLOR); 498 454 active_item=NULL; 499 455 } 500 456 if(target_item) 501 457 { 502 propertyUpdate((mytab.mapstorage)->graph.target(active_edge),N_COLOR);458 propertyUpdate(ms.graph.target(active_edge),N_COLOR); 503 459 target_item=NULL; 504 460 } … … 515 471 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) 516 472 { 473 MapStorage& ms = *mytab.mapstorage; 474 517 475 switch(e->type) 518 476 { 519 477 case GDK_BUTTON_PRESS: 520 478 //finding the clicked items … … 524 482 active_edge=INVALID; 525 483 //was it a node? 526 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)527 528 529 530 531 532 484 for (NodeIt i(ms.graph); i!=INVALID; ++i) 485 { 486 if(nodesmap[i]==active_item) 487 { 488 active_node=i; 489 } 490 } 533 491 //or was it an edge? 534 492 if(active_node==INVALID) 535 536 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)537 538 539 540 541 542 543 493 { 494 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 495 { 496 if(edgesmap[i]->getLine()==active_item) 497 { 498 active_edge=i; 499 } 500 } 501 } 544 502 545 503 // return if the clicked object is neither an edge nor a node 546 504 if (active_edge == INVALID) return false; 547 505 548 506 //recolor activated item 549 507 if(active_item) 550 551 552 508 { 509 *active_item << Gnome::Canvas::Properties::fill_color("red"); 510 } 553 511 break; 554 512 … … 556 514 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 557 515 if(active_item) 558 559 560 561 562 563 564 565 (mytab.mapstorage)->modified = true;566 567 568 569 for(OutEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)570 571 572 573 574 for(InEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 516 { 517 //the cursor was not moved since pressing it 518 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) 519 { 520 //a node was found 521 if(active_node!=INVALID) 522 { 523 ms.setModified(); 524 525 std::set<Graph::Edge> edges_to_delete; 526 527 for(OutEdgeIt e(ms.graph,active_node);e!=INVALID;++e) 528 { 529 edges_to_delete.insert(e); 530 } 531 532 for(InEdgeIt e(ms.graph,active_node);e!=INVALID;++e) 533 { 534 edges_to_delete.insert(e); 535 } 536 537 //deleting collected edges 538 for(std::set<Graph::Edge>::iterator 539 edge_set_it=edges_to_delete.begin(); 540 edge_set_it!=edges_to_delete.end(); 541 ++edge_set_it) 542 { 543 deleteItem(*edge_set_it); 544 } 545 deleteItem(active_node); 546 } 547 //a simple edge was chosen 548 else if (active_edge != INVALID) 549 { 550 deleteItem(active_edge); 551 } 552 } 553 //pointer was moved, deletion is cancelled 554 else 555 { 556 if(active_node!=INVALID) 557 { 558 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 559 } 560 else if (active_edge != INVALID) 561 { 562 *active_item << Gnome::Canvas::Properties::fill_color("green"); 563 } 564 } 565 } 608 566 //reseting datas 609 567 active_item=NULL; … … 617 575 default: 618 576 break; 619 577 } 620 578 return false; 621 579 } … … 623 581 bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e) 624 582 { 583 MapStorage& ms = *mytab.mapstorage; 584 625 585 if(actual_tool==MAP_EDIT) 626 { 627 switch(e->type) 628 { 629 case GDK_BUTTON_PRESS: 630 { 631 //for determine, whether it was an edge 632 Edge clicked_edge=INVALID; 633 //for determine, whether it was a node 634 Node clicked_node=INVALID; 635 636 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 637 active_item=(get_item_at(clicked_x, clicked_y)); 638 639 //find the activated item between text of nodes 640 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 641 { 642 //at the same time only one can be active 643 if(nodetextmap[i]==active_item) 644 { 645 clicked_node=i; 646 } 647 } 648 649 //if there was not, search for it between nodes 650 if(clicked_node==INVALID) 651 { 652 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 653 { 654 //at the same time only one can be active 655 if(nodesmap[i]==active_item) 656 { 657 clicked_node=i; 658 } 659 } 660 } 661 662 if(clicked_node==INVALID) 663 { 664 //find the activated item between texts 665 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 666 { 667 //at the same time only one can be active 668 if(edgetextmap[i]==active_item) 669 { 670 clicked_edge=i; 671 } 672 } 673 674 //if it was not between texts, search for it between edges 675 if(clicked_edge==INVALID) 676 { 677 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 678 { 679 //at the same time only one can be active 680 if((edgesmap[i]->getLine())==active_item) 681 { 682 clicked_edge=i; 683 } 684 } 685 } 686 } 687 688 //if it was really a node... 689 if(clicked_node!=INVALID) 690 { 691 // the id map is not editable 692 if (nodemap_to_edit == "label") return 0; 693 694 //and there is activated map 695 if(nodetextmap[clicked_node]->property_text().get_value()!="") 696 { 697 //activate the general variable for it 698 active_node=clicked_node; 699 700 //create a dialog 701 Gtk::Dialog dialog("Edit value", true); 702 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 703 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 704 Gtk::VBox* vbox = dialog.get_vbox(); 705 Gtk::SpinButton spin(0.0, 4); 706 spin.set_increments(1.0, 10.0); 707 spin.set_range(-1000000.0, 1000000.0); 708 spin.set_numeric(true); 709 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); 710 vbox->add(spin); 711 spin.show(); 712 switch (dialog.run()) 713 { 714 case Gtk::RESPONSE_NONE: 715 case Gtk::RESPONSE_CANCEL: 716 break; 717 case Gtk::RESPONSE_ACCEPT: 718 double new_value = spin.get_value(); 719 (*(mytab.mapstorage)->nodemap_storage[nodemap_to_edit])[active_node] = 720 new_value; 721 std::ostringstream ostr; 722 ostr << new_value; 723 nodetextmap[active_node]->property_text().set_value(ostr.str()); 724 //mapwin.updateNode(active_node); 725 //mapwin.updateNode(Node(INVALID)); 726 propertyUpdate(Node(INVALID)); 727 } 728 } 729 } 730 else 731 //if it was really an edge... 732 if(clicked_edge!=INVALID) 733 { 734 // the id map is not editable 735 if (edgemap_to_edit == "label") return 0; 736 737 //and there is activated map 738 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 739 { 740 //activate the general variable for it 741 active_edge=clicked_edge; 742 743 //create a dialog 744 Gtk::Dialog dialog("Edit value", true); 745 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 746 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 747 Gtk::VBox* vbox = dialog.get_vbox(); 748 Gtk::SpinButton spin(0.0, 4); 749 spin.set_increments(1.0, 10.0); 750 spin.set_range(-1000000.0, 1000000.0); 751 spin.set_numeric(true); 752 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); 753 vbox->add(spin); 754 spin.show(); 755 switch (dialog.run()) 756 { 757 case Gtk::RESPONSE_NONE: 758 case Gtk::RESPONSE_CANCEL: 759 break; 760 case Gtk::RESPONSE_ACCEPT: 761 double new_value = spin.get_value(); 762 (*(mytab.mapstorage)->edgemap_storage[edgemap_to_edit])[active_edge] = 763 new_value; 764 std::ostringstream ostr; 765 ostr << new_value; 766 edgetextmap[active_edge]->property_text().set_value( 767 ostr.str()); 768 //mapwin.updateEdge(active_edge); 769 // mapwin.updateEdge(Edge(INVALID)); 770 propertyUpdate(Edge(INVALID)); 771 } 772 } 773 } 774 break; 775 } 776 default: 777 break; 778 } 779 } 586 { 587 switch(e->type) 588 { 589 case GDK_BUTTON_PRESS: 590 { 591 //for determine, whether it was an edge 592 Edge clicked_edge=INVALID; 593 //for determine, whether it was a node 594 Node clicked_node=INVALID; 595 596 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 597 active_item=(get_item_at(clicked_x, clicked_y)); 598 599 //find the activated item between text of nodes 600 for (NodeIt i(ms.graph); i!=INVALID; ++i) 601 { 602 //at the same time only one can be active 603 if(nodetextmap[i]==active_item) 604 { 605 clicked_node=i; 606 } 607 } 608 609 //if there was not, search for it between nodes 610 if(clicked_node==INVALID) 611 { 612 for (NodeIt i(ms.graph); i!=INVALID; ++i) 613 { 614 //at the same time only one can be active 615 if(nodesmap[i]==active_item) 616 { 617 clicked_node=i; 618 } 619 } 620 } 621 622 if(clicked_node==INVALID) 623 { 624 //find the activated item between texts 625 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 626 { 627 //at the same time only one can be active 628 if(edgetextmap[i]==active_item) 629 { 630 clicked_edge=i; 631 } 632 } 633 634 //if it was not between texts, search for it between edges 635 if(clicked_edge==INVALID) 636 { 637 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 638 { 639 //at the same time only one can be active 640 if((edgesmap[i]->getLine())==active_item) 641 { 642 clicked_edge=i; 643 } 644 } 645 } 646 } 647 648 //if it was really a node... 649 if(clicked_node!=INVALID) 650 { 651 // the id map is not editable 652 if (nodemap_to_edit == "label") return 0; 653 654 //and there is activated map 655 if(nodetextmap[clicked_node]->property_text().get_value()!="") 656 { 657 //activate the general variable for it 658 active_node=clicked_node; 659 660 //create a dialog 661 Gtk::Dialog dialog("Edit value", true); 662 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 663 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 664 Gtk::VBox* vbox = dialog.get_vbox(); 665 666 /* 667 Gtk::SpinButton spin(0.0, 4); 668 spin.set_increments(1.0, 10.0); 669 spin.set_range(-1000000.0, 1000000.0); 670 spin.set_numeric(true); 671 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); 672 vbox->add(spin); 673 spin.show(); 674 */ 675 Gtk::Entry entry; 676 entry.set_text(nodetextmap[active_node]->property_text().get_value()); 677 vbox->add(entry); 678 entry.show(); 679 680 switch (dialog.run()) 681 { 682 case Gtk::RESPONSE_NONE: 683 case Gtk::RESPONSE_CANCEL: 684 break; 685 case Gtk::RESPONSE_ACCEPT: 686 switch (ms.getNodeMapElementType(nodemap_to_edit)) 687 { 688 case MapValue::NUMERIC: 689 ms.set(nodemap_to_edit, active_node, 690 atof(entry.get_text().c_str())); 691 break; 692 case MapValue::STRING: 693 ms.set(nodemap_to_edit, active_node, 694 static_cast<std::string>(entry.get_text())); 695 break; 696 } 697 nodetextmap[active_node]->property_text().set_value( 698 static_cast<std::string>(ms.get(nodemap_to_edit, active_node))); 699 700 //mapwin.updateNode(active_node); 701 //mapwin.updateNode(Node(INVALID)); 702 propertyUpdate(Node(INVALID)); 703 } 704 } 705 } 706 else 707 //if it was really an edge... 708 if(clicked_edge!=INVALID) 709 { 710 // the id map is not editable 711 if (edgemap_to_edit == "label") return 0; 712 713 //and there is activated map 714 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 715 { 716 //activate the general variable for it 717 active_edge=clicked_edge; 718 719 //create a dialog 720 Gtk::Dialog dialog("Edit value", true); 721 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 722 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 723 Gtk::VBox* vbox = dialog.get_vbox(); 724 725 /* 726 Gtk::SpinButton spin(0.0, 4); 727 spin.set_increments(1.0, 10.0); 728 spin.set_range(-1000000.0, 1000000.0); 729 spin.set_numeric(true); 730 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); 731 vbox->add(spin); 732 spin.show(); 733 */ 734 Gtk::Entry entry; 735 entry.set_text(edgetextmap[active_edge]->property_text().get_value()); 736 vbox->add(entry); 737 entry.show(); 738 739 std::cout << edgemap_to_edit << std::endl; 740 switch (dialog.run()) 741 { 742 case Gtk::RESPONSE_NONE: 743 case Gtk::RESPONSE_CANCEL: 744 break; 745 case Gtk::RESPONSE_ACCEPT: 746 switch (ms.getEdgeMapElementType(edgemap_to_edit)) 747 { 748 case MapValue::NUMERIC: 749 ms.set(edgemap_to_edit, active_edge, 750 atof(entry.get_text().c_str())); 751 break; 752 case MapValue::STRING: 753 ms.set(edgemap_to_edit, active_edge, 754 static_cast<std::string>(entry.get_text())); 755 break; 756 } 757 edgetextmap[active_edge]->property_text().set_value( 758 static_cast<std::string>(ms.get(edgemap_to_edit, active_edge))); 759 760 //mapwin.updateEdge(active_edge); 761 // mapwin.updateEdge(Edge(INVALID)); 762 propertyUpdate(Edge(INVALID)); 763 } 764 } 765 } 766 break; 767 } 768 default: 769 break; 770 } 771 } 780 772 return false; 781 773 } … … 785 777 delete(nodetextmap[node_to_delete]); 786 778 delete(nodesmap[node_to_delete]); 787 (mytab.mapstorage)->graph.erase(node_to_delete);779 mytab.mapstorage->graph.erase(node_to_delete); 788 780 } 789 781 … … 792 784 delete(edgetextmap[edge_to_delete]); 793 785 delete(edgesmap[edge_to_delete]); 794 (mytab.mapstorage)->graph.erase(edge_to_delete);786 mytab.mapstorage->graph.erase(edge_to_delete); 795 787 } 796 788 … … 812 804 else 813 805 { 814 for (EdgeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)806 for (EdgeIt i(mytab.mapstorage->graph); i!=INVALID; ++i) 815 807 { 816 808 if(edgesmap[i]==active_bre) … … 822 814 } 823 815 else 824 825 826 827 828 829 830 831 832 833 816 { 817 if(forming_edge!=INVALID) 818 { 819 forming_edge=INVALID; 820 } 821 else 822 { 823 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; 824 } 825 } 834 826 } 835 827 836 828 void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node) 837 829 { 830 MapStorage& ms = *mytab.mapstorage; 831 838 832 Gnome::Canvas::Item * moved_item=item; 839 833 Node moved_node=node; 840 834 841 835 if(item==NULL && node==INVALID) 842 843 844 845 836 { 837 moved_item=active_item; 838 moved_node=active_node; 839 } 846 840 else 847 848 849 841 { 842 isbutton=1; 843 } 850 844 851 845 //repositioning node and its text … … 854 848 855 849 // the new coordinates of the centre of the node 856 double coord_x = dx + (mytab.mapstorage)->coords[moved_node].x;857 double coord_y = dy + (mytab.mapstorage)->coords[moved_node].y;850 double coord_x = dx + ms.getNodeCoords(moved_node).x; 851 double coord_y = dy + ms.getNodeCoords(moved_node).y; 858 852 859 853 // write back the new coordinates to the coords map 860 (mytab.mapstorage)->coords.set(moved_node, XY(coord_x, coord_y));854 ms.setNodeCoords(moved_node, XY(coord_x, coord_y)); 861 855 862 856 //all the edges connected to the moved point has to be redrawn 863 for(OutEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) 864 { 857 for(OutEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) 858 { 859 XY arrow_pos; 860 861 if (ms.graph.source(ei) == ms.graph.target(ei)) 862 { 863 arrow_pos = ms.getArrowCoords(ei) + XY(dx, dy); 864 } 865 else 866 { 867 XY moved_node_1(coord_x - dx, coord_y - dy); 868 XY moved_node_2(coord_x, coord_y); 869 Node target = ms.graph.target(ei); 870 XY fix_node = ms.getNodeCoords(target); 871 XY old_arrow_pos(ms.getArrowCoords(ei)); 872 873 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 874 } 875 876 ms.setArrowCoords(ei, arrow_pos); 877 edgesmap[ei]->draw(); 878 879 //reposition of edgetext 880 XY text_pos=ms.getArrowCoords(ei); 881 text_pos+=(XY(10,10)); 882 edgetextmap[ei]->property_x().set_value(text_pos.x); 883 edgetextmap[ei]->property_y().set_value(text_pos.y); 884 } 885 886 for(InEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) 887 { 888 if (ms.graph.source(ei) != ms.graph.target(ei)) 889 { 890 XY moved_node_1(coord_x - dx, coord_y - dy); 891 XY moved_node_2(coord_x, coord_y); 892 Node source = ms.graph.source(ei); 893 XY fix_node = ms.getNodeCoords(source); 894 XY old_arrow_pos(ms.getArrowCoords(ei)); 895 865 896 XY arrow_pos; 866 867 if (mytab.mapstorage->graph.source(ei) == mytab.mapstorage->graph.target(ei)) 868 { 869 arrow_pos = mytab.mapstorage->arrow_pos[ei] + XY(dx, dy); 870 } 871 else 872 { 873 XY moved_node_1(coord_x - dx, coord_y - dy); 874 XY moved_node_2(coord_x, coord_y); 875 Node target = mytab.mapstorage->graph.target(ei); 876 XY fix_node(mytab.mapstorage->coords[target].x, 877 mytab.mapstorage->coords[target].y); 878 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); 879 880 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 881 } 882 883 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); 897 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 898 899 ms.setArrowCoords(ei, arrow_pos); 884 900 edgesmap[ei]->draw(); 885 901 886 902 //reposition of edgetext 887 XY text_pos=m ytab.mapstorage->arrow_pos[ei];903 XY text_pos=ms.getArrowCoords(ei); 888 904 text_pos+=(XY(10,10)); 889 905 edgetextmap[ei]->property_x().set_value(text_pos.x); 890 906 edgetextmap[ei]->property_y().set_value(text_pos.y); 891 907 } 892 893 for(InEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) 894 { 895 if (mytab.mapstorage->graph.source(ei) != mytab.mapstorage->graph.target(ei)) 896 { 897 XY moved_node_1(coord_x - dx, coord_y - dy); 898 XY moved_node_2(coord_x, coord_y); 899 Node source = mytab.mapstorage->graph.source(ei); 900 XY fix_node(mytab.mapstorage->coords[source].x, 901 mytab.mapstorage->coords[source].y); 902 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); 903 904 XY arrow_pos; 905 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 906 907 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); 908 edgesmap[ei]->draw(); 909 910 //reposition of edgetext 911 XY text_pos=mytab.mapstorage->arrow_pos[ei]; 912 text_pos+=(XY(10,10)); 913 edgetextmap[ei]->property_x().set_value(text_pos.x); 914 edgetextmap[ei]->property_y().set_value(text_pos.y); 915 } 916 } 908 } 917 909 } 918 910 … … 929 921 //the actual value belongs to 930 922 for (int i=0;i<=5;i++) 931 932 933 934 935 936 923 { 924 if(((double)i/6<pos)&&(pos<=(double(i+1)/6))) 925 { 926 phase=i; 927 } 928 } 937 929 if(phase<6) 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 930 { 931 //within its 1/6 long phase the relativ position 932 //determines the power of the color changed in 933 //that phase 934 //we normalize that to one, to be able to give percentage 935 //value for the function 936 double rel_pos=(pos-(phase/6.0))*6.0; 937 938 switch(phase) 939 { 940 case 0: 941 color.set_rgb_p (1, 0, 1-rel_pos); 942 break; 943 case 1: 944 color.set_rgb_p (1, rel_pos, 0); 945 break; 946 case 2: 947 color.set_rgb_p (1-rel_pos, 1, 0); 948 break; 949 case 3: 950 color.set_rgb_p (0, 1, rel_pos); 951 break; 952 case 4: 953 color.set_rgb_p (0, 1-rel_pos, 1); 954 break; 955 case 5: 956 color.set_rgb_p ((rel_pos/3.0), 0, 1); 957 break; 958 default: 959 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; 960 } 961 } 970 962 else 971 972 973 963 { 964 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; 965 } 974 966 return color; 975 967 }
Note: See TracChangeset
for help on using the changeset viewer.