668 entrywidget.hide(); |
668 entrywidget.hide(); |
669 break; |
669 break; |
670 case GDK_KP_Enter: |
670 case GDK_KP_Enter: |
671 case GDK_Return: |
671 case GDK_Return: |
672 { |
672 { |
673 Glib::ustring mapvalue = entrywidget.get_text(); |
673 bool valid_double=true; |
674 |
674 int point_num=0; |
675 double double_map_fract_value=0; |
675 Glib::ustring mapvalue_str = entrywidget.get_text(); |
676 double double_map_value=0; |
676 |
677 int offset=0; |
677 char * mapvalue_ch=new char [mapvalue_str.length()]; |
678 int found_letter=0; |
678 for(int i=0;i<(int)(mapvalue_str.length());i++) |
679 //converting text to double |
|
680 for(int i=0;i<(int)(mapvalue.length());i++) |
|
681 { |
679 { |
682 if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.')) |
680 if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.')) |
683 { |
681 { |
684 if(mapvalue[i]=='.') |
682 valid_double=false; |
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 } |
683 } |
706 else |
684 else |
707 { |
685 { |
708 found_letter++; |
686 if(mapvalue_str[i]=='.') |
709 continue; |
687 { |
|
688 point_num++; |
|
689 } |
710 } |
690 } |
|
691 mapvalue_ch[i]=mapvalue_str[i]; |
711 } |
692 } |
712 |
693 |
713 if(!found_letter) |
694 double mapvalue_d=atof(mapvalue_ch); |
|
695 |
|
696 // double double_map_fract_value=0; |
|
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)) |
714 { |
735 { |
715 switch(actual_tool) |
736 switch(actual_tool) |
716 { |
737 { |
717 case EDGE_MAP_EDIT: |
738 case EDGE_MAP_EDIT: |
718 edgetextmap[active_edge]->property_text().set_value(mapvalue); |
739 edgetextmap[active_edge]->property_text().set_value(mapvalue_str); |
719 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=double_map_value+double_map_fract_value; |
740 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d; |
720 break; |
741 break; |
721 case NODE_MAP_EDIT: |
742 case NODE_MAP_EDIT: |
722 nodetextmap[active_node]->property_text().set_value(mapvalue); |
743 nodetextmap[active_node]->property_text().set_value(mapvalue_str); |
723 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=double_map_value+double_map_fract_value; |
744 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d; |
724 break; |
745 break; |
725 default: |
746 default: |
726 break; |
747 break; |
727 } |
748 } |
728 entrywidget.hide(); |
749 entrywidget.hide(); |
801 } |
822 } |
802 } |
823 } |
803 |
824 |
804 } |
825 } |
805 |
826 |
806 void GraphDisplayerCanvas::addNewEdgeMap() |
827 void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
807 { |
828 { |
808 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,20); |
829 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value); |
809 mapstorage.addEdgeMap("NewEdgeMap",emptr); |
830 mapstorage.addEdgeMap(mapname,emptr); |
810 mapwin->registerNewEdgeMap("NewEdgeMap"); |
831 mapwin->registerNewEdgeMap(mapname); |
811 changeEdgeText("NewEdgeMap"); |
832 changeEdgeText(mapname); |
812 } |
833 } |
813 |
834 |
814 void GraphDisplayerCanvas::addNewNodeMap() |
835 void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
815 { |
836 { |
816 std::cout << "Add New NodeMap is not yet implemented." << std::endl; |
837 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value); |
817 } |
838 mapstorage.addNodeMap(mapname,emptr); |
818 |
839 mapwin->registerNewNodeMap(mapname); |
|
840 changeNodeText(mapname); |
|
841 } |
|
842 |