Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
1 #include <new_map_win.h>
3 bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
5 if(e->keyval==GDK_Escape)
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")
14 set_default_size(200, 50);
16 signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
18 Gtk::VBox * vbox=get_vbox();
21 table=new Gtk::Table(3, 2, false);
24 label->set_text("Name of new map:");
27 (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
28 (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
31 label->set_text("Default value in the map:");
32 default_value.set_text("0");
34 (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
35 (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
37 //node vs. edge map selector
38 Gtk::RadioButton::Group group = node.get_group();
39 edge.set_group(group);
43 (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
44 (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
58 vbox->pack_start(*table);
61 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
67 void NewMapWin::on_response(int response_id)
69 if(response_id==Gtk::RESPONSE_OK)
73 //get and formulate text
74 std::string def_val_str=default_value.get_text();
75 std::string polishform=string2Polishform(def_val_str,edge.get_active());
78 std::string mapname=name.get_text();
80 if(!mapname.empty()&&!polishform.empty())
86 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
88 std::stack<double> polishstack;
90 for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
92 for(int i=0;i<(int)polishform.size();i++)
102 op1=polishstack.top();
104 op2=polishstack.top();
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());
113 polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
117 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
118 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
120 def_val_ch[j]=ch2var[ polishform[i] ][j];
122 polishstack.push(atof(def_val_ch));
130 switch(polishform[i])
145 std::cout << "How could we get here?" << std::endl;
148 polishstack.push(res);
151 (*emptr)[k]=polishstack.top();
154 //if addition was not successful addEdgeMap returns one.
155 //cause can be that there is already a map named like the new one
156 if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
161 //add it to the list of the displayable maps
162 //furthermore it is done by signals
163 //mytab.registerNewEdgeMap(mapname);
166 //gdc.changeEdgeText(mapname);
168 else //!edge.get_active()
171 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
173 std::stack<double> polishstack;
175 for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
177 for(int i=0;i<(int)polishform.size();i++)
181 switch(polishform[i])
187 op1=polishstack.top();
189 op2=polishstack.top();
193 std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
194 bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
197 polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
201 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
202 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
204 def_val_ch[j]=ch2var[ polishform[i] ][j];
206 polishstack.push(atof(def_val_ch));
214 switch(polishform[i])
229 std::cout << "How could we get here?" << std::endl;
232 polishstack.push(res);
235 (*emptr)[k]=polishstack.top();
238 //if addition was not successful addNodeMap returns one.
239 //cause can be that there is already a map named like the new one
240 if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
245 //add it to the list of the displayable maps
246 //furthermore it is done by signals
247 //mytab.registerNewNodeMap(mapname);
250 //gdc.changeNodeText(mapname);
255 default_value.set_text("0");
265 std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
267 bool valid_entry=true;
269 std::map<std::string, int> str2i;
273 std::string variable;
277 for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
279 switch(rawcommand[i])
287 if(!variable.empty())
289 valid_entry=validVariable(variable, itisedge);
290 ch2var[index]=variable;
293 variable.erase(0,variable.size());
295 command+=rawcommand[i];
298 variable+=rawcommand[i];
303 if(!variable.empty()&&valid_entry)
305 valid_entry=validVariable(variable, itisedge);
306 ch2var[index]=variable;
309 variable.erase(0,variable.size());
314 unsigned int pr=10000;
316 unsigned int prev_change=pr;
317 unsigned int prev_br=pr;
319 std::string comm_nobr="";
320 std::vector<unsigned int> p;
324 //6 brackets embedded
325 //100 operation in a row from the same priority
327 for(int i=0;i<(int)command.size();i++)
329 bool put_in_string=true;
375 comm_nobr=comm_nobr+command[i];
379 tree_node * root=weightedString2Tree(comm_nobr, p, 0);
381 std::string polishform=postOrder(root);
388 NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector<unsigned int> & p, int offset)
390 unsigned int min=p[offset];
392 for(int i=0;i<(int)to_tree.size();i++)
400 tree_node * act_node=new tree_node;
401 act_node->ch=to_tree[minplace];
402 if(to_tree.size()>=3)
404 act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
405 act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
409 act_node->left_child=NULL;
410 act_node->right_child=NULL;
415 std::string NewMapWin::postOrder(tree_node * subtree)
417 std::string subtree_to_string;
418 if(subtree->left_child)
420 subtree_to_string=postOrder(subtree->left_child);
422 if(subtree->right_child)
424 subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
426 subtree_to_string=subtree_to_string+subtree->ch;
427 return subtree_to_string;
430 bool NewMapWin::validVariable(std::string variable, bool itisedge)
436 cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end());
440 cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end());
447 for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
449 if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))