215 active_node=NodeIt(g,g.addNode()); |
224 active_node=NodeIt(g,g.addNode()); |
216 |
225 |
217 //initiating values corresponding to new node in maps |
226 //initiating values corresponding to new node in maps |
218 |
227 |
219 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
228 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
220 |
|
221 target_item=NULL; |
|
222 target_item=get_item_at(clicked_x, clicked_y); |
|
223 |
229 |
224 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
230 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
225 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
231 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
226 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); |
232 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); |
227 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); |
233 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); |
245 break; |
251 break; |
246 } |
252 } |
247 |
253 |
248 //finalize the new node |
254 //finalize the new node |
249 case GDK_BUTTON_RELEASE: |
255 case GDK_BUTTON_RELEASE: |
|
256 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
|
257 |
|
258 active_item->lower_to_bottom(); |
|
259 |
|
260 target_item=NULL; |
|
261 target_item=get_item_at(clicked_x, clicked_y); |
|
262 |
|
263 active_item->raise_to_top(); |
|
264 |
250 isbutton=0; |
265 isbutton=0; |
251 if(!target_item) |
266 if(target_item==active_item) |
252 { |
267 { |
253 //Its appropriate color is given by update. |
268 //Its appropriate color is given by update. |
254 //*active_item << Gnome::Canvas::Properties::fill_color("blue"); |
269 *active_item << Gnome::Canvas::Properties::fill_color("blue"); |
255 } |
270 } |
256 else |
271 else |
257 { |
272 { |
258 //In this case the given color has to be overwritten, because the noe covers an other item. |
273 //In this case the given color has to be overwritten, because the noe covers an other item. |
259 *active_item << Gnome::Canvas::Properties::fill_color("lightblue"); |
274 *active_item << Gnome::Canvas::Properties::fill_color("lightblue"); |
566 return false; |
574 return false; |
567 } |
575 } |
568 |
576 |
569 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e) |
577 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e) |
570 { |
578 { |
571 e=e; |
579 switch(e->type) |
572 return false; |
580 { |
|
581 case GDK_KEY_PRESS: |
|
582 { |
|
583 switch(((GdkEventKey*)e)->keyval) |
|
584 { |
|
585 case GDK_Escape: |
|
586 entrywidget.hide(); |
|
587 break; |
|
588 case GDK_Return: |
|
589 case GDK_KP_Enter: |
|
590 entrywidget.hide(); |
|
591 break; |
|
592 default: |
|
593 break; |
|
594 } |
|
595 |
|
596 break; |
|
597 } |
|
598 case GDK_BUTTON_PRESS: |
|
599 { |
|
600 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
|
601 active_item=(get_item_at(clicked_x, clicked_y)); |
|
602 Graph::NodeIt clicked_node=INVALID; |
|
603 for (NodeIt i(g); i!=INVALID; ++i) |
|
604 { |
|
605 if(nodesmap[i]==active_item) |
|
606 { |
|
607 clicked_node=i; |
|
608 } |
|
609 } |
|
610 if(clicked_node!=INVALID) |
|
611 { |
|
612 //If there is already edited edge, it has to be saved first |
|
613 if(entrywidget.is_visible()) |
|
614 { |
|
615 GdkEvent * generated=new GdkEvent(); |
|
616 generated->type=GDK_KEY_PRESS; |
|
617 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
|
618 entryWidgetChangeHandler(generated); |
|
619 } |
|
620 //If the previous value could be saved, we can go further, otherwise not |
|
621 if(!entrywidget.is_visible()) |
|
622 { |
|
623 |
|
624 if(nodetextmap[clicked_node]->property_text().get_value()!="") |
|
625 { |
|
626 active_node=clicked_node; |
|
627 if(canvasentrywidget) |
|
628 { |
|
629 delete(canvasentrywidget); |
|
630 } |
|
631 entrywidget.show(); |
|
632 entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); |
|
633 xy<double> entry_coos; |
|
634 entry_coos.x=(nodetextmap[active_node])->property_x().get_value(); |
|
635 entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2; |
|
636 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; |
|
638 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); |
|
639 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); |
|
641 } |
|
642 } |
|
643 } |
|
644 else |
|
645 { |
|
646 GdkEvent * generated=new GdkEvent(); |
|
647 generated->type=GDK_KEY_PRESS; |
|
648 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; |
|
649 entryWidgetChangeHandler(generated); |
|
650 } |
|
651 break; |
|
652 } |
|
653 default: |
|
654 break; |
|
655 } |
|
656 return false; |
573 } |
657 } |
574 |
658 |
575 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e) |
659 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e) |
576 { |
660 { |
577 Glib::ustring mapvalue = entrywidget.get_text(); |
661 if(entrywidget.is_visible()) |
578 std::cout << mapvalue << std::endl; |
662 { |
579 e=e; |
663 if(e->type==GDK_KEY_PRESS) |
|
664 { |
|
665 switch(((GdkEventKey*)e)->keyval) |
|
666 { |
|
667 case GDK_Escape: |
|
668 entrywidget.hide(); |
|
669 break; |
|
670 case GDK_KP_Enter: |
|
671 case GDK_Return: |
|
672 { |
|
673 Glib::ustring mapvalue = entrywidget.get_text(); |
|
674 |
|
675 double double_map_fract_value=0; |
|
676 double double_map_value=0; |
|
677 int offset=0; |
|
678 int found_letter=0; |
|
679 //converting text to double |
|
680 for(int i=0;i<(int)(mapvalue.length());i++) |
|
681 { |
|
682 if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.')) |
|
683 { |
|
684 if(mapvalue[i]=='.') |
|
685 { |
|
686 //for calculating non-integer part of double we step backward from the end |
|
687 //after each step the number will be divided by ten, and the new value will be added |
|
688 //to step backward from the end until the point the actual character of the string is the following: |
|
689 // mapvalue.length()-(i-position_of_point) |
|
690 //if i was the number of the first character after the decimal point the selected character will be the last |
|
691 //if i was the number of the last character, the selected character will be the first after the decimal point |
|
692 offset=mapvalue.length()+i; |
|
693 } |
|
694 else |
|
695 { |
|
696 if(!offset) |
|
697 { |
|
698 double_map_value=10*double_map_value+mapvalue[i]-'0'; |
|
699 } |
|
700 else |
|
701 { |
|
702 double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10; |
|
703 } |
|
704 } |
|
705 } |
|
706 else |
|
707 { |
|
708 found_letter++; |
|
709 continue; |
|
710 } |
|
711 } |
|
712 |
|
713 if(!found_letter) |
|
714 { |
|
715 switch(actual_tool) |
|
716 { |
|
717 case EDGE_MAP_EDIT: |
|
718 edgetextmap[active_edge]->property_text().set_value(mapvalue); |
|
719 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=double_map_value+double_map_fract_value; |
|
720 break; |
|
721 case NODE_MAP_EDIT: |
|
722 nodetextmap[active_node]->property_text().set_value(mapvalue); |
|
723 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=double_map_value+double_map_fract_value; |
|
724 break; |
|
725 default: |
|
726 break; |
|
727 } |
|
728 entrywidget.hide(); |
|
729 } |
|
730 else |
|
731 { |
|
732 std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl; |
|
733 } |
|
734 |
|
735 break; |
|
736 } |
|
737 default: |
|
738 break; |
|
739 } |
|
740 } |
|
741 } |
580 return false; |
742 return false; |
581 } |
743 } |
582 |
744 |
583 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete) |
745 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete) |
584 { |
746 { |
602 } |
764 } |
603 |
765 |
604 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
766 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
605 { |
767 { |
606 new_place+=(xy<double>(10,10)); |
768 new_place+=(xy<double>(10,10)); |
607 edgetextmap[active_edge]->property_x().set_value(new_place.x); |
769 edgetextmap[forming_edge]->property_x().set_value(new_place.x); |
608 edgetextmap[active_edge]->property_y().set_value(new_place.y); |
770 edgetextmap[forming_edge]->property_y().set_value(new_place.y); |
609 } |
771 } |
610 |
772 |
611 void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on) |
773 void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on) |
612 { |
774 { |
613 if(on) |
775 if(on) |
614 { |
776 { |
615 if(active_edge!=INVALID) |
777 if(forming_edge!=INVALID) |
616 { |
778 { |
617 std::cout << "ERROR!!!! Valid edge found!" << std::endl; |
779 std::cout << "ERROR!!!! Valid edge found!" << std::endl; |
618 } |
780 } |
619 else |
781 else |
620 { |
782 { |
621 for (EdgeIt i(g); i!=INVALID; ++i) |
783 for (EdgeIt i(g); i!=INVALID; ++i) |
622 { |
784 { |
623 if(edgesmap[i]==active_bre) |
785 if(edgesmap[i]==active_bre) |
624 { |
786 { |
625 active_edge=i; |
787 forming_edge=i; |
626 } |
788 } |
627 } |
789 } |
628 } |
790 } |
629 } |
791 } |
630 else |
792 else |
631 { |
793 { |
632 if(active_edge!=INVALID) |
794 if(forming_edge!=INVALID) |
633 { |
795 { |
634 active_edge=INVALID; |
796 forming_edge=INVALID; |
635 } |
797 } |
636 else |
798 else |
637 { |
799 { |
638 std::cout << "ERROR!!!! Invalid edge found!" << std::endl; |
800 std::cout << "ERROR!!!! Invalid edge found!" << std::endl; |
639 } |
801 } |