new_map_win.cc
changeset 201 879e47e5b731
parent 194 6b2b718420eb
     1.1 --- a/new_map_win.cc	Wed May 02 20:33:58 2007 +0000
     1.2 +++ b/new_map_win.cc	Wed Jan 02 21:03:09 2008 +0000
     1.3 @@ -29,7 +29,7 @@
     1.4    return true;
     1.5  }
     1.6  
     1.7 -NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap")
     1.8 +NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode, MapType type):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap"),map_type(type)
     1.9  {
    1.10    set_default_size(200, 50);
    1.11  
    1.12 @@ -38,7 +38,7 @@
    1.13    Gtk::VBox * vbox=get_vbox();
    1.14  
    1.15    //entries
    1.16 -  table=new Gtk::Table(3, 2, false);
    1.17 +  table=new Gtk::Table(5, 2, false);
    1.18  
    1.19    label=new Gtk::Label;
    1.20    label->set_text("Name of new map:");
    1.21 @@ -47,33 +47,45 @@
    1.22    (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.23    (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.24  
    1.25 +  lblType.set_label("Element type:");
    1.26 +  if (map_type & NUM)
    1.27 +    cbType.append_text("Numeric");
    1.28 +  if (map_type & STR)
    1.29 +    cbType.append_text("String");
    1.30 +  cbType.set_active(0);
    1.31 +
    1.32 +  (*table).attach(lblType,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.33 +  (*table).attach(cbType, 1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.34 +
    1.35    label=new Gtk::Label;
    1.36    label->set_text("Default value in the map:");
    1.37    default_value.set_text("0");
    1.38  
    1.39 -  (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.40 -  (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.41 +  (*table).attach(*label,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.42 +  (*table).attach(default_value,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.43  
    1.44    //node vs. edge map selector
    1.45    Gtk::RadioButton::Group group = node.get_group();
    1.46    edge.set_group(group);
    1.47 -  
    1.48 +
    1.49    if(edgenode)
    1.50 +  {
    1.51 +    (*table).attach(node,0,1,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.52 +    (*table).attach(edge,1,2,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.53 +  }
    1.54 +  else
    1.55 +  {
    1.56 +    if(itisedge)
    1.57      {
    1.58 -      (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.59 -      (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.60 +      edge.set_active();
    1.61      }
    1.62 -  else
    1.63 +    else
    1.64      {
    1.65 -      if(itisedge)
    1.66 -	{
    1.67 -	  edge.set_active();
    1.68 -	}
    1.69 -      else
    1.70 -	{
    1.71 -	  node.set_active();
    1.72 -	}
    1.73 +      node.set_active();
    1.74      }
    1.75 +  }
    1.76 +
    1.77 +  (*table).attach(lblErrorMsg,0,2,4,5,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.78  
    1.79    vbox->pack_start(*table);
    1.80  
    1.81 @@ -84,214 +96,242 @@
    1.82  
    1.83  }
    1.84  
    1.85 +void NewMapWin::setErrorMsg(const Glib::ustring& msg)
    1.86 +{
    1.87 +  lblErrorMsg.set_markup("<i><small>" + msg + "</small></i>");
    1.88 +}
    1.89 +
    1.90 +std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform, bool itisedge)
    1.91 +{
    1.92 +  MapStorage& ms = *mytab.mapstorage;
    1.93 +
    1.94 +  std::vector<double>* ret = new std::vector<double>;
    1.95 +  std::stack<double> polishstack;
    1.96 +
    1.97 +  if (itisedge)
    1.98 +  {
    1.99 +    for(EdgeIt k(ms.graph); k!=INVALID; ++k)
   1.100 +    {
   1.101 +      for(int i=0;i<(int)polishform.size();i++)
   1.102 +      {
   1.103 +        double op1=0, op2=0;
   1.104 +        bool operation=true;
   1.105 +        switch(polishform[i])
   1.106 +        {
   1.107 +          case '+':
   1.108 +          case '-':
   1.109 +          case '/':
   1.110 +          case '*':
   1.111 +            op1=polishstack.top();
   1.112 +            polishstack.pop();
   1.113 +            op2=polishstack.top();
   1.114 +            polishstack.pop();
   1.115 +            break;
   1.116 +          default:
   1.117 +            //substitute variable
   1.118 +            std::vector<std::string> maps = ms.getEdgeMapList(NUM);
   1.119 +            bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
   1.120 +            if(itisvar)
   1.121 +            {
   1.122 +              polishstack.push(ms.get(ch2var[ polishform[i] ], k));
   1.123 +            }
   1.124 +            else
   1.125 +            {
   1.126 +              polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.127 +            }
   1.128 +            operation=false;
   1.129 +            break;
   1.130 +        }
   1.131 +        if(operation)
   1.132 +        {
   1.133 +          double res;
   1.134 +          switch(polishform[i])
   1.135 +          {
   1.136 +            case '+':
   1.137 +              res=op1+op2;
   1.138 +              break;
   1.139 +            case '-':
   1.140 +              res=op2-op1;
   1.141 +              break;
   1.142 +            case '/':
   1.143 +              res=op2/op1;
   1.144 +              break;
   1.145 +            case '*':
   1.146 +              res=op1*op2;
   1.147 +              break;
   1.148 +            default:
   1.149 +              std::cout << "How could we get here?" << std::endl;
   1.150 +              break;
   1.151 +          }
   1.152 +          polishstack.push(res);
   1.153 +        }
   1.154 +      }//foreach letter in polishform
   1.155 +      ret->push_back(polishstack.top());
   1.156 +    }//foreach edge
   1.157 +  }
   1.158 +  else
   1.159 +  {
   1.160 +    for(NodeIt k(ms.graph); k!=INVALID; ++k)
   1.161 +    {
   1.162 +      for(int i=0;i<(int)polishform.size();i++)
   1.163 +      {
   1.164 +        double op1=0, op2=0;
   1.165 +        bool operation=true;
   1.166 +        switch(polishform[i])
   1.167 +        {
   1.168 +          case '+':
   1.169 +          case '-':
   1.170 +          case '/':
   1.171 +          case '*':
   1.172 +            op1=polishstack.top();
   1.173 +            polishstack.pop();
   1.174 +            op2=polishstack.top();
   1.175 +            polishstack.pop();
   1.176 +            break;
   1.177 +          default:
   1.178 +            //substitute variable
   1.179 +            std::vector<std::string> maps = ms.getNodeMapList(NUM);
   1.180 +            bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
   1.181 +            if(itisvar)
   1.182 +            {
   1.183 +              polishstack.push(ms.get(ch2var[ polishform[i] ], k));
   1.184 +            }
   1.185 +            else
   1.186 +            {
   1.187 +              polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.188 +            }
   1.189 +            operation=false;
   1.190 +            break;
   1.191 +        }
   1.192 +        if(operation)
   1.193 +        {
   1.194 +          double res;
   1.195 +          switch(polishform[i])
   1.196 +          {
   1.197 +            case '+':
   1.198 +              res=op1+op2;
   1.199 +              break;
   1.200 +            case '-':
   1.201 +              res=op2-op1;
   1.202 +              break;
   1.203 +            case '/':
   1.204 +              res=op2/op1;
   1.205 +              break;
   1.206 +            case '*':
   1.207 +              res=op1*op2;
   1.208 +              break;
   1.209 +            default:
   1.210 +              std::cout << "How could we get here?" << std::endl;
   1.211 +              break;
   1.212 +          }
   1.213 +          polishstack.push(res);
   1.214 +        }
   1.215 +      }//foreach letter in polishform
   1.216 +      ret->push_back(polishstack.top());
   1.217 +    }//foreach edge
   1.218 +  }
   1.219 +  return ret;
   1.220 +}
   1.221 +
   1.222  void NewMapWin::on_response(int response_id)
   1.223  {
   1.224 +  MapStorage& ms = *mytab.mapstorage;
   1.225 +
   1.226    if(response_id==Gtk::RESPONSE_OK)
   1.227 +  {
   1.228 +    std::string map_name = name.get_text();
   1.229 +    std::string def_val = default_value.get_text();
   1.230 +
   1.231 +    if (map_name.empty())
   1.232      {
   1.233 -      double def_val=0;
   1.234 +      setErrorMsg("No map name given.");
   1.235 +      return;
   1.236 +    }
   1.237  
   1.238 -      //get and formulate text
   1.239 -      std::string def_val_str=default_value.get_text();
   1.240 +    // check whether the map already exists
   1.241 +    if (edge.get_active())
   1.242 +    {
   1.243 +      if (ms.edgeMapExists(map_name))
   1.244 +      {
   1.245 +        setErrorMsg("Map '" + map_name + "' already exists.");
   1.246 +        return;
   1.247 +      }
   1.248 +    }
   1.249 +    else
   1.250 +    {
   1.251 +      if (ms.nodeMapExists(map_name))
   1.252 +      {
   1.253 +        setErrorMsg("Map '" + map_name + "' already exists.");
   1.254 +        return;
   1.255 +      }
   1.256 +    }
   1.257  
   1.258 -      bool only_nums=true;
   1.259 -      for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
   1.260 -	{
   1.261 -	  if( def_val_str[i]<'0' || def_val_str[i]>'9' )
   1.262 -	    {
   1.263 -	      only_nums=false;
   1.264 -	    }
   1.265 -	}
   1.266 -      std::string polishform;
   1.267 +    Glib::ustring text = cbType.get_active_text();
   1.268 +    if (text == "Numeric")
   1.269 +    {
   1.270 +      double d;
   1.271 +      char *endptr;
   1.272 +      d = strtod(def_val.c_str(), &endptr);
   1.273 +      if (def_val.c_str() + def_val.length() == endptr)
   1.274 +      {
   1.275 +        // the full string was a number
   1.276 +        if (edge.get_active())
   1.277 +          ms.createEdgeMap(map_name, MapValue::NUMERIC,
   1.278 +              MapValue(d));
   1.279 +        else
   1.280 +          ms.createNodeMap(map_name, MapValue::NUMERIC,
   1.281 +              MapValue(d));
   1.282 +      }
   1.283 +      else
   1.284 +      {
   1.285 +        // let't try to evaluate the string as an arithmetic expression
   1.286 +        std::string polishform =
   1.287 +          string2Polishform(def_val, edge.get_active());
   1.288 +        if (polishform.empty())
   1.289 +          return;
   1.290 +        std::vector<double>* values =
   1.291 +          evaluate_expr(polishform, edge.get_active());
   1.292 +        if (edge.get_active())
   1.293 +        {
   1.294 +          ms.createEdgeMap(map_name, MapValue::NUMERIC,
   1.295 +              MapValue(0.0));
   1.296 +          std::vector<double>::const_iterator vit = values->begin();
   1.297 +          for (EdgeIt it(ms.graph); it != INVALID; ++it)
   1.298 +          {
   1.299 +            ms.set(map_name, it, MapValue(*vit));
   1.300 +            ++vit;
   1.301 +          }
   1.302 +        }
   1.303 +        else
   1.304 +        {
   1.305 +          ms.createNodeMap(map_name, MapValue::NUMERIC,
   1.306 +              MapValue(0.0));
   1.307 +          std::vector<double>::const_iterator vit = values->begin();
   1.308 +          for (NodeIt it(ms.graph); it != INVALID; ++it)
   1.309 +          {
   1.310 +            ms.set(map_name, it, MapValue(*vit));
   1.311 +            ++vit;
   1.312 +          }
   1.313 +        }
   1.314 +        delete values;
   1.315 +      }
   1.316 +    }
   1.317 +    else if (text == "String")
   1.318 +    {
   1.319 +      if (edge.get_active())
   1.320 +        ms.createEdgeMap(map_name, MapValue::STRING,
   1.321 +            MapValue(def_val));
   1.322 +      else
   1.323 +        ms.createNodeMap(map_name, MapValue::STRING,
   1.324 +            MapValue(def_val));
   1.325 +    }
   1.326  
   1.327 -      if(only_nums)
   1.328 -	{
   1.329 -	  def_val=atof(def_val_str.c_str());
   1.330 -	}
   1.331 -      else
   1.332 -	{
   1.333 -	  polishform=string2Polishform(def_val_str,edge.get_active());
   1.334 -	}
   1.335 -
   1.336 -      //get name of text
   1.337 -      std::string mapname=name.get_text();
   1.338 -      
   1.339 -      if(!mapname.empty()&&(!polishform.empty()||only_nums))
   1.340 -	{
   1.341 -	  int abortion=0;
   1.342 -	  if(edge.get_active())
   1.343 -	    {
   1.344 -	      //create the new map
   1.345 -	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage->graph, def_val);
   1.346 -	      
   1.347 -	      if(!only_nums)
   1.348 -		{
   1.349 -		  std::stack<double> polishstack;
   1.350 -		  
   1.351 -		  for(EdgeIt k(mytab.mapstorage->graph); k!=INVALID; ++k)
   1.352 -		    {
   1.353 -		      for(int i=0;i<(int)polishform.size();i++)
   1.354 -			{
   1.355 -			  double op1=0, op2=0;
   1.356 -			  bool operation=true;
   1.357 -			  switch(polishform[i])
   1.358 -			    {
   1.359 -			    case '+':
   1.360 -			    case '-':
   1.361 -			    case '/':
   1.362 -			    case '*':
   1.363 -			      op1=polishstack.top();
   1.364 -			      polishstack.pop();
   1.365 -			      op2=polishstack.top();
   1.366 -			      polishstack.pop();
   1.367 -			      break;
   1.368 -			    default:
   1.369 -			      //substitute variable
   1.370 -			      std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage->edgemap_storage;
   1.371 -			      bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   1.372 -			      if(itisvar)
   1.373 -				{
   1.374 -				  polishstack.push( (*(mytab.mapstorage->edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.375 -				}
   1.376 -			      else
   1.377 -				{
   1.378 -				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.379 -				}
   1.380 -			      operation=false;
   1.381 -			      break;
   1.382 -			    }
   1.383 -			  if(operation)
   1.384 -			    {
   1.385 -			      double res;
   1.386 -			      switch(polishform[i])
   1.387 -				{
   1.388 -				case '+':
   1.389 -				  res=op1+op2;
   1.390 -				  break;
   1.391 -				case '-':
   1.392 -				  res=op2-op1;
   1.393 -				  break;
   1.394 -				case '/':
   1.395 -				  res=op2/op1;
   1.396 -				  break;
   1.397 -				case '*':
   1.398 -				  res=op1*op2;
   1.399 -				  break;
   1.400 -				default:
   1.401 -				  std::cout << "How could we get here?" << std::endl;
   1.402 -				  break;
   1.403 -				}
   1.404 -			      polishstack.push(res);
   1.405 -			    }
   1.406 -			}//foreach letter in polishform
   1.407 -		      (*emptr)[k]=polishstack.top(); 
   1.408 -		    }//foreach edge
   1.409 -		}//!only_nums
   1.410 -
   1.411 -	      //if addition was not successful addEdgeMap returns one.
   1.412 -	      //cause can be that there is already a map named like the new one
   1.413 -	      if(mytab.mapstorage->addEdgeMap(mapname, emptr, def_val))
   1.414 -		{
   1.415 -		  abortion=1;
   1.416 -		}
   1.417 -
   1.418 -	      //add it to the list of the displayable maps
   1.419 -	      //furthermore it is done by signals
   1.420 -	      //mytab.registerNewEdgeMap(mapname);
   1.421 -
   1.422 -	      //display it
   1.423 -	      //gdc.changeEdgeText(mapname);
   1.424 -	    }
   1.425 -	  else //!edge.get_active()
   1.426 -	    {
   1.427 -	      //create the new map
   1.428 -	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage->graph, def_val);
   1.429 -
   1.430 -	      if(!only_nums)
   1.431 -		{
   1.432 -		  std::stack<double> polishstack;
   1.433 -  
   1.434 -		  for(NodeIt k(mytab.mapstorage->graph); k!=INVALID; ++k)
   1.435 -		    {
   1.436 -		      for(int i=0;i<(int)polishform.size();i++)
   1.437 -			{
   1.438 -			  double op1=0, op2=0;
   1.439 -			  bool operation=true;
   1.440 -			  switch(polishform[i])
   1.441 -			    {
   1.442 -			    case '+':
   1.443 -			    case '-':
   1.444 -			    case '/':
   1.445 -			    case '*':
   1.446 -			      op1=polishstack.top();
   1.447 -			      polishstack.pop();
   1.448 -			      op2=polishstack.top();
   1.449 -			      polishstack.pop();
   1.450 -			      break;
   1.451 -			    default:
   1.452 -			      std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage->nodemap_storage;
   1.453 -			      bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   1.454 -			      if(itisvar)
   1.455 -				{
   1.456 -				  polishstack.push( (*(mytab.mapstorage->nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.457 -				}
   1.458 -			      else
   1.459 -				{
   1.460 -				  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
   1.461 -				}
   1.462 -			      operation=false;
   1.463 -			      break;
   1.464 -			    }
   1.465 -			  if(operation)
   1.466 -			    {
   1.467 -			      double res;
   1.468 -			      switch(polishform[i])
   1.469 -				{
   1.470 -				case '+':
   1.471 -				  res=op1+op2;
   1.472 -				  break;
   1.473 -				case '-':
   1.474 -				  res=op2-op1;
   1.475 -				  break;
   1.476 -				case '/':
   1.477 -				  res=op2/op1;
   1.478 -				  break;
   1.479 -				case '*':
   1.480 -				  res=op1*op2;
   1.481 -				  break;
   1.482 -				default:
   1.483 -				  std::cout << "How could we get here?" << std::endl;
   1.484 -				  break;
   1.485 -				}
   1.486 -			      polishstack.push(res);
   1.487 -			    }
   1.488 -			}
   1.489 -		      (*emptr)[k]=polishstack.top(); 
   1.490 -		    }
   1.491 -		}
   1.492 -	      //if addition was not successful addNodeMap returns one.
   1.493 -	      //cause can be that there is already a map named like the new one
   1.494 -	      if(mytab.mapstorage->addNodeMap(mapname,emptr, def_val))
   1.495 -		{
   1.496 -		  abortion=1;
   1.497 -		}
   1.498 -
   1.499 -	      //add it to the list of the displayable maps
   1.500 -	      //furthermore it is done by signals
   1.501 -	      //mytab.registerNewNodeMap(mapname);
   1.502 -
   1.503 -	      //display it
   1.504 -	      //gdc.changeNodeText(mapname);
   1.505 -	    }
   1.506 -	  if(!abortion)
   1.507 -	    {
   1.508 -	      name.set_text("");
   1.509 -	      default_value.set_text("0");
   1.510 -	      edge.show();
   1.511 -	      node.show();
   1.512 -	      hide();
   1.513 -	    }
   1.514 -	}
   1.515 -    }
   1.516 +    name.set_text("");
   1.517 +    default_value.set_text("0");
   1.518 +    edge.show();
   1.519 +    node.show();
   1.520 +    hide();
   1.521 +  }
   1.522  }
   1.523  
   1.524  
   1.525 @@ -308,128 +348,128 @@
   1.526    char index='a';
   1.527  
   1.528    for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
   1.529 +  {
   1.530 +    switch(rawcommand[i])
   1.531      {
   1.532 -      switch(rawcommand[i])
   1.533 -	{
   1.534 -	case '+':
   1.535 -	case '-':
   1.536 -	case '*':
   1.537 -	case '/':
   1.538 -	case ')':
   1.539 -	case '(':
   1.540 - 	  if(!variable.empty())
   1.541 -	    {
   1.542 -	      valid_entry=validVariable(variable, itisedge);
   1.543 -	      ch2var[index]=variable;
   1.544 -	      command+=index;
   1.545 -	      index++;
   1.546 -	      variable.erase(0,variable.size());	  
   1.547 -	    }
   1.548 -	  command+=rawcommand[i];
   1.549 -	  break;
   1.550 -	default:
   1.551 -	  variable+=rawcommand[i];
   1.552 -	  break;
   1.553 -	}
   1.554 +      case '+':
   1.555 +      case '-':
   1.556 +      case '*':
   1.557 +      case '/':
   1.558 +      case ')':
   1.559 +      case '(':
   1.560 +        if(!variable.empty())
   1.561 +        {
   1.562 +          valid_entry=validVariable(variable, itisedge);
   1.563 +          ch2var[index]=variable;
   1.564 +          command+=index;
   1.565 +          index++;
   1.566 +          variable.erase(0,variable.size());	  
   1.567 +        }
   1.568 +        command+=rawcommand[i];
   1.569 +        break;
   1.570 +      default:
   1.571 +        variable+=rawcommand[i];
   1.572 +        break;
   1.573 +    }
   1.574 +  }
   1.575 +
   1.576 +  if(!variable.empty()&&valid_entry)
   1.577 +  {
   1.578 +    valid_entry=validVariable(variable, itisedge);
   1.579 +    ch2var[index]=variable;
   1.580 +    command+=index;
   1.581 +    index++;
   1.582 +    variable.erase(0,variable.size());	  
   1.583 +  }
   1.584 +
   1.585 +  if(valid_entry)
   1.586 +  {
   1.587 +    unsigned int pr=10000;
   1.588 +    bool prevmult=false;
   1.589 +    unsigned int prev_change=pr;
   1.590 +    unsigned int prev_br=pr;
   1.591 +    int counter=0;
   1.592 +    std::string comm_nobr="";
   1.593 +    std::vector<unsigned int> p;
   1.594 +    p.resize(counter+1);
   1.595 +
   1.596 +    //limits
   1.597 +    //6 brackets embedded
   1.598 +    //100 operation in a row from the same priority
   1.599 +
   1.600 +    for(int i=0;i<(int)command.size();i++)
   1.601 +    {
   1.602 +      bool put_in_string=true;
   1.603 +      switch(command[i])
   1.604 +      {
   1.605 +        case '(':
   1.606 +          pr=prev_br+10000;
   1.607 +          prev_br=pr;
   1.608 +          prevmult=false;
   1.609 +          put_in_string=false;
   1.610 +          break;
   1.611 +        case ')':
   1.612 +          pr=prev_br-10000;
   1.613 +          prev_br=pr;
   1.614 +          prevmult=false;
   1.615 +          put_in_string=false;
   1.616 +          break;
   1.617 +        case '+':
   1.618 +        case '-':
   1.619 +          if(prevmult)
   1.620 +          {
   1.621 +            pr=prev_change;
   1.622 +          }
   1.623 +          p[counter]=pr;
   1.624 +          pr-=100;
   1.625 +
   1.626 +          prevmult=false;
   1.627 +          break;
   1.628 +        case '/':
   1.629 +        case '*':
   1.630 +          if(!prevmult)
   1.631 +          {
   1.632 +            prev_change=pr;
   1.633 +            pr+=200;
   1.634 +            pr-=1;
   1.635 +          }
   1.636 +          p[counter]=pr;
   1.637 +          pr-=1;
   1.638 +          prevmult=true;
   1.639 +          break;
   1.640 +        default:
   1.641 +          p[counter]=65000;
   1.642 +          break;
   1.643 +      }
   1.644 +      if(put_in_string)
   1.645 +      {
   1.646 +        counter++;
   1.647 +        p.resize(counter+1);
   1.648 +        comm_nobr=comm_nobr+command[i];
   1.649 +      }
   1.650      }
   1.651  
   1.652 -  if(!variable.empty()&&valid_entry)
   1.653 -    {
   1.654 -      valid_entry=validVariable(variable, itisedge);
   1.655 -      ch2var[index]=variable;
   1.656 -      command+=index;
   1.657 -      index++;
   1.658 -      variable.erase(0,variable.size());	  
   1.659 -    }
   1.660 +    tree_node * root=weightedString2Tree(comm_nobr, p, 0);
   1.661  
   1.662 -  if(valid_entry)
   1.663 -    {
   1.664 -      unsigned int pr=10000;
   1.665 -      bool prevmult=false;
   1.666 -      unsigned int prev_change=pr;
   1.667 -      unsigned int prev_br=pr;
   1.668 -      int counter=0;
   1.669 -      std::string comm_nobr="";
   1.670 -      std::vector<unsigned int> p;
   1.671 -      p.resize(counter+1);
   1.672 -      
   1.673 -      //limits
   1.674 -      //6 brackets embedded
   1.675 -      //100 operation in a row from the same priority
   1.676 -      
   1.677 -      for(int i=0;i<(int)command.size();i++)
   1.678 -	{
   1.679 -	  bool put_in_string=true;
   1.680 -	  switch(command[i])
   1.681 -	    {
   1.682 -	    case '(':
   1.683 -	      pr=prev_br+10000;
   1.684 -	      prev_br=pr;
   1.685 -	      prevmult=false;
   1.686 -	      put_in_string=false;
   1.687 -	      break;
   1.688 -	    case ')':
   1.689 -	      pr=prev_br-10000;
   1.690 -	      prev_br=pr;
   1.691 -	      prevmult=false;
   1.692 -	      put_in_string=false;
   1.693 -	      break;
   1.694 -	    case '+':
   1.695 -	    case '-':
   1.696 -	      if(prevmult)
   1.697 -		{
   1.698 -		  pr=prev_change;
   1.699 -		}
   1.700 -	      p[counter]=pr;
   1.701 -	      pr-=100;
   1.702 +    std::string polishform=postOrder(root);
   1.703  
   1.704 -	      prevmult=false;
   1.705 -	      break;
   1.706 -	    case '/':
   1.707 -	    case '*':
   1.708 -	      if(!prevmult)
   1.709 -		{
   1.710 -		  prev_change=pr;
   1.711 -		  pr+=200;
   1.712 -		  pr-=1;
   1.713 -		}
   1.714 -	      p[counter]=pr;
   1.715 -	      pr-=1;
   1.716 -	      prevmult=true;
   1.717 -	      break;
   1.718 -	    default:
   1.719 -	      p[counter]=65000;
   1.720 -	      break;
   1.721 -	    }
   1.722 -	  if(put_in_string)
   1.723 -	    {
   1.724 -	      counter++;
   1.725 -	      p.resize(counter+1);
   1.726 -	      comm_nobr=comm_nobr+command[i];
   1.727 -	    }
   1.728 -	}
   1.729 +    deleteTree(root);
   1.730  
   1.731 -      tree_node * root=weightedString2Tree(comm_nobr, p, 0);
   1.732 -
   1.733 -      std::string polishform=postOrder(root);
   1.734 -
   1.735 -      deleteTree(root);
   1.736 -
   1.737 -      return polishform;
   1.738 -    }
   1.739 +    return polishform;
   1.740 +  }
   1.741    return "";
   1.742  }
   1.743  
   1.744  void NewMapWin::deleteTree(NewMapWin::tree_node * node)
   1.745  {
   1.746    if(node->left_child!=NULL)
   1.747 -    {
   1.748 -      deleteTree(node->left_child);
   1.749 -    }
   1.750 +  {
   1.751 +    deleteTree(node->left_child);
   1.752 +  }
   1.753    if(node->right_child!=NULL)
   1.754 -    {
   1.755 -      deleteTree(node->right_child);
   1.756 -    }
   1.757 +  {
   1.758 +    deleteTree(node->right_child);
   1.759 +  }
   1.760    delete node;
   1.761  }
   1.762  
   1.763 @@ -438,25 +478,25 @@
   1.764    unsigned int min=p[offset];
   1.765    int minplace=0;
   1.766    for(int i=0;i<(int)to_tree.size();i++)
   1.767 +  {
   1.768 +    if(min>p[offset+i])
   1.769      {
   1.770 -      if(min>p[offset+i])
   1.771 -	{
   1.772 -	  min=p[offset+i];
   1.773 -	  minplace=i;
   1.774 -	}
   1.775 +      min=p[offset+i];
   1.776 +      minplace=i;
   1.777      }
   1.778 +  }
   1.779    tree_node * act_node=new tree_node;
   1.780    act_node->ch=to_tree[minplace];
   1.781    if(to_tree.size()>=3)
   1.782 -    {
   1.783 -      act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
   1.784 -      act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
   1.785 -    }
   1.786 +  {
   1.787 +    act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
   1.788 +    act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
   1.789 +  }
   1.790    else
   1.791 -    {
   1.792 -      act_node->left_child=NULL;
   1.793 -      act_node->right_child=NULL;
   1.794 -    }
   1.795 +  {
   1.796 +    act_node->left_child=NULL;
   1.797 +    act_node->right_child=NULL;
   1.798 +  }
   1.799    return act_node;
   1.800  }
   1.801  
   1.802 @@ -464,56 +504,62 @@
   1.803  {
   1.804    std::string subtree_to_string;
   1.805    if(subtree->left_child)
   1.806 -    {
   1.807 -      subtree_to_string=postOrder(subtree->left_child);
   1.808 -    }
   1.809 +  {
   1.810 +    subtree_to_string=postOrder(subtree->left_child);
   1.811 +  }
   1.812    if(subtree->right_child)
   1.813 -    {
   1.814 -      subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
   1.815 -    }
   1.816 +  {
   1.817 +    subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
   1.818 +  }
   1.819    subtree_to_string=subtree_to_string+subtree->ch;
   1.820    return subtree_to_string;
   1.821  }
   1.822  
   1.823  bool NewMapWin::validVariable(std::string variable, bool itisedge)
   1.824  {
   1.825 +  MapStorage& ms = *mytab.mapstorage;
   1.826 +
   1.827    bool cancel;
   1.828    //is it mapname?
   1.829    if(itisedge)
   1.830 -    {
   1.831 -      cancel=(mytab.mapstorage->edgemap_storage.find(variable)==mytab.mapstorage->edgemap_storage.end());
   1.832 -    }
   1.833 +  {
   1.834 +    std::vector<std::string> edge_maps =
   1.835 +      ms.getEdgeMapList(NUM);
   1.836 +    cancel=(std::find(edge_maps.begin(), edge_maps.end(), variable)==edge_maps.end());
   1.837 +  }
   1.838    else
   1.839 -    {
   1.840 -      cancel=(mytab.mapstorage->nodemap_storage.find(variable)==mytab.mapstorage->nodemap_storage.end());
   1.841 -    }
   1.842 +  {
   1.843 +    std::vector<std::string> node_maps =
   1.844 +      ms.getNodeMapList(NUM);
   1.845 +    cancel=(std::find(node_maps.begin(), node_maps.end(), variable)==node_maps.end());
   1.846 +  }
   1.847    //maybe it is number
   1.848    int point_num=0;
   1.849    if(cancel)
   1.850 +  {
   1.851 +    cancel=false;
   1.852 +    for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
   1.853      {
   1.854 -      cancel=false;
   1.855 -      for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
   1.856 -	{
   1.857 -	  if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
   1.858 -	    {
   1.859 -	      cancel=true;
   1.860 -	    }
   1.861 -	  else
   1.862 -	    {
   1.863 -	      if(variable[j]=='.')
   1.864 -		{
   1.865 -		  point_num++;
   1.866 -		  if(point_num>1)
   1.867 -		    {
   1.868 -		      cancel=true;
   1.869 -		    }
   1.870 -		}
   1.871 -	    }
   1.872 -	}
   1.873 +      if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
   1.874 +      {
   1.875 +        cancel=true;
   1.876 +      }
   1.877 +      else
   1.878 +      {
   1.879 +        if(variable[j]=='.')
   1.880 +        {
   1.881 +          point_num++;
   1.882 +          if(point_num>1)
   1.883 +          {
   1.884 +            cancel=true;
   1.885 +          }
   1.886 +        }
   1.887 +      }
   1.888      }
   1.889 +  }
   1.890    if(cancel)
   1.891 -    {
   1.892 -      return false;
   1.893 -    }
   1.894 +  {
   1.895 +    return false;
   1.896 +  }
   1.897    return true;
   1.898  }