COIN-OR::LEMON - Graph Library

Changeset 41:06f1f9a8d51f in glemon-0.x for graph_displayer_canvas-event.cc


Ignore:
Timestamp:
07/26/05 23:19:41 (19 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2096
Message:

EdgeMap? and NodeMap? creation is done, at last. Bach 4ever.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r40 r41  
    671671            case GDK_Return:
    672672              {
    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++)
     673                bool valid_double=true;
     674                int point_num=0;
     675                Glib::ustring mapvalue_str = entrywidget.get_text();
     676
     677                char * mapvalue_ch=new char [mapvalue_str.length()];
     678                for(int i=0;i<(int)(mapvalue_str.length());i++)
    681679                  {
    682                     if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.'))
     680                    if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
    683681                      {
    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                           }
     682                        valid_double=false;
    705683                      }
    706684                    else
    707685                      {
    708                         found_letter++;
    709                         continue;
     686                        if(mapvalue_str[i]=='.')
     687                          {
     688                            point_num++;
     689                          }
    710690                      }
     691                    mapvalue_ch[i]=mapvalue_str[i];
    711692                  }
    712 
    713                 if(!found_letter)
     693 
     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))
    714735                  {
    715736                    switch(actual_tool)
    716737                      {
    717738                      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;
     739                        edgetextmap[active_edge]->property_text().set_value(mapvalue_str);
     740                        (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
    720741                        break;
    721742                      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;
     743                        nodetextmap[active_node]->property_text().set_value(mapvalue_str);
     744                        (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
    724745                        break;
    725746                      default:
     
    804825}
    805826
    806 void GraphDisplayerCanvas::addNewEdgeMap()
    807 {
    808   Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,20);
    809   mapstorage.addEdgeMap("NewEdgeMap",emptr);
    810   mapwin->registerNewEdgeMap("NewEdgeMap");
    811   changeEdgeText("NewEdgeMap");
    812 }
    813 
    814 void GraphDisplayerCanvas::addNewNodeMap()
    815 {
    816   std::cout << "Add New NodeMap is not yet implemented." << std::endl;
    817 }
    818 
     827void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
     828{
     829  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
     830  mapstorage.addEdgeMap(mapname,emptr);
     831  mapwin->registerNewEdgeMap(mapname);
     832  changeEdgeText(mapname);
     833}
     834
     835void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
     836{
     837  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
     838  mapstorage.addNodeMap(mapname,emptr);
     839  mapwin->registerNewNodeMap(mapname);
     840  changeNodeText(mapname);
     841}
     842
Note: See TracChangeset for help on using the changeset viewer.