gui/new_map_win.cc
changeset 1990 15fb7a4ea6be
parent 1887 22fdc00894aa
equal deleted inserted replaced
11:1c9a8dfe7244 12:82682dc30cac
    70     {
    70     {
    71       double def_val=0;
    71       double def_val=0;
    72 
    72 
    73       //get and formulate text
    73       //get and formulate text
    74       std::string def_val_str=default_value.get_text();
    74       std::string def_val_str=default_value.get_text();
    75       std::string polishform=string2Polishform(def_val_str,edge.get_active());
    75 
       
    76       bool only_nums=true;
       
    77       for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
       
    78 	{
       
    79 	  if( def_val_str[i]<'0' || def_val_str[i]>'9' )
       
    80 	    {
       
    81 	      only_nums=false;
       
    82 	    }
       
    83 	}
       
    84       std::string polishform;
       
    85 
       
    86       if(only_nums)
       
    87 	{
       
    88 	  def_val=atof(def_val_str.c_str());
       
    89 	}
       
    90       else
       
    91 	{
       
    92 	  polishform=string2Polishform(def_val_str,edge.get_active());
       
    93 	}
    76 
    94 
    77       //get name of text
    95       //get name of text
    78       std::string mapname=name.get_text();
    96       std::string mapname=name.get_text();
    79 
    97       
    80       if(!mapname.empty()&&!polishform.empty())
    98       if(!mapname.empty()&&(!polishform.empty()||only_nums))
    81 	{
    99 	{
    82 	  int abortion=0;
   100 	  int abortion=0;
    83 	  if(edge.get_active())
   101 	  if(edge.get_active())
    84 	    {
   102 	    {
    85 	      //create the new map
   103 	      //create the new map
    86 	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
   104 	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
    87 
   105 	      
    88 	      std::stack<double> polishstack;
   106 	      if(!only_nums)
    89   
   107 		{
    90 	      for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   108 		  std::stack<double> polishstack;
    91 		{
   109 		  
    92 		  for(int i=0;i<(int)polishform.size();i++)
   110 		  for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    93 		    {
   111 		    {
    94 		      double op1, op2;
   112 		      for(int i=0;i<(int)polishform.size();i++)
    95 		      bool operation=true;
       
    96 		      switch(polishform[i])
       
    97 			{
   113 			{
    98 			case '+':
   114 			  double op1=0, op2=0;
    99 			case '-':
   115 			  bool operation=true;
   100 			case '/':
       
   101 			case '*':
       
   102 			  op1=polishstack.top();
       
   103 			  polishstack.pop();
       
   104 			  op2=polishstack.top();
       
   105 			  polishstack.pop();
       
   106 			  break;
       
   107 			default:
       
   108 			  //substitute variable
       
   109 			  std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
       
   110 			  bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
       
   111 			  if(itisvar)
       
   112 			    {
       
   113 			      polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
       
   114 			    }
       
   115 			  else
       
   116 			    {
       
   117 			      polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
       
   118 			    }
       
   119 			  operation=false;
       
   120 			  break;
       
   121 			}
       
   122 		      if(operation)
       
   123 			{
       
   124 			  double res;
       
   125 			  switch(polishform[i])
   116 			  switch(polishform[i])
   126 			    {
   117 			    {
   127 			    case '+':
   118 			    case '+':
   128 			      res=op1+op2;
       
   129 			      break;
       
   130 			    case '-':
   119 			    case '-':
   131 			      res=op2-op1;
       
   132 			      break;
       
   133 			    case '/':
   120 			    case '/':
   134 			      res=op2/op1;
       
   135 			      break;
       
   136 			    case '*':
   121 			    case '*':
   137 			      res=op1*op2;
   122 			      op1=polishstack.top();
       
   123 			      polishstack.pop();
       
   124 			      op2=polishstack.top();
       
   125 			      polishstack.pop();
   138 			      break;
   126 			      break;
   139 			    default:
   127 			    default:
   140 			      std::cout << "How could we get here?" << std::endl;
   128 			      //substitute variable
       
   129 			      std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
       
   130 			      bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
       
   131 			      if(itisvar)
       
   132 				{
       
   133 				  polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
       
   134 				}
       
   135 			      else
       
   136 				{
       
   137 				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
       
   138 				}
       
   139 			      operation=false;
   141 			      break;
   140 			      break;
   142 			    }
   141 			    }
   143 			  polishstack.push(res);
   142 			  if(operation)
   144 			}
   143 			    {
   145 		    }
   144 			      double res;
   146 		  (*emptr)[k]=polishstack.top(); 
   145 			      switch(polishform[i])
   147 		}
   146 				{
       
   147 				case '+':
       
   148 				  res=op1+op2;
       
   149 				  break;
       
   150 				case '-':
       
   151 				  res=op2-op1;
       
   152 				  break;
       
   153 				case '/':
       
   154 				  res=op2/op1;
       
   155 				  break;
       
   156 				case '*':
       
   157 				  res=op1*op2;
       
   158 				  break;
       
   159 				default:
       
   160 				  std::cout << "How could we get here?" << std::endl;
       
   161 				  break;
       
   162 				}
       
   163 			      polishstack.push(res);
       
   164 			    }
       
   165 			}//foreach letter in polishform
       
   166 		      (*emptr)[k]=polishstack.top(); 
       
   167 		    }//foreach edge
       
   168 		}//!only_nums
   148 
   169 
   149 	      //if addition was not successful addEdgeMap returns one.
   170 	      //if addition was not successful addEdgeMap returns one.
   150 	      //cause can be that there is already a map named like the new one
   171 	      //cause can be that there is already a map named like the new one
   151 	      if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
   172 	      if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
   152 		{
   173 		{
   161 	      //gdc.changeEdgeText(mapname);
   182 	      //gdc.changeEdgeText(mapname);
   162 	    }
   183 	    }
   163 	  else //!edge.get_active()
   184 	  else //!edge.get_active()
   164 	    {
   185 	    {
   165 	      //create the new map
   186 	      //create the new map
   166 	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
   187 	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
   167 
   188 
   168 	      std::stack<double> polishstack;
   189 	      if(!only_nums)
       
   190 		{
       
   191 		  std::stack<double> polishstack;
   169   
   192   
   170 	      for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   193 		  for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   171 		{
       
   172 		  for(int i=0;i<(int)polishform.size();i++)
       
   173 		    {
   194 		    {
   174 		      double op1, op2;
   195 		      for(int i=0;i<(int)polishform.size();i++)
   175 		      bool operation=true;
       
   176 		      switch(polishform[i])
       
   177 			{
   196 			{
   178 			case '+':
   197 			  double op1=0, op2=0;
   179 			case '-':
   198 			  bool operation=true;
   180 			case '/':
       
   181 			case '*':
       
   182 			  op1=polishstack.top();
       
   183 			  polishstack.pop();
       
   184 			  op2=polishstack.top();
       
   185 			  polishstack.pop();
       
   186 			  break;
       
   187 			default:
       
   188 			  std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
       
   189 			  bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
       
   190 			  if(itisvar)
       
   191 			    {
       
   192 			      polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
       
   193 			    }
       
   194 			  else
       
   195 			    {
       
   196 			      polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
       
   197 			    }
       
   198 			  operation=false;
       
   199 			  break;
       
   200 			}
       
   201 		      if(operation)
       
   202 			{
       
   203 			  double res;
       
   204 			  switch(polishform[i])
   199 			  switch(polishform[i])
   205 			    {
   200 			    {
   206 			    case '+':
   201 			    case '+':
   207 			      res=op1+op2;
       
   208 			      break;
       
   209 			    case '-':
   202 			    case '-':
   210 			      res=op2-op1;
       
   211 			      break;
       
   212 			    case '/':
   203 			    case '/':
   213 			      res=op2/op1;
       
   214 			      break;
       
   215 			    case '*':
   204 			    case '*':
   216 			      res=op1*op2;
   205 			      op1=polishstack.top();
       
   206 			      polishstack.pop();
       
   207 			      op2=polishstack.top();
       
   208 			      polishstack.pop();
   217 			      break;
   209 			      break;
   218 			    default:
   210 			    default:
   219 			      std::cout << "How could we get here?" << std::endl;
   211 			      std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
       
   212 			      bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
       
   213 			      if(itisvar)
       
   214 				{
       
   215 				  polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
       
   216 				}
       
   217 			      else
       
   218 				{
       
   219 				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
       
   220 				}
       
   221 			      operation=false;
   220 			      break;
   222 			      break;
   221 			    }
   223 			    }
   222 			  polishstack.push(res);
   224 			  if(operation)
       
   225 			    {
       
   226 			      double res;
       
   227 			      switch(polishform[i])
       
   228 				{
       
   229 				case '+':
       
   230 				  res=op1+op2;
       
   231 				  break;
       
   232 				case '-':
       
   233 				  res=op2-op1;
       
   234 				  break;
       
   235 				case '/':
       
   236 				  res=op2/op1;
       
   237 				  break;
       
   238 				case '*':
       
   239 				  res=op1*op2;
       
   240 				  break;
       
   241 				default:
       
   242 				  std::cout << "How could we get here?" << std::endl;
       
   243 				  break;
       
   244 				}
       
   245 			      polishstack.push(res);
       
   246 			    }
   223 			}
   247 			}
       
   248 		      (*emptr)[k]=polishstack.top(); 
   224 		    }
   249 		    }
   225 		  (*emptr)[k]=polishstack.top(); 
   250 		}
   226 		}
       
   227 
       
   228 	      //if addition was not successful addNodeMap returns one.
   251 	      //if addition was not successful addNodeMap returns one.
   229 	      //cause can be that there is already a map named like the new one
   252 	      //cause can be that there is already a map named like the new one
   230 	      if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
   253 	      if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
   231 		{
   254 		{
   232 		  abortion=1;
   255 		  abortion=1;