gui/new_map_win.cc
changeset 1872 3b7694cf0a08
parent 1837 8dd6160ff699
child 1878 409a31271efd
equal deleted inserted replaced
6:b0c415e9eaa2 7:345b48244cb9
     7     hide();
     7     hide();
     8   }
     8   }
     9   return true;
     9   return true;
    10 }
    10 }
    11 
    11 
    12 NewMapWin::NewMapWin(const std::string& title, MainWin & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mainwin(mw),node("Create NodeMap"),edge("Create EdgeMap")
    12 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")
    13 {
    13 {
    14   set_default_size(200, 50);
    14   set_default_size(200, 50);
    15 
    15 
    16   signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    16   signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    17 
    17 
    81 	{
    81 	{
    82 	  int abortion=0;
    82 	  int abortion=0;
    83 	  if(edge.get_active())
    83 	  if(edge.get_active())
    84 	    {
    84 	    {
    85 	      //create the new map
    85 	      //create the new map
    86 	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mainwin.mapstorage.graph);
    86 	      Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
    87 
    87 
    88 	      std::stack<double> polishstack;
    88 	      std::stack<double> polishstack;
    89   
    89   
    90 	      for(EdgeIt k(mainwin.mapstorage.graph); k!=INVALID; ++k)
    90 	      for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    91 		{
    91 		{
    92 		  for(int i=0;i<(int)polishform.size();i++)
    92 		  for(int i=0;i<(int)polishform.size();i++)
    93 		    {
    93 		    {
    94 		      double op1, op2;
    94 		      double op1, op2;
    95 		      bool operation=true;
    95 		      bool operation=true;
   104 			  op2=polishstack.top();
   104 			  op2=polishstack.top();
   105 			  polishstack.pop();
   105 			  polishstack.pop();
   106 			  break;
   106 			  break;
   107 			default:
   107 			default:
   108 			  //substitute variable
   108 			  //substitute variable
   109 			  std::map< std::string,Graph::EdgeMap<double> * > ems=mainwin.mapstorage.edgemap_storage;
   109 			  std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
   110 			  bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   110 			  bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
   111 			  if(itisvar)
   111 			  if(itisvar)
   112 			    {
   112 			    {
   113 			      polishstack.push( (*(mainwin.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   113 			      polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   114 			    }
   114 			    }
   115 			  else
   115 			  else
   116 			    {
   116 			    {
   117 			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   117 			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   118 			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   118 			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   151 		  (*emptr)[k]=polishstack.top(); 
   151 		  (*emptr)[k]=polishstack.top(); 
   152 		}
   152 		}
   153 
   153 
   154 	      //if addition was not successful addEdgeMap returns one.
   154 	      //if addition was not successful addEdgeMap returns one.
   155 	      //cause can be that there is already a map named like the new one
   155 	      //cause can be that there is already a map named like the new one
   156 	      if(mainwin.mapstorage.addEdgeMap(mapname, emptr, def_val))
   156 	      if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
   157 		{
   157 		{
   158 		  abortion=1;
   158 		  abortion=1;
   159 		}
   159 		}
   160 
   160 
   161 	      //add it to the list of the displayable maps
   161 	      //add it to the list of the displayable maps
   162 	      mainwin.registerNewEdgeMap(mapname);
   162 	      mytab.registerNewEdgeMap(mapname);
   163 
   163 
   164 	      //display it
   164 	      //display it
   165 	      //gdc.changeEdgeText(mapname);
   165 	      //gdc.changeEdgeText(mapname);
   166 	    }
   166 	    }
   167 	  else //!edge.get_active()
   167 	  else //!edge.get_active()
   168 	    {
   168 	    {
   169 	      //create the new map
   169 	      //create the new map
   170 	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mainwin.mapstorage.graph);
   170 	      Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
   171 
   171 
   172 	      std::stack<double> polishstack;
   172 	      std::stack<double> polishstack;
   173   
   173   
   174 	      for(NodeIt k(mainwin.mapstorage.graph); k!=INVALID; ++k)
   174 	      for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
   175 		{
   175 		{
   176 		  for(int i=0;i<(int)polishform.size();i++)
   176 		  for(int i=0;i<(int)polishform.size();i++)
   177 		    {
   177 		    {
   178 		      double op1, op2;
   178 		      double op1, op2;
   179 		      bool operation=true;
   179 		      bool operation=true;
   187 			  polishstack.pop();
   187 			  polishstack.pop();
   188 			  op2=polishstack.top();
   188 			  op2=polishstack.top();
   189 			  polishstack.pop();
   189 			  polishstack.pop();
   190 			  break;
   190 			  break;
   191 			default:
   191 			default:
   192 			  std::map< std::string,Graph::NodeMap<double> * > nms=mainwin.mapstorage.nodemap_storage;
   192 			  std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
   193 			  bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   193 			  bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
   194 			  if(itisvar)
   194 			  if(itisvar)
   195 			    {
   195 			    {
   196 			      polishstack.push( (*(mainwin.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   196 			      polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
   197 			    }
   197 			    }
   198 			  else
   198 			  else
   199 			    {
   199 			    {
   200 			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   200 			      char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
   201 			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   201 			      for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
   234 		  (*emptr)[k]=polishstack.top(); 
   234 		  (*emptr)[k]=polishstack.top(); 
   235 		}
   235 		}
   236 
   236 
   237 	      //if addition was not successful addNodeMap returns one.
   237 	      //if addition was not successful addNodeMap returns one.
   238 	      //cause can be that there is already a map named like the new one
   238 	      //cause can be that there is already a map named like the new one
   239 	      if(mainwin.mapstorage.addNodeMap(mapname,emptr, def_val))
   239 	      if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
   240 		{
   240 		{
   241 		  abortion=1;
   241 		  abortion=1;
   242 		}
   242 		}
   243 
   243 
   244 	      //add it to the list of the displayable maps
   244 	      //add it to the list of the displayable maps
   245 	      mainwin.registerNewNodeMap(mapname);
   245 	      mytab.registerNewNodeMap(mapname);
   246 
   246 
   247 	      //display it
   247 	      //display it
   248 	      //gdc.changeNodeText(mapname);
   248 	      //gdc.changeNodeText(mapname);
   249 	    }
   249 	    }
   250 	  if(!abortion)
   250 	  if(!abortion)
   429 {
   429 {
   430   bool cancel;
   430   bool cancel;
   431   //is it mapname?
   431   //is it mapname?
   432   if(itisedge)
   432   if(itisedge)
   433     {
   433     {
   434       cancel=(mainwin.mapstorage.edgemap_storage.find(variable)==mainwin.mapstorage.edgemap_storage.end());
   434       cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end());
   435     }
   435     }
   436   else
   436   else
   437     {
   437     {
   438       cancel=(mainwin.mapstorage.nodemap_storage.find(variable)==mainwin.mapstorage.nodemap_storage.end());
   438       cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end());
   439     }
   439     }
   440   //maybe it is number
   440   //maybe it is number
   441   int point_num=0;
   441   int point_num=0;
   442   if(cancel)
   442   if(cancel)
   443     {
   443     {