422 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) |
422 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) |
423 { |
423 { |
424 switch(e->type) |
424 switch(e->type) |
425 { |
425 { |
426 case GDK_BUTTON_PRESS: |
426 case GDK_BUTTON_PRESS: |
|
427 //finding the clicked items |
427 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
428 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
428 active_item=(get_item_at(clicked_x, clicked_y)); |
429 active_item=(get_item_at(clicked_x, clicked_y)); |
429 active_node=INVALID; |
430 active_node=INVALID; |
430 active_edge=INVALID; |
431 active_edge=INVALID; |
|
432 |
|
433 //was it a node? |
431 for (NodeIt i(g); i!=INVALID; ++i) |
434 for (NodeIt i(g); i!=INVALID; ++i) |
432 { |
435 { |
433 if(nodesmap[i]==active_item) |
436 if(nodesmap[i]==active_item) |
434 { |
437 { |
435 active_node=i; |
438 active_node=i; |
436 } |
439 } |
437 } |
440 } |
|
441 //or was it an edge? |
438 if(active_node==INVALID) |
442 if(active_node==INVALID) |
439 { |
443 { |
440 for (EdgeIt i(g); i!=INVALID; ++i) |
444 for (EdgeIt i(g); i!=INVALID; ++i) |
441 { |
445 { |
442 if(edgesmap[i]==active_item) |
446 if(edgesmap[i]==active_item) |
443 { |
447 { |
444 active_edge=i; |
448 active_edge=i; |
445 } |
449 } |
446 } |
450 } |
447 } |
451 } |
|
452 |
|
453 //recolor activated item |
448 if(active_item) |
454 if(active_item) |
449 { |
455 { |
450 *active_item << Gnome::Canvas::Properties::fill_color("red"); |
456 *active_item << Gnome::Canvas::Properties::fill_color("red"); |
451 } |
457 } |
452 break; |
458 break; |
453 |
459 |
454 case GDK_BUTTON_RELEASE: |
460 case GDK_BUTTON_RELEASE: |
455 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
461 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
456 if(active_item) |
462 if(active_item) |
457 { |
463 { |
|
464 //the cursor was not moved since pressing it |
458 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
465 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
459 { |
466 { |
|
467 //a node was found |
460 if(active_node!=INVALID) |
468 if(active_node!=INVALID) |
461 { |
469 { |
462 |
470 |
463 //collecting edges to delete |
471 //collecting edges to delete |
464 EdgeIt e; |
472 EdgeIt e; |
520 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e) |
528 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e) |
521 { |
529 { |
522 switch(e->type) |
530 switch(e->type) |
523 { |
531 { |
524 case GDK_KEY_PRESS: |
532 case GDK_KEY_PRESS: |
|
533 //for Escape or Enter hide the displayed widget |
525 { |
534 { |
526 nodeMapEditEventHandler(e); |
535 nodeMapEditEventHandler(e); |
527 break; |
536 break; |
528 } |
537 } |
529 case GDK_BUTTON_PRESS: |
538 case GDK_BUTTON_PRESS: |
|
539 //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. |
530 { |
540 { |
|
541 //find the activated item |
531 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
542 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
532 active_item=(get_item_at(clicked_x, clicked_y)); |
543 active_item=(get_item_at(clicked_x, clicked_y)); |
|
544 |
|
545 //determine, whether it was an edge |
533 Graph::EdgeIt clicked_edge=INVALID; |
546 Graph::EdgeIt clicked_edge=INVALID; |
534 for (EdgeIt i(g); i!=INVALID; ++i) |
547 for (EdgeIt i(g); i!=INVALID; ++i) |
535 { |
548 { |
536 if(edgesmap[i]==active_item) |
549 if(edgesmap[i]==active_item) |
537 { |
550 { |
538 clicked_edge=i; |
551 clicked_edge=i; |
539 } |
552 } |
540 } |
553 } |
|
554 //if it was really an edge... |
541 if(clicked_edge!=INVALID) |
555 if(clicked_edge!=INVALID) |
542 { |
556 { |
543 if(edgetextmap[clicked_edge]->property_text().get_value()!="") |
557 //If there is already edited edge, it has to be saved first |
544 { |
558 if(entrywidget.is_visible()) |
545 active_edge=clicked_edge; |
559 { |
546 if(canvasentrywidget) |
560 GdkEvent * generated=new GdkEvent(); |
|
561 generated->type=GDK_KEY_PRESS; |
|
562 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
|
563 entryWidgetChangeHandler(generated); |
|
564 } |
|
565 //If the previous value could be saved, we can go further, otherwise not |
|
566 if(!entrywidget.is_visible()) |
|
567 { |
|
568 //and there is activated map |
|
569 if(edgetextmap[clicked_edge]->property_text().get_value()!="") |
547 { |
570 { |
548 delete(canvasentrywidget); |
571 //activate the general variable for it |
|
572 active_edge=clicked_edge; |
|
573 //delete visible widget if there is |
|
574 if(canvasentrywidget) |
|
575 { |
|
576 delete(canvasentrywidget); |
|
577 } |
|
578 |
|
579 //initialize the entry |
|
580 entrywidget.show(); |
|
581 |
|
582 //fill in the correct value |
|
583 entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value()); |
|
584 |
|
585 //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc |
|
586 xy<double> entry_coos; |
|
587 entry_coos.x=(edgetextmap[active_edge])->property_x().get_value(); |
|
588 entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2; |
|
589 entry_coos.y=(edgetextmap[active_edge])->property_y().get_value(); |
|
590 entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2; |
|
591 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); |
|
592 canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5); |
|
593 canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5); |
549 } |
594 } |
550 entrywidget.show(); |
|
551 entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value()); |
|
552 xy<double> entry_coos; |
|
553 entry_coos.x=(edgetextmap[active_edge])->property_x().get_value(); |
|
554 entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2; |
|
555 entry_coos.y=(edgetextmap[active_edge])->property_y().get_value(); |
|
556 entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2; |
|
557 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); |
|
558 canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5); |
|
559 canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5); |
|
560 } |
595 } |
561 } |
596 } |
|
597 //if it was not an edge... |
562 else |
598 else |
563 { |
599 { |
|
600 //In this case the click did not happen on an edge |
|
601 //if there is visible entry we save the value in it |
|
602 //we pretend like an Enter was presse din the Entry widget |
564 GdkEvent * generated=new GdkEvent(); |
603 GdkEvent * generated=new GdkEvent(); |
565 generated->type=GDK_KEY_PRESS; |
604 generated->type=GDK_KEY_PRESS; |
566 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
605 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
567 entryWidgetChangeHandler(generated); |
606 entryWidgetChangeHandler(generated); |
568 } |
607 } |
594 } |
634 } |
595 |
635 |
596 break; |
636 break; |
597 } |
637 } |
598 case GDK_BUTTON_PRESS: |
638 case GDK_BUTTON_PRESS: |
|
639 //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. |
599 { |
640 { |
|
641 //find the activated item |
600 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
642 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
601 active_item=(get_item_at(clicked_x, clicked_y)); |
643 active_item=(get_item_at(clicked_x, clicked_y)); |
|
644 |
|
645 //determine, whether it was a node |
602 Graph::NodeIt clicked_node=INVALID; |
646 Graph::NodeIt clicked_node=INVALID; |
603 for (NodeIt i(g); i!=INVALID; ++i) |
647 for (NodeIt i(g); i!=INVALID; ++i) |
604 { |
648 { |
605 if(nodesmap[i]==active_item) |
649 if(nodesmap[i]==active_item) |
606 { |
650 { |
607 clicked_node=i; |
651 clicked_node=i; |
608 } |
652 } |
609 } |
653 } |
|
654 |
|
655 //if it was really an edge... |
610 if(clicked_node!=INVALID) |
656 if(clicked_node!=INVALID) |
611 { |
657 { |
612 //If there is already edited edge, it has to be saved first |
658 //If there is already edited edge, it has to be saved first |
613 if(entrywidget.is_visible()) |
659 if(entrywidget.is_visible()) |
614 { |
660 { |
618 entryWidgetChangeHandler(generated); |
664 entryWidgetChangeHandler(generated); |
619 } |
665 } |
620 //If the previous value could be saved, we can go further, otherwise not |
666 //If the previous value could be saved, we can go further, otherwise not |
621 if(!entrywidget.is_visible()) |
667 if(!entrywidget.is_visible()) |
622 { |
668 { |
623 |
669 //and there is activated map |
624 if(nodetextmap[clicked_node]->property_text().get_value()!="") |
670 if(nodetextmap[clicked_node]->property_text().get_value()!="") |
625 { |
671 { |
|
672 //activate the general variable for it |
626 active_node=clicked_node; |
673 active_node=clicked_node; |
|
674 //delete visible widget if there is |
627 if(canvasentrywidget) |
675 if(canvasentrywidget) |
628 { |
676 { |
629 delete(canvasentrywidget); |
677 delete(canvasentrywidget); |
630 } |
678 } |
|
679 |
|
680 //initialize the entry |
631 entrywidget.show(); |
681 entrywidget.show(); |
|
682 |
|
683 //fill in the correct value |
632 entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); |
684 entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); |
|
685 |
|
686 //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc |
633 xy<double> entry_coos; |
687 xy<double> entry_coos; |
634 entry_coos.x=(nodetextmap[active_node])->property_x().get_value(); |
688 entry_coos.x=(nodetextmap[active_node])->property_x().get_value(); |
635 entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2; |
689 entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2; |
636 entry_coos.y=(nodetextmap[active_node])->property_y().get_value(); |
690 entry_coos.y=(nodetextmap[active_node])->property_y().get_value(); |
637 entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2; |
691 entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2; |
639 canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5); |
693 canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5); |
640 canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5); |
694 canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5); |
641 } |
695 } |
642 } |
696 } |
643 } |
697 } |
|
698 //if it was not an edge... |
644 else |
699 else |
645 { |
700 { |
|
701 //In this case the click did not happen on an edge |
|
702 //if there is visible entry we save the value in it |
|
703 //we pretend like an Enter was presse din the Entry widget |
646 GdkEvent * generated=new GdkEvent(); |
704 GdkEvent * generated=new GdkEvent(); |
647 generated->type=GDK_KEY_PRESS; |
705 generated->type=GDK_KEY_PRESS; |
648 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
706 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
649 entryWidgetChangeHandler(generated); |
707 entryWidgetChangeHandler(generated); |
650 } |
708 } |
691 mapvalue_ch[i]=mapvalue_str[i]; |
752 mapvalue_ch[i]=mapvalue_str[i]; |
692 } |
753 } |
693 |
754 |
694 double mapvalue_d=atof(mapvalue_ch); |
755 double mapvalue_d=atof(mapvalue_ch); |
695 |
756 |
696 // double double_map_fract_value=0; |
757 //if the text in the entry was correct |
697 // double double_map_value=0; |
|
698 // int offset=0; |
|
699 // int found_letter=0; |
|
700 //converting text to double |
|
701 // for(int i=0;i<(int)(mapvalue.length());i++) |
|
702 // { |
|
703 // if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.')) |
|
704 // { |
|
705 // if(mapvalue[i]=='.') |
|
706 // { |
|
707 // //for calculating non-integer part of double we step backward from the end |
|
708 // //after each step the number will be divided by ten, and the new value will be added |
|
709 // //to step backward from the end until the point the actual character of the string is the following: |
|
710 // // mapvalue.length()-(i-position_of_point) |
|
711 // //if i was the number of the first character after the decimal point the selected character will be the last |
|
712 // //if i was the number of the last character, the selected character will be the first after the decimal point |
|
713 // offset=mapvalue.length()+i; |
|
714 // } |
|
715 // else |
|
716 // { |
|
717 // if(!offset) |
|
718 // { |
|
719 // double_map_value=10*double_map_value+mapvalue[i]-'0'; |
|
720 // } |
|
721 // else |
|
722 // { |
|
723 // double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10; |
|
724 // } |
|
725 // } |
|
726 // } |
|
727 // else |
|
728 // { |
|
729 // found_letter++; |
|
730 // continue; |
|
731 // } |
|
732 // } |
|
733 |
|
734 if((point_num<=1)&&(valid_double)) |
758 if((point_num<=1)&&(valid_double)) |
735 { |
759 { |
|
760 //save the value to the correct place |
736 switch(actual_tool) |
761 switch(actual_tool) |
737 { |
762 { |
738 case EDGE_MAP_EDIT: |
763 case EDGE_MAP_EDIT: |
739 edgetextmap[active_edge]->property_text().set_value(mapvalue_str); |
764 edgetextmap[active_edge]->property_text().set_value(mapvalue_str); |
740 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d; |
765 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d; |
824 |
850 |
825 } |
851 } |
826 |
852 |
827 void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
853 void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
828 { |
854 { |
|
855 //create the new map |
829 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value); |
856 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value); |
830 mapstorage.addEdgeMap(mapname,emptr); |
857 mapstorage.addEdgeMap(mapname,emptr); |
|
858 |
|
859 //add it to the list of the displayable maps |
831 mapwin->registerNewEdgeMap(mapname); |
860 mapwin->registerNewEdgeMap(mapname); |
|
861 |
|
862 //display it |
832 changeEdgeText(mapname); |
863 changeEdgeText(mapname); |
833 } |
864 } |
834 |
865 |
835 void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
866 void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
836 { |
867 { |
|
868 //create the new map |
837 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value); |
869 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value); |
838 mapstorage.addNodeMap(mapname,emptr); |
870 mapstorage.addNodeMap(mapname,emptr); |
|
871 |
|
872 //add it to the list of the displayable maps |
839 mapwin->registerNewNodeMap(mapname); |
873 mapwin->registerNewNodeMap(mapname); |
|
874 |
|
875 //display it |
840 changeNodeText(mapname); |
876 changeNodeText(mapname); |
841 } |
877 } |
842 |
878 |