Sorry for the previous commit, it was not ready yet, but that damned up arrow... So in this new revision string-double and double-string conversion is corrected to a more C++ way. gui
authorhegyi
Wed, 27 Jul 2005 11:19:35 +0000
branchgui
changeset 45199f433eb7cd
parent 44 9a217bdf53a3
child 46 121452cc4096
Sorry for the previous commit, it was not ready yet, but that damned up arrow... So in this new revision string-double and double-string conversion is corrected to a more C++ way.
graph_displayer_canvas-edge.cc
graph_displayer_canvas-event.cc
graph_displayer_canvas-node.cc
     1.1 --- a/graph_displayer_canvas-edge.cc	Wed Jul 27 11:02:51 2005 +0000
     1.2 +++ b/graph_displayer_canvas-edge.cc	Wed Jul 27 11:19:35 2005 +0000
     1.3 @@ -119,37 +119,10 @@
     1.4  	    {
     1.5  	      edgemap_to_edit=mapname;
     1.6  	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
     1.7 -// 	      int length=1;
     1.8 -// 	      //if number is smaller than one, length would be negative, or invalid
     1.9 -// 	      if(number>=1)
    1.10 -// 		{
    1.11 -// 		  length=(int)(floor(log(number)/log(10)))+1;
    1.12 -// 		}
    1.13 -// 	      int maxpos=(int)(pow(10,length-1));
    1.14 -// 	      int strl=length+1+RANGE;
    1.15 -// 	      char * str=new char[strl];
    1.16 -// 	      str[length]='.';
    1.17 -// 	      str[strl]='\0';
    1.18 -      
    1.19 -// 	      for(int j=0;j<strl;j++)
    1.20 -// 		{
    1.21 -// 		  if(j!=length)
    1.22 -// 		    {
    1.23 -// 		      if((number-(int)number)>ALMOST_ONE)
    1.24 -// 			{
    1.25 -// 			  number=round(number);
    1.26 -// 			}
    1.27 -// 		      int digit=(int)(number/maxpos);
    1.28 -// 		      str[j]=(digit+'0');
    1.29 -// 		      number-=digit*maxpos;
    1.30 -// 		      number*=10;
    1.31 -// 		    }
    1.32 -// 		}
    1.33 -//       	      edgetextmap[i]->property_text().set_value(str);
    1.34  
    1.35  	      std::ostringstream ostr;
    1.36  	      ostr << number;
    1.37 -
    1.38 +	      
    1.39        	      edgetextmap[i]->property_text().set_value(ostr.str());
    1.40  	    }
    1.41  	  else
    1.42 @@ -165,34 +138,11 @@
    1.43        if(mapname!="Default")
    1.44  	{
    1.45  	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
    1.46 -	  int length=1;
    1.47 -	  //if number is smaller than one, length would be negative, or invalid
    1.48 -	  if(number>=1)
    1.49 -	    {
    1.50 -	      length=(int)(floor(log(number)/log(10)))+1;
    1.51 -	    }
    1.52 -	  int maxpos=(int)(pow(10,length-1));
    1.53 -	  int strl=length+1+RANGE;
    1.54 -	  char * str=new char[strl];
    1.55 -	  str[length]='.';
    1.56 -	  str[strl]='\0';
    1.57 -      
    1.58 -	  for(int j=0;j<strl;j++)
    1.59 -	    {
    1.60 -	      if(j!=length)
    1.61 -		{
    1.62 -		  if((number-(int)number)>ALMOST_ONE)
    1.63 -		    {
    1.64 -		      number=round(number);
    1.65 -		    }
    1.66 -		  int digit=(int)(number/maxpos);
    1.67 -		  str[j]=(digit+'0');
    1.68 -		  number-=digit*maxpos;
    1.69 -		  number*=10;
    1.70 -		}
    1.71 -	    }
    1.72 -      
    1.73 -	  edgetextmap[edge]->property_text().set_value(str);
    1.74 +
    1.75 +	  std::ostringstream ostr;
    1.76 +	  ostr << number;
    1.77 +	  
    1.78 +	  edgetextmap[edge]->property_text().set_value(ostr.str());
    1.79  	}
    1.80        else
    1.81  	{
     2.1 --- a/graph_displayer_canvas-event.cc	Wed Jul 27 11:02:51 2005 +0000
     2.2 +++ b/graph_displayer_canvas-event.cc	Wed Jul 27 11:19:35 2005 +0000
     2.3 @@ -751,21 +751,25 @@
     2.4  		      }
     2.5  		    mapvalue_ch[i]=mapvalue_str[i];
     2.6  		  }
     2.7 -  
     2.8 -		double mapvalue_d=atof(mapvalue_ch);
     2.9 -
    2.10 +  	      
    2.11  		//if the text in the entry was correct
    2.12  		if((point_num<=1)&&(valid_double))
    2.13  		  {
    2.14 +		    double mapvalue_d=atof(mapvalue_ch);
    2.15 +
    2.16 +		    //reconvert the double to string for the correct format
    2.17 +		    std::ostringstream ostr;
    2.18 +		    ostr << mapvalue_d;
    2.19 +
    2.20  		    //save the value to the correct place
    2.21  		    switch(actual_tool)
    2.22  		      {
    2.23  		      case EDGE_MAP_EDIT:
    2.24 -			edgetextmap[active_edge]->property_text().set_value(mapvalue_str);
    2.25 +			edgetextmap[active_edge]->property_text().set_value(ostr.str());
    2.26  			(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
    2.27  			break;
    2.28  		      case NODE_MAP_EDIT:
    2.29 -			nodetextmap[active_node]->property_text().set_value(mapvalue_str);
    2.30 +			nodetextmap[active_node]->property_text().set_value(ostr.str());
    2.31  			(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
    2.32  			break;
    2.33  		      default:
     3.1 --- a/graph_displayer_canvas-node.cc	Wed Jul 27 11:02:51 2005 +0000
     3.2 +++ b/graph_displayer_canvas-node.cc	Wed Jul 27 11:19:35 2005 +0000
     3.3 @@ -149,37 +149,11 @@
     3.4  	    {
     3.5  	      nodemap_to_edit=mapname;
     3.6  	      double number=(*actual_map)[i];
     3.7 -	      int length=1;
     3.8 -	      //if number is smaller than one, length would be negative, or invalid
     3.9 -	      if(number>=1)
    3.10 -		{
    3.11 -		  length=(int)(floor(log(number)/log(10)))+1;
    3.12 -		}
    3.13 -	      int maxpos=(int)(pow(10,length-1));
    3.14 -	      int strl=length+1+RANGE;
    3.15 -	      char * str=new char[strl];
    3.16 -	      str[length]='.';
    3.17 -	      str[strl]='\0';
    3.18 -      
    3.19 -	      for(int j=0;j<strl;j++)
    3.20 -		{
    3.21 -		  if(j!=length)
    3.22 -		    {
    3.23 -//  		      std::cout << (number) << "-" << (int)number << "=" << (number)-(int)number << std::endl;
    3.24 -		      if((number-(int)number)>ALMOST_ONE)
    3.25 -			{
    3.26 -// 			  std::cout<<"rounding: " <<number<<std::endl;
    3.27 -			  number=round(number);
    3.28 -			}
    3.29 - 		      int digit=(int)(number/maxpos);
    3.30 -// 		      std::cout << number << "/" << maxpos << "=" << digit << std::endl;
    3.31 -		      str[j]=(digit+'0');
    3.32 -		      number-=digit*maxpos;
    3.33 -		      number*=10;
    3.34 -		    }
    3.35 -		}
    3.36 -      
    3.37 -	      nodetextmap[i]->property_text().set_value(str);
    3.38 +
    3.39 +	      std::ostringstream ostr;
    3.40 +	      ostr << number;
    3.41 +	      
    3.42 +      	      nodetextmap[i]->property_text().set_value(ostr.str());
    3.43  	    }
    3.44  	  else
    3.45  	    {
    3.46 @@ -193,34 +167,11 @@
    3.47        if(mapname!="Default")
    3.48  	{
    3.49  	  double number=(*actual_map)[node];
    3.50 -	  int length=1;
    3.51 -	  //if number is smaller than one, length would be negative, or invalid
    3.52 -	  if(number>=1)
    3.53 -	    {
    3.54 -	      length=(int)(floor(log(number)/log(10)))+1;
    3.55 -	    }
    3.56 -	  int maxpos=(int)(pow(10,length-1));
    3.57 -	  int strl=length+1+RANGE;
    3.58 -	  char * str=new char[strl];
    3.59 -	  str[length]='.';
    3.60 -	  str[strl]='\0';
    3.61 -      
    3.62 -	  for(int j=0;j<strl;j++)
    3.63 -	    {
    3.64 -	      if(j!=length)
    3.65 -		{
    3.66 -		  if((number-(int)number)>ALMOST_ONE)
    3.67 -		    {
    3.68 -		      number=round(number);
    3.69 -		    }
    3.70 -		  int digit=(int)(number/maxpos);
    3.71 -		  str[j]=(digit+'0');
    3.72 -		  number-=digit*maxpos;
    3.73 -		  number*=10;
    3.74 -		}
    3.75 -	    }
    3.76 -      
    3.77 -	  nodetextmap[node]->property_text().set_value(str);
    3.78 +
    3.79 +	  std::ostringstream ostr;
    3.80 +	  ostr << number;
    3.81 +	      
    3.82 +	  nodetextmap[node]->property_text().set_value(ostr.str());
    3.83  	}
    3.84        else
    3.85  	{