gui/new_map_win.cc
changeset 1888 eed01ce27087
parent 1887 22fdc00894aa
     1.1 --- a/gui/new_map_win.cc	Mon Jan 09 12:41:06 2006 +0000
     1.2 +++ b/gui/new_map_win.cc	Tue Jan 10 15:15:57 2006 +0000
     1.3 @@ -72,79 +72,100 @@
     1.4  
     1.5        //get and formulate text
     1.6        std::string def_val_str=default_value.get_text();
     1.7 -      std::string polishform=string2Polishform(def_val_str,edge.get_active());
     1.8 +
     1.9 +      bool only_nums=true;
    1.10 +      for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
    1.11 +	{
    1.12 +	  if( def_val_str[i]<'0' || def_val_str[i]>'9' )
    1.13 +	    {
    1.14 +	      only_nums=false;
    1.15 +	    }
    1.16 +	}
    1.17 +      std::string polishform;
    1.18 +
    1.19 +      if(only_nums)
    1.20 +	{
    1.21 +	  def_val=atof(def_val_str.c_str());
    1.22 +	}
    1.23 +      else
    1.24 +	{
    1.25 +	  polishform=string2Polishform(def_val_str,edge.get_active());
    1.26 +	}
    1.27  
    1.28        //get name of text
    1.29        std::string mapname=name.get_text();
    1.30 -
    1.31 -      if(!mapname.empty()&&!polishform.empty())
    1.32 +      
    1.33 +      if(!mapname.empty()&&(!polishform.empty()||only_nums))
    1.34  	{
    1.35  	  int abortion=0;
    1.36  	  if(edge.get_active())
    1.37  	    {
    1.38  	      //create the new map
    1.39 -	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
    1.40 -
    1.41 -	      std::stack<double> polishstack;
    1.42 -  
    1.43 -	      for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    1.44 +	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
    1.45 +	      
    1.46 +	      if(!only_nums)
    1.47  		{
    1.48 -		  for(int i=0;i<(int)polishform.size();i++)
    1.49 +		  std::stack<double> polishstack;
    1.50 +		  
    1.51 +		  for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    1.52  		    {
    1.53 -		      double op1, op2;
    1.54 -		      bool operation=true;
    1.55 -		      switch(polishform[i])
    1.56 +		      for(int i=0;i<(int)polishform.size();i++)
    1.57  			{
    1.58 -			case '+':
    1.59 -			case '-':
    1.60 -			case '/':
    1.61 -			case '*':
    1.62 -			  op1=polishstack.top();
    1.63 -			  polishstack.pop();
    1.64 -			  op2=polishstack.top();
    1.65 -			  polishstack.pop();
    1.66 -			  break;
    1.67 -			default:
    1.68 -			  //substitute variable
    1.69 -			  std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
    1.70 -			  bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
    1.71 -			  if(itisvar)
    1.72 -			    {
    1.73 -			      polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    1.74 -			    }
    1.75 -			  else
    1.76 -			    {
    1.77 -			      polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    1.78 -			    }
    1.79 -			  operation=false;
    1.80 -			  break;
    1.81 -			}
    1.82 -		      if(operation)
    1.83 -			{
    1.84 -			  double res;
    1.85 +			  double op1=0, op2=0;
    1.86 +			  bool operation=true;
    1.87  			  switch(polishform[i])
    1.88  			    {
    1.89  			    case '+':
    1.90 -			      res=op1+op2;
    1.91 -			      break;
    1.92  			    case '-':
    1.93 -			      res=op2-op1;
    1.94 -			      break;
    1.95  			    case '/':
    1.96 -			      res=op2/op1;
    1.97 -			      break;
    1.98  			    case '*':
    1.99 -			      res=op1*op2;
   1.100 +			      op1=polishstack.top();
   1.101 +			      polishstack.pop();
   1.102 +			      op2=polishstack.top();
   1.103 +			      polishstack.pop();
   1.104  			      break;
   1.105  			    default:
   1.106 -			      std::cout << "How could we get here?" << std::endl;
   1.107 +			      //substitute variable
   1.108 +			      std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
   1.109 +			      bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   1.110 +			      if(itisvar)
   1.111 +				{
   1.112 +				  polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.113 +				}
   1.114 +			      else
   1.115 +				{
   1.116 +				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.117 +				}
   1.118 +			      operation=false;
   1.119  			      break;
   1.120  			    }
   1.121 -			  polishstack.push(res);
   1.122 -			}
   1.123 -		    }
   1.124 -		  (*emptr)[k]=polishstack.top(); 
   1.125 -		}
   1.126 +			  if(operation)
   1.127 +			    {
   1.128 +			      double res;
   1.129 +			      switch(polishform[i])
   1.130 +				{
   1.131 +				case '+':
   1.132 +				  res=op1+op2;
   1.133 +				  break;
   1.134 +				case '-':
   1.135 +				  res=op2-op1;
   1.136 +				  break;
   1.137 +				case '/':
   1.138 +				  res=op2/op1;
   1.139 +				  break;
   1.140 +				case '*':
   1.141 +				  res=op1*op2;
   1.142 +				  break;
   1.143 +				default:
   1.144 +				  std::cout << "How could we get here?" << std::endl;
   1.145 +				  break;
   1.146 +				}
   1.147 +			      polishstack.push(res);
   1.148 +			    }
   1.149 +			}//foreach letter in polishform
   1.150 +		      (*emptr)[k]=polishstack.top(); 
   1.151 +		    }//foreach edge
   1.152 +		}//!only_nums
   1.153  
   1.154  	      //if addition was not successful addEdgeMap returns one.
   1.155  	      //cause can be that there is already a map named like the new one
   1.156 @@ -163,68 +184,70 @@
   1.157  	  else //!edge.get_active()
   1.158  	    {
   1.159  	      //create the new map
   1.160 -	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
   1.161 +	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
   1.162  
   1.163 -	      std::stack<double> polishstack;
   1.164 +	      if(!only_nums)
   1.165 +		{
   1.166 +		  std::stack<double> polishstack;
   1.167    
   1.168 -	      for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   1.169 -		{
   1.170 -		  for(int i=0;i<(int)polishform.size();i++)
   1.171 +		  for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   1.172  		    {
   1.173 -		      double op1, op2;
   1.174 -		      bool operation=true;
   1.175 -		      switch(polishform[i])
   1.176 +		      for(int i=0;i<(int)polishform.size();i++)
   1.177  			{
   1.178 -			case '+':
   1.179 -			case '-':
   1.180 -			case '/':
   1.181 -			case '*':
   1.182 -			  op1=polishstack.top();
   1.183 -			  polishstack.pop();
   1.184 -			  op2=polishstack.top();
   1.185 -			  polishstack.pop();
   1.186 -			  break;
   1.187 -			default:
   1.188 -			  std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
   1.189 -			  bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   1.190 -			  if(itisvar)
   1.191 -			    {
   1.192 -			      polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.193 -			    }
   1.194 -			  else
   1.195 -			    {
   1.196 -			      polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.197 -			    }
   1.198 -			  operation=false;
   1.199 -			  break;
   1.200 -			}
   1.201 -		      if(operation)
   1.202 -			{
   1.203 -			  double res;
   1.204 +			  double op1=0, op2=0;
   1.205 +			  bool operation=true;
   1.206  			  switch(polishform[i])
   1.207  			    {
   1.208  			    case '+':
   1.209 -			      res=op1+op2;
   1.210 -			      break;
   1.211  			    case '-':
   1.212 -			      res=op2-op1;
   1.213 -			      break;
   1.214  			    case '/':
   1.215 -			      res=op2/op1;
   1.216 -			      break;
   1.217  			    case '*':
   1.218 -			      res=op1*op2;
   1.219 +			      op1=polishstack.top();
   1.220 +			      polishstack.pop();
   1.221 +			      op2=polishstack.top();
   1.222 +			      polishstack.pop();
   1.223  			      break;
   1.224  			    default:
   1.225 -			      std::cout << "How could we get here?" << std::endl;
   1.226 +			      std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
   1.227 +			      bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   1.228 +			      if(itisvar)
   1.229 +				{
   1.230 +				  polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.231 +				}
   1.232 +			      else
   1.233 +				{
   1.234 +				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.235 +				}
   1.236 +			      operation=false;
   1.237  			      break;
   1.238  			    }
   1.239 -			  polishstack.push(res);
   1.240 +			  if(operation)
   1.241 +			    {
   1.242 +			      double res;
   1.243 +			      switch(polishform[i])
   1.244 +				{
   1.245 +				case '+':
   1.246 +				  res=op1+op2;
   1.247 +				  break;
   1.248 +				case '-':
   1.249 +				  res=op2-op1;
   1.250 +				  break;
   1.251 +				case '/':
   1.252 +				  res=op2/op1;
   1.253 +				  break;
   1.254 +				case '*':
   1.255 +				  res=op1*op2;
   1.256 +				  break;
   1.257 +				default:
   1.258 +				  std::cout << "How could we get here?" << std::endl;
   1.259 +				  break;
   1.260 +				}
   1.261 +			      polishstack.push(res);
   1.262 +			    }
   1.263  			}
   1.264 +		      (*emptr)[k]=polishstack.top(); 
   1.265  		    }
   1.266 -		  (*emptr)[k]=polishstack.top(); 
   1.267  		}
   1.268 -
   1.269  	      //if addition was not successful addNodeMap returns one.
   1.270  	      //cause can be that there is already a map named like the new one
   1.271  	      if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))