new_map_win.cc
branchgui
changeset 90 e9f8f44f12a3
parent 89 4042761b21e3
child 94 adfdc2f70548
     1.1 --- a/new_map_win.cc	Mon Nov 21 12:07:05 2005 +0000
     1.2 +++ b/new_map_win.cc	Mon Nov 21 18:03:20 2005 +0000
     1.3 @@ -9,13 +9,13 @@
     1.4    return true;
     1.5  }
     1.6  
     1.7 -NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
     1.8 +NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
     1.9  {
    1.10 -  set_title(title);
    1.11    set_default_size(200, 50);
    1.12  
    1.13    signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    1.14  
    1.15 +  Gtk::VBox * vbox=get_vbox();
    1.16  
    1.17    //entries
    1.18    table=new Gtk::Table(3, 2, false);
    1.19 @@ -37,236 +37,229 @@
    1.20    //node vs. edge map selector
    1.21    Gtk::RadioButton::Group group = node.get_group();
    1.22    edge.set_group(group);
    1.23 +  
    1.24 +  if(edgenode)
    1.25 +    {
    1.26 +      (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.27 +      (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.28 +    }
    1.29 +  else
    1.30 +    {
    1.31 +      if(itisedge)
    1.32 +	{
    1.33 +	  edge.set_active();
    1.34 +	}
    1.35 +      else
    1.36 +	{
    1.37 +	  node.set_active();
    1.38 +	}
    1.39 +    }
    1.40  
    1.41 -  (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.42 -  (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.43 -
    1.44 -  vbox.pack_start(*table);
    1.45 +  vbox->pack_start(*table);
    1.46  
    1.47    //OK button
    1.48 -  button=new Gtk::Button("OK");
    1.49 -
    1.50 -  button->signal_clicked().connect
    1.51 -    (
    1.52 -     sigc::mem_fun(*this, &NewMapWin::buttonPressed)
    1.53 -    );
    1.54 -
    1.55 -
    1.56 -  vbox.pack_start(*button);
    1.57 -
    1.58 -  add(vbox);
    1.59 +  add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
    1.60  
    1.61    show_all_children();
    1.62  
    1.63  }
    1.64  
    1.65 -void NewMapWin::showByPreChoose(bool itisedge)
    1.66 +void NewMapWin::on_response(int response_id)
    1.67  {
    1.68 -  if(itisedge)
    1.69 +  if(response_id==Gtk::RESPONSE_OK)
    1.70      {
    1.71 -      edge.set_active();
    1.72 -    }
    1.73 -  else
    1.74 -    {
    1.75 -      node.set_active();
    1.76 -    }
    1.77 -  node.hide();
    1.78 -  edge.hide();
    1.79 -  show();
    1.80 -}
    1.81 +      double def_val=0;
    1.82  
    1.83 -void NewMapWin::buttonPressed()
    1.84 -{
    1.85 -  double def_val=0;
    1.86 +      //get and formulate text
    1.87 +      std::string def_val_str=default_value.get_text();
    1.88 +      std::string polishform=string2Polishform(def_val_str,edge.get_active());
    1.89  
    1.90 -  //get and formulate text
    1.91 -  std::string def_val_str=default_value.get_text();
    1.92 -  std::string polishform=string2Polishform(def_val_str,edge.get_active());
    1.93 +      //get name of text
    1.94 +      std::string mapname=name.get_text();
    1.95  
    1.96 -  //get name of text
    1.97 -  std::string mapname=name.get_text();
    1.98 +      if(!mapname.empty()&&!polishform.empty())
    1.99 +	{
   1.100 +	  int abortion=0;
   1.101 +	  if(edge.get_active())
   1.102 +	    {
   1.103 +	      //create the new map
   1.104 +	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph);
   1.105  
   1.106 -  if(!mapname.empty()&&!polishform.empty())
   1.107 -    {
   1.108 -      int abortion=0;
   1.109 -      if(edge.get_active())
   1.110 -	{
   1.111 -	  //create the new map
   1.112 -	  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph);
   1.113 -
   1.114 -	  std::stack<double> polishstack;
   1.115 +	      std::stack<double> polishstack;
   1.116    
   1.117 -	  for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
   1.118 -	    {
   1.119 -	      for(int i=0;i<(int)polishform.size();i++)
   1.120 +	      for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
   1.121  		{
   1.122 -		  double op1, op2;
   1.123 -		  bool operation=true;
   1.124 -		  switch(polishform[i])
   1.125 +		  for(int i=0;i<(int)polishform.size();i++)
   1.126  		    {
   1.127 -		    case '+':
   1.128 -		    case '-':
   1.129 -		    case '/':
   1.130 -		    case '*':
   1.131 -		      op1=polishstack.top();
   1.132 -		      polishstack.pop();
   1.133 -		      op2=polishstack.top();
   1.134 -		      polishstack.pop();
   1.135 -		      break;
   1.136 -		    default:
   1.137 -		      //substitute variable
   1.138 -		      std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage;
   1.139 -		      bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   1.140 -		      if(itisvar)
   1.141 -			{
   1.142 -			  polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.143 -			}
   1.144 -		      else
   1.145 -			{
   1.146 -			  char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   1.147 -			  for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   1.148 -			    {
   1.149 -			      def_val_ch[j]=ch2var[ polishform[i] ][j];
   1.150 -			    }
   1.151 -			  polishstack.push(atof(def_val_ch));
   1.152 -			}
   1.153 -		      operation=false;
   1.154 -		      break;
   1.155 -		    }
   1.156 -		  if(operation)
   1.157 -		    {
   1.158 -		      double res;
   1.159 +		      double op1, op2;
   1.160 +		      bool operation=true;
   1.161  		      switch(polishform[i])
   1.162  			{
   1.163  			case '+':
   1.164 -			  res=op1+op2;
   1.165 -			  break;
   1.166  			case '-':
   1.167 -			  res=op2-op1;
   1.168 -			  break;
   1.169  			case '/':
   1.170 -			  res=op2/op1;
   1.171 -			  break;
   1.172  			case '*':
   1.173 -			  res=op1*op2;
   1.174 +			  op1=polishstack.top();
   1.175 +			  polishstack.pop();
   1.176 +			  op2=polishstack.top();
   1.177 +			  polishstack.pop();
   1.178  			  break;
   1.179  			default:
   1.180 -			  std::cout << "How could we get here?" << std::endl;
   1.181 +			  //substitute variable
   1.182 +			  std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage;
   1.183 +			  bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   1.184 +			  if(itisvar)
   1.185 +			    {
   1.186 +			      polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.187 +			    }
   1.188 +			  else
   1.189 +			    {
   1.190 +			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   1.191 +			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   1.192 +				{
   1.193 +				  def_val_ch[j]=ch2var[ polishform[i] ][j];
   1.194 +				}
   1.195 +			      polishstack.push(atof(def_val_ch));
   1.196 +			    }
   1.197 +			  operation=false;
   1.198  			  break;
   1.199  			}
   1.200 -		      polishstack.push(res);
   1.201 +		      if(operation)
   1.202 +			{
   1.203 +			  double res;
   1.204 +			  switch(polishform[i])
   1.205 +			    {
   1.206 +			    case '+':
   1.207 +			      res=op1+op2;
   1.208 +			      break;
   1.209 +			    case '-':
   1.210 +			      res=op2-op1;
   1.211 +			      break;
   1.212 +			    case '/':
   1.213 +			      res=op2/op1;
   1.214 +			      break;
   1.215 +			    case '*':
   1.216 +			      res=op1*op2;
   1.217 +			      break;
   1.218 +			    default:
   1.219 +			      std::cout << "How could we get here?" << std::endl;
   1.220 +			      break;
   1.221 +			    }
   1.222 +			  polishstack.push(res);
   1.223 +			}
   1.224  		    }
   1.225 +		  (*emptr)[k]=polishstack.top(); 
   1.226  		}
   1.227 -	      (*emptr)[k]=polishstack.top(); 
   1.228 +
   1.229 +	      //if addition was not successful addEdgeMap returns one.
   1.230 +	      //cause can be that there is already a map named like the new one
   1.231 +	      if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val))
   1.232 +		{
   1.233 +		  abortion=1;
   1.234 +		}
   1.235 +
   1.236 +	      //add it to the list of the displayable maps
   1.237 +	      gdc.mapwin.registerNewEdgeMap(mapname);
   1.238 +
   1.239 +	      //display it
   1.240 +	      gdc.changeEdgeText(mapname);
   1.241  	    }
   1.242 +	  else //!edge.get_active()
   1.243 +	    {
   1.244 +	      //create the new map
   1.245 +	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph);
   1.246  
   1.247 -	  //if addition was not successful addEdgeMap returns one.
   1.248 -	  //cause can be that there is already a map named like the new one
   1.249 -	  if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val))
   1.250 -	    {
   1.251 -	      abortion=1;
   1.252 -	    }
   1.253 -
   1.254 -	  //add it to the list of the displayable maps
   1.255 -	  gdc.mapwin.registerNewEdgeMap(mapname);
   1.256 -
   1.257 -	  //display it
   1.258 -	  gdc.changeEdgeText(mapname);
   1.259 -	}
   1.260 -      else //!edge.get_active()
   1.261 -	{
   1.262 -	  //create the new map
   1.263 -	  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph);
   1.264 -
   1.265 -	  std::stack<double> polishstack;
   1.266 +	      std::stack<double> polishstack;
   1.267    
   1.268 -	  for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
   1.269 -	    {
   1.270 -	      for(int i=0;i<(int)polishform.size();i++)
   1.271 +	      for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
   1.272  		{
   1.273 -		  double op1, op2;
   1.274 -		  bool operation=true;
   1.275 -		  switch(polishform[i])
   1.276 +		  for(int i=0;i<(int)polishform.size();i++)
   1.277  		    {
   1.278 -		    case '+':
   1.279 -		    case '-':
   1.280 -		    case '/':
   1.281 -		    case '*':
   1.282 -		      op1=polishstack.top();
   1.283 -		      polishstack.pop();
   1.284 -		      op2=polishstack.top();
   1.285 -		      polishstack.pop();
   1.286 -		      break;
   1.287 -		    default:
   1.288 -		      std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage;
   1.289 -		      bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   1.290 -		      if(itisvar)
   1.291 -			{
   1.292 -			  polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.293 -			}
   1.294 -		      else
   1.295 -			{
   1.296 -			  char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   1.297 -			  for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   1.298 -			    {
   1.299 -			      def_val_ch[j]=ch2var[ polishform[i] ][j];
   1.300 -			    }
   1.301 -			  polishstack.push(atof(def_val_ch));
   1.302 -			}
   1.303 -		      operation=false;
   1.304 -		      break;
   1.305 -		    }
   1.306 -		  if(operation)
   1.307 -		    {
   1.308 -		      double res;
   1.309 +		      double op1, op2;
   1.310 +		      bool operation=true;
   1.311  		      switch(polishform[i])
   1.312  			{
   1.313  			case '+':
   1.314 -			  res=op1+op2;
   1.315 -			  break;
   1.316  			case '-':
   1.317 -			  res=op2-op1;
   1.318 -			  break;
   1.319  			case '/':
   1.320 -			  res=op2/op1;
   1.321 -			  break;
   1.322  			case '*':
   1.323 -			  res=op1*op2;
   1.324 +			  op1=polishstack.top();
   1.325 +			  polishstack.pop();
   1.326 +			  op2=polishstack.top();
   1.327 +			  polishstack.pop();
   1.328  			  break;
   1.329  			default:
   1.330 -			  std::cout << "How could we get here?" << std::endl;
   1.331 +			  std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage;
   1.332 +			  bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   1.333 +			  if(itisvar)
   1.334 +			    {
   1.335 +			      polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   1.336 +			    }
   1.337 +			  else
   1.338 +			    {
   1.339 +			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   1.340 +			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   1.341 +				{
   1.342 +				  def_val_ch[j]=ch2var[ polishform[i] ][j];
   1.343 +				}
   1.344 +			      polishstack.push(atof(def_val_ch));
   1.345 +			    }
   1.346 +			  operation=false;
   1.347  			  break;
   1.348  			}
   1.349 -		      polishstack.push(res);
   1.350 +		      if(operation)
   1.351 +			{
   1.352 +			  double res;
   1.353 +			  switch(polishform[i])
   1.354 +			    {
   1.355 +			    case '+':
   1.356 +			      res=op1+op2;
   1.357 +			      break;
   1.358 +			    case '-':
   1.359 +			      res=op2-op1;
   1.360 +			      break;
   1.361 +			    case '/':
   1.362 +			      res=op2/op1;
   1.363 +			      break;
   1.364 +			    case '*':
   1.365 +			      res=op1*op2;
   1.366 +			      break;
   1.367 +			    default:
   1.368 +			      std::cout << "How could we get here?" << std::endl;
   1.369 +			      break;
   1.370 +			    }
   1.371 +			  polishstack.push(res);
   1.372 +			}
   1.373  		    }
   1.374 +		  (*emptr)[k]=polishstack.top(); 
   1.375  		}
   1.376 -	      (*emptr)[k]=polishstack.top(); 
   1.377 +
   1.378 +	      //if addition was not successful addNodeMap returns one.
   1.379 +	      //cause can be that there is already a map named like the new one
   1.380 +	      if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val))
   1.381 +		{
   1.382 +		  abortion=1;
   1.383 +		}
   1.384 +
   1.385 +	      //add it to the list of the displayable maps
   1.386 +	      gdc.mapwin.registerNewNodeMap(mapname);
   1.387 +
   1.388 +	      //display it
   1.389 +	      //gdc.changeNodeText(mapname);
   1.390  	    }
   1.391 -
   1.392 -	  //if addition was not successful addNodeMap returns one.
   1.393 -	  //cause can be that there is already a map named like the new one
   1.394 -	  if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val))
   1.395 +	  if(!abortion)
   1.396  	    {
   1.397 -	      abortion=1;
   1.398 +	      name.set_text("");
   1.399 +	      default_value.set_text("0");
   1.400 +	      edge.show();
   1.401 +	      node.show();
   1.402 +	      hide();
   1.403  	    }
   1.404 -
   1.405 -	  //add it to the list of the displayable maps
   1.406 -	  gdc.mapwin.registerNewNodeMap(mapname);
   1.407 -
   1.408 -	  //display it
   1.409 -	  gdc.changeNodeText(mapname);
   1.410 -	}
   1.411 -      if(!abortion)
   1.412 -	{
   1.413 -	  name.set_text("");
   1.414 -	  default_value.set_text("0");
   1.415 -	  edge.show();
   1.416 -	  node.show();
   1.417 -	  hide();
   1.418  	}
   1.419      }
   1.420  }
   1.421  
   1.422 +
   1.423  std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
   1.424  {
   1.425    bool valid_entry=true;