hegyi@42
|
1 |
#include <new_map_win.h>
|
hegyi@42
|
2 |
|
hegyi@42
|
3 |
bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
|
hegyi@42
|
4 |
{
|
hegyi@42
|
5 |
if(e->keyval==GDK_Escape)
|
hegyi@42
|
6 |
{
|
hegyi@42
|
7 |
hide();
|
hegyi@42
|
8 |
}
|
hegyi@42
|
9 |
return true;
|
hegyi@42
|
10 |
}
|
hegyi@42
|
11 |
|
hegyi@96
|
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")
|
hegyi@42
|
13 |
{
|
hegyi@42
|
14 |
set_default_size(200, 50);
|
hegyi@42
|
15 |
|
hegyi@42
|
16 |
signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
|
hegyi@42
|
17 |
|
hegyi@90
|
18 |
Gtk::VBox * vbox=get_vbox();
|
hegyi@42
|
19 |
|
hegyi@42
|
20 |
//entries
|
hegyi@42
|
21 |
table=new Gtk::Table(3, 2, false);
|
hegyi@42
|
22 |
|
hegyi@42
|
23 |
label=new Gtk::Label;
|
hegyi@42
|
24 |
label->set_text("Name of new map:");
|
hegyi@42
|
25 |
name.set_text("");
|
hegyi@42
|
26 |
|
hegyi@42
|
27 |
(*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
28 |
(*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
29 |
|
hegyi@42
|
30 |
label=new Gtk::Label;
|
hegyi@42
|
31 |
label->set_text("Default value in the map:");
|
hegyi@42
|
32 |
default_value.set_text("0");
|
hegyi@42
|
33 |
|
hegyi@42
|
34 |
(*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
35 |
(*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@42
|
36 |
|
hegyi@42
|
37 |
//node vs. edge map selector
|
hegyi@42
|
38 |
Gtk::RadioButton::Group group = node.get_group();
|
hegyi@42
|
39 |
edge.set_group(group);
|
hegyi@90
|
40 |
|
hegyi@90
|
41 |
if(edgenode)
|
hegyi@90
|
42 |
{
|
hegyi@90
|
43 |
(*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@90
|
44 |
(*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@90
|
45 |
}
|
hegyi@90
|
46 |
else
|
hegyi@90
|
47 |
{
|
hegyi@90
|
48 |
if(itisedge)
|
hegyi@90
|
49 |
{
|
hegyi@90
|
50 |
edge.set_active();
|
hegyi@90
|
51 |
}
|
hegyi@90
|
52 |
else
|
hegyi@90
|
53 |
{
|
hegyi@90
|
54 |
node.set_active();
|
hegyi@90
|
55 |
}
|
hegyi@90
|
56 |
}
|
hegyi@42
|
57 |
|
hegyi@90
|
58 |
vbox->pack_start(*table);
|
hegyi@42
|
59 |
|
hegyi@42
|
60 |
//OK button
|
hegyi@90
|
61 |
add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
hegyi@42
|
62 |
|
hegyi@42
|
63 |
show_all_children();
|
hegyi@42
|
64 |
|
hegyi@42
|
65 |
}
|
hegyi@42
|
66 |
|
hegyi@90
|
67 |
void NewMapWin::on_response(int response_id)
|
hegyi@85
|
68 |
{
|
hegyi@90
|
69 |
if(response_id==Gtk::RESPONSE_OK)
|
hegyi@85
|
70 |
{
|
hegyi@90
|
71 |
double def_val=0;
|
hegyi@85
|
72 |
|
hegyi@90
|
73 |
//get and formulate text
|
hegyi@90
|
74 |
std::string def_val_str=default_value.get_text();
|
hegyi@118
|
75 |
|
hegyi@118
|
76 |
bool only_nums=true;
|
hegyi@118
|
77 |
for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
|
hegyi@118
|
78 |
{
|
hegyi@118
|
79 |
if( def_val_str[i]<'0' || def_val_str[i]>'9' )
|
hegyi@118
|
80 |
{
|
hegyi@118
|
81 |
only_nums=false;
|
hegyi@118
|
82 |
}
|
hegyi@118
|
83 |
}
|
hegyi@118
|
84 |
std::string polishform;
|
hegyi@118
|
85 |
|
hegyi@118
|
86 |
if(only_nums)
|
hegyi@118
|
87 |
{
|
hegyi@118
|
88 |
def_val=atof(def_val_str.c_str());
|
hegyi@118
|
89 |
}
|
hegyi@118
|
90 |
else
|
hegyi@118
|
91 |
{
|
hegyi@118
|
92 |
polishform=string2Polishform(def_val_str,edge.get_active());
|
hegyi@118
|
93 |
}
|
hegyi@42
|
94 |
|
hegyi@90
|
95 |
//get name of text
|
hegyi@90
|
96 |
std::string mapname=name.get_text();
|
hegyi@118
|
97 |
|
hegyi@118
|
98 |
if(!mapname.empty()&&(!polishform.empty()||only_nums))
|
hegyi@90
|
99 |
{
|
hegyi@90
|
100 |
int abortion=0;
|
hegyi@90
|
101 |
if(edge.get_active())
|
hegyi@90
|
102 |
{
|
hegyi@90
|
103 |
//create the new map
|
hegyi@118
|
104 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
|
hegyi@118
|
105 |
|
hegyi@118
|
106 |
if(!only_nums)
|
hegyi@88
|
107 |
{
|
hegyi@118
|
108 |
std::stack<double> polishstack;
|
hegyi@118
|
109 |
|
hegyi@118
|
110 |
for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
|
hegyi@88
|
111 |
{
|
hegyi@118
|
112 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@88
|
113 |
{
|
hegyi@118
|
114 |
double op1=0, op2=0;
|
hegyi@118
|
115 |
bool operation=true;
|
hegyi@90
|
116 |
switch(polishform[i])
|
hegyi@90
|
117 |
{
|
hegyi@90
|
118 |
case '+':
|
hegyi@90
|
119 |
case '-':
|
hegyi@90
|
120 |
case '/':
|
hegyi@90
|
121 |
case '*':
|
hegyi@118
|
122 |
op1=polishstack.top();
|
hegyi@118
|
123 |
polishstack.pop();
|
hegyi@118
|
124 |
op2=polishstack.top();
|
hegyi@118
|
125 |
polishstack.pop();
|
hegyi@90
|
126 |
break;
|
hegyi@90
|
127 |
default:
|
hegyi@118
|
128 |
//substitute variable
|
hegyi@118
|
129 |
std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
|
hegyi@118
|
130 |
bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
|
hegyi@118
|
131 |
if(itisvar)
|
hegyi@118
|
132 |
{
|
hegyi@118
|
133 |
polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
|
hegyi@118
|
134 |
}
|
hegyi@118
|
135 |
else
|
hegyi@118
|
136 |
{
|
hegyi@118
|
137 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@118
|
138 |
}
|
hegyi@118
|
139 |
operation=false;
|
hegyi@90
|
140 |
break;
|
hegyi@90
|
141 |
}
|
hegyi@118
|
142 |
if(operation)
|
hegyi@118
|
143 |
{
|
hegyi@118
|
144 |
double res;
|
hegyi@118
|
145 |
switch(polishform[i])
|
hegyi@118
|
146 |
{
|
hegyi@118
|
147 |
case '+':
|
hegyi@118
|
148 |
res=op1+op2;
|
hegyi@118
|
149 |
break;
|
hegyi@118
|
150 |
case '-':
|
hegyi@118
|
151 |
res=op2-op1;
|
hegyi@118
|
152 |
break;
|
hegyi@118
|
153 |
case '/':
|
hegyi@118
|
154 |
res=op2/op1;
|
hegyi@118
|
155 |
break;
|
hegyi@118
|
156 |
case '*':
|
hegyi@118
|
157 |
res=op1*op2;
|
hegyi@118
|
158 |
break;
|
hegyi@118
|
159 |
default:
|
hegyi@118
|
160 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@118
|
161 |
break;
|
hegyi@118
|
162 |
}
|
hegyi@118
|
163 |
polishstack.push(res);
|
hegyi@118
|
164 |
}
|
hegyi@118
|
165 |
}//foreach letter in polishform
|
hegyi@118
|
166 |
(*emptr)[k]=polishstack.top();
|
hegyi@118
|
167 |
}//foreach edge
|
hegyi@118
|
168 |
}//!only_nums
|
hegyi@90
|
169 |
|
hegyi@90
|
170 |
//if addition was not successful addEdgeMap returns one.
|
hegyi@90
|
171 |
//cause can be that there is already a map named like the new one
|
hegyi@96
|
172 |
if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
|
hegyi@90
|
173 |
{
|
hegyi@90
|
174 |
abortion=1;
|
hegyi@90
|
175 |
}
|
hegyi@90
|
176 |
|
hegyi@90
|
177 |
//add it to the list of the displayable maps
|
hegyi@108
|
178 |
//furthermore it is done by signals
|
hegyi@108
|
179 |
//mytab.registerNewEdgeMap(mapname);
|
hegyi@90
|
180 |
|
hegyi@90
|
181 |
//display it
|
hegyi@94
|
182 |
//gdc.changeEdgeText(mapname);
|
hegyi@88
|
183 |
}
|
hegyi@90
|
184 |
else //!edge.get_active()
|
hegyi@90
|
185 |
{
|
hegyi@90
|
186 |
//create the new map
|
hegyi@118
|
187 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
|
hegyi@88
|
188 |
|
hegyi@118
|
189 |
if(!only_nums)
|
hegyi@118
|
190 |
{
|
hegyi@118
|
191 |
std::stack<double> polishstack;
|
hegyi@88
|
192 |
|
hegyi@118
|
193 |
for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
|
hegyi@88
|
194 |
{
|
hegyi@118
|
195 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@88
|
196 |
{
|
hegyi@118
|
197 |
double op1=0, op2=0;
|
hegyi@118
|
198 |
bool operation=true;
|
hegyi@90
|
199 |
switch(polishform[i])
|
hegyi@90
|
200 |
{
|
hegyi@90
|
201 |
case '+':
|
hegyi@90
|
202 |
case '-':
|
hegyi@90
|
203 |
case '/':
|
hegyi@90
|
204 |
case '*':
|
hegyi@118
|
205 |
op1=polishstack.top();
|
hegyi@118
|
206 |
polishstack.pop();
|
hegyi@118
|
207 |
op2=polishstack.top();
|
hegyi@118
|
208 |
polishstack.pop();
|
hegyi@90
|
209 |
break;
|
hegyi@90
|
210 |
default:
|
hegyi@118
|
211 |
std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
|
hegyi@118
|
212 |
bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
|
hegyi@118
|
213 |
if(itisvar)
|
hegyi@118
|
214 |
{
|
hegyi@118
|
215 |
polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
|
hegyi@118
|
216 |
}
|
hegyi@118
|
217 |
else
|
hegyi@118
|
218 |
{
|
hegyi@118
|
219 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@118
|
220 |
}
|
hegyi@118
|
221 |
operation=false;
|
hegyi@90
|
222 |
break;
|
hegyi@90
|
223 |
}
|
hegyi@118
|
224 |
if(operation)
|
hegyi@118
|
225 |
{
|
hegyi@118
|
226 |
double res;
|
hegyi@118
|
227 |
switch(polishform[i])
|
hegyi@118
|
228 |
{
|
hegyi@118
|
229 |
case '+':
|
hegyi@118
|
230 |
res=op1+op2;
|
hegyi@118
|
231 |
break;
|
hegyi@118
|
232 |
case '-':
|
hegyi@118
|
233 |
res=op2-op1;
|
hegyi@118
|
234 |
break;
|
hegyi@118
|
235 |
case '/':
|
hegyi@118
|
236 |
res=op2/op1;
|
hegyi@118
|
237 |
break;
|
hegyi@118
|
238 |
case '*':
|
hegyi@118
|
239 |
res=op1*op2;
|
hegyi@118
|
240 |
break;
|
hegyi@118
|
241 |
default:
|
hegyi@118
|
242 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@118
|
243 |
break;
|
hegyi@118
|
244 |
}
|
hegyi@118
|
245 |
polishstack.push(res);
|
hegyi@118
|
246 |
}
|
hegyi@90
|
247 |
}
|
hegyi@118
|
248 |
(*emptr)[k]=polishstack.top();
|
hegyi@88
|
249 |
}
|
hegyi@88
|
250 |
}
|
hegyi@90
|
251 |
//if addition was not successful addNodeMap returns one.
|
hegyi@90
|
252 |
//cause can be that there is already a map named like the new one
|
hegyi@96
|
253 |
if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
|
hegyi@90
|
254 |
{
|
hegyi@90
|
255 |
abortion=1;
|
hegyi@90
|
256 |
}
|
hegyi@90
|
257 |
|
hegyi@90
|
258 |
//add it to the list of the displayable maps
|
hegyi@108
|
259 |
//furthermore it is done by signals
|
hegyi@108
|
260 |
//mytab.registerNewNodeMap(mapname);
|
hegyi@90
|
261 |
|
hegyi@90
|
262 |
//display it
|
hegyi@90
|
263 |
//gdc.changeNodeText(mapname);
|
hegyi@88
|
264 |
}
|
hegyi@90
|
265 |
if(!abortion)
|
hegyi@88
|
266 |
{
|
hegyi@90
|
267 |
name.set_text("");
|
hegyi@90
|
268 |
default_value.set_text("0");
|
hegyi@90
|
269 |
edge.show();
|
hegyi@90
|
270 |
node.show();
|
hegyi@90
|
271 |
hide();
|
hegyi@88
|
272 |
}
|
hegyi@46
|
273 |
}
|
hegyi@42
|
274 |
}
|
hegyi@42
|
275 |
}
|
hegyi@42
|
276 |
|
hegyi@90
|
277 |
|
hegyi@88
|
278 |
std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
|
hegyi@88
|
279 |
{
|
hegyi@88
|
280 |
bool valid_entry=true;
|
hegyi@88
|
281 |
|
hegyi@88
|
282 |
std::map<std::string, int> str2i;
|
hegyi@88
|
283 |
|
hegyi@88
|
284 |
std::string command;
|
hegyi@88
|
285 |
|
hegyi@88
|
286 |
std::string variable;
|
hegyi@88
|
287 |
|
hegyi@88
|
288 |
char index='a';
|
hegyi@88
|
289 |
|
hegyi@88
|
290 |
for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
|
hegyi@88
|
291 |
{
|
hegyi@88
|
292 |
switch(rawcommand[i])
|
hegyi@88
|
293 |
{
|
hegyi@88
|
294 |
case '+':
|
hegyi@88
|
295 |
case '-':
|
hegyi@88
|
296 |
case '*':
|
hegyi@88
|
297 |
case '/':
|
hegyi@88
|
298 |
case ')':
|
hegyi@88
|
299 |
case '(':
|
hegyi@88
|
300 |
if(!variable.empty())
|
hegyi@88
|
301 |
{
|
hegyi@88
|
302 |
valid_entry=validVariable(variable, itisedge);
|
hegyi@88
|
303 |
ch2var[index]=variable;
|
hegyi@88
|
304 |
command+=index;
|
hegyi@88
|
305 |
index++;
|
hegyi@88
|
306 |
variable.erase(0,variable.size());
|
hegyi@88
|
307 |
}
|
hegyi@88
|
308 |
command+=rawcommand[i];
|
hegyi@88
|
309 |
break;
|
hegyi@88
|
310 |
default:
|
hegyi@88
|
311 |
variable+=rawcommand[i];
|
hegyi@88
|
312 |
break;
|
hegyi@88
|
313 |
}
|
hegyi@88
|
314 |
}
|
hegyi@88
|
315 |
|
hegyi@88
|
316 |
if(!variable.empty()&&valid_entry)
|
hegyi@88
|
317 |
{
|
hegyi@88
|
318 |
valid_entry=validVariable(variable, itisedge);
|
hegyi@88
|
319 |
ch2var[index]=variable;
|
hegyi@88
|
320 |
command+=index;
|
hegyi@88
|
321 |
index++;
|
hegyi@88
|
322 |
variable.erase(0,variable.size());
|
hegyi@88
|
323 |
}
|
hegyi@88
|
324 |
|
hegyi@88
|
325 |
if(valid_entry)
|
hegyi@88
|
326 |
{
|
hegyi@88
|
327 |
unsigned int pr=10000;
|
hegyi@88
|
328 |
bool prevmult=false;
|
hegyi@89
|
329 |
unsigned int prev_change=pr;
|
hegyi@89
|
330 |
unsigned int prev_br=pr;
|
hegyi@88
|
331 |
int counter=0;
|
hegyi@88
|
332 |
std::string comm_nobr="";
|
hegyi@88
|
333 |
std::vector<unsigned int> p;
|
hegyi@88
|
334 |
p.resize(counter+1);
|
hegyi@88
|
335 |
|
hegyi@88
|
336 |
//limits
|
hegyi@88
|
337 |
//6 brackets embedded
|
hegyi@88
|
338 |
//100 operation in a row from the same priority
|
hegyi@88
|
339 |
|
hegyi@88
|
340 |
for(int i=0;i<(int)command.size();i++)
|
hegyi@88
|
341 |
{
|
hegyi@88
|
342 |
bool put_in_string=true;
|
hegyi@88
|
343 |
switch(command[i])
|
hegyi@88
|
344 |
{
|
hegyi@88
|
345 |
case '(':
|
hegyi@88
|
346 |
pr=prev_br+10000;
|
hegyi@88
|
347 |
prev_br=pr;
|
hegyi@88
|
348 |
prevmult=false;
|
hegyi@88
|
349 |
put_in_string=false;
|
hegyi@88
|
350 |
break;
|
hegyi@88
|
351 |
case ')':
|
hegyi@88
|
352 |
pr=prev_br-10000;
|
hegyi@88
|
353 |
prev_br=pr;
|
hegyi@88
|
354 |
prevmult=false;
|
hegyi@88
|
355 |
put_in_string=false;
|
hegyi@88
|
356 |
break;
|
hegyi@88
|
357 |
case '+':
|
hegyi@88
|
358 |
case '-':
|
hegyi@88
|
359 |
if(prevmult)
|
hegyi@88
|
360 |
{
|
hegyi@88
|
361 |
pr=prev_change;
|
hegyi@88
|
362 |
}
|
hegyi@88
|
363 |
p[counter]=pr;
|
hegyi@88
|
364 |
pr-=100;
|
hegyi@88
|
365 |
|
hegyi@88
|
366 |
prevmult=false;
|
hegyi@88
|
367 |
break;
|
hegyi@88
|
368 |
case '/':
|
hegyi@88
|
369 |
case '*':
|
hegyi@88
|
370 |
if(!prevmult)
|
hegyi@88
|
371 |
{
|
hegyi@88
|
372 |
prev_change=pr;
|
hegyi@88
|
373 |
pr+=200;
|
hegyi@88
|
374 |
pr-=1;
|
hegyi@88
|
375 |
}
|
hegyi@88
|
376 |
p[counter]=pr;
|
hegyi@88
|
377 |
pr-=1;
|
hegyi@88
|
378 |
prevmult=true;
|
hegyi@88
|
379 |
break;
|
hegyi@88
|
380 |
default:
|
hegyi@88
|
381 |
p[counter]=65000;
|
hegyi@88
|
382 |
break;
|
hegyi@88
|
383 |
}
|
hegyi@88
|
384 |
if(put_in_string)
|
hegyi@88
|
385 |
{
|
hegyi@88
|
386 |
counter++;
|
hegyi@88
|
387 |
p.resize(counter+1);
|
hegyi@88
|
388 |
comm_nobr=comm_nobr+command[i];
|
hegyi@88
|
389 |
}
|
hegyi@88
|
390 |
}
|
hegyi@88
|
391 |
|
hegyi@88
|
392 |
tree_node * root=weightedString2Tree(comm_nobr, p, 0);
|
hegyi@88
|
393 |
|
hegyi@88
|
394 |
std::string polishform=postOrder(root);
|
hegyi@88
|
395 |
|
hegyi@117
|
396 |
deleteTree(root);
|
hegyi@117
|
397 |
|
hegyi@88
|
398 |
return polishform;
|
hegyi@88
|
399 |
}
|
hegyi@88
|
400 |
return "";
|
hegyi@88
|
401 |
}
|
hegyi@88
|
402 |
|
hegyi@117
|
403 |
void NewMapWin::deleteTree(NewMapWin::tree_node * node)
|
hegyi@117
|
404 |
{
|
hegyi@117
|
405 |
if(node->left_child!=NULL)
|
hegyi@117
|
406 |
{
|
hegyi@117
|
407 |
deleteTree(node->left_child);
|
hegyi@117
|
408 |
}
|
hegyi@117
|
409 |
if(node->right_child!=NULL)
|
hegyi@117
|
410 |
{
|
hegyi@117
|
411 |
deleteTree(node->right_child);
|
hegyi@117
|
412 |
}
|
hegyi@117
|
413 |
delete node;
|
hegyi@117
|
414 |
}
|
hegyi@117
|
415 |
|
hegyi@88
|
416 |
NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector<unsigned int> & p, int offset)
|
hegyi@88
|
417 |
{
|
hegyi@89
|
418 |
unsigned int min=p[offset];
|
hegyi@88
|
419 |
int minplace=0;
|
hegyi@88
|
420 |
for(int i=0;i<(int)to_tree.size();i++)
|
hegyi@88
|
421 |
{
|
hegyi@88
|
422 |
if(min>p[offset+i])
|
hegyi@88
|
423 |
{
|
hegyi@88
|
424 |
min=p[offset+i];
|
hegyi@88
|
425 |
minplace=i;
|
hegyi@88
|
426 |
}
|
hegyi@88
|
427 |
}
|
hegyi@88
|
428 |
tree_node * act_node=new tree_node;
|
hegyi@88
|
429 |
act_node->ch=to_tree[minplace];
|
hegyi@88
|
430 |
if(to_tree.size()>=3)
|
hegyi@88
|
431 |
{
|
hegyi@88
|
432 |
act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
|
hegyi@88
|
433 |
act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
|
hegyi@88
|
434 |
}
|
hegyi@88
|
435 |
else
|
hegyi@88
|
436 |
{
|
hegyi@88
|
437 |
act_node->left_child=NULL;
|
hegyi@88
|
438 |
act_node->right_child=NULL;
|
hegyi@88
|
439 |
}
|
hegyi@88
|
440 |
return act_node;
|
hegyi@88
|
441 |
}
|
hegyi@88
|
442 |
|
hegyi@88
|
443 |
std::string NewMapWin::postOrder(tree_node * subtree)
|
hegyi@88
|
444 |
{
|
hegyi@88
|
445 |
std::string subtree_to_string;
|
hegyi@88
|
446 |
if(subtree->left_child)
|
hegyi@88
|
447 |
{
|
hegyi@88
|
448 |
subtree_to_string=postOrder(subtree->left_child);
|
hegyi@88
|
449 |
}
|
hegyi@88
|
450 |
if(subtree->right_child)
|
hegyi@88
|
451 |
{
|
hegyi@88
|
452 |
subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
|
hegyi@88
|
453 |
}
|
hegyi@88
|
454 |
subtree_to_string=subtree_to_string+subtree->ch;
|
hegyi@88
|
455 |
return subtree_to_string;
|
hegyi@88
|
456 |
}
|
hegyi@88
|
457 |
|
hegyi@88
|
458 |
bool NewMapWin::validVariable(std::string variable, bool itisedge)
|
hegyi@88
|
459 |
{
|
hegyi@88
|
460 |
bool cancel;
|
hegyi@88
|
461 |
//is it mapname?
|
hegyi@88
|
462 |
if(itisedge)
|
hegyi@88
|
463 |
{
|
hegyi@96
|
464 |
cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end());
|
hegyi@88
|
465 |
}
|
hegyi@88
|
466 |
else
|
hegyi@88
|
467 |
{
|
hegyi@96
|
468 |
cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end());
|
hegyi@88
|
469 |
}
|
hegyi@88
|
470 |
//maybe it is number
|
hegyi@88
|
471 |
int point_num=0;
|
hegyi@88
|
472 |
if(cancel)
|
hegyi@88
|
473 |
{
|
hegyi@88
|
474 |
cancel=false;
|
hegyi@88
|
475 |
for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
|
hegyi@88
|
476 |
{
|
hegyi@88
|
477 |
if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
|
hegyi@88
|
478 |
{
|
hegyi@88
|
479 |
cancel=true;
|
hegyi@88
|
480 |
}
|
hegyi@88
|
481 |
else
|
hegyi@88
|
482 |
{
|
hegyi@88
|
483 |
if(variable[j]=='.')
|
hegyi@88
|
484 |
{
|
hegyi@88
|
485 |
point_num++;
|
hegyi@88
|
486 |
if(point_num>1)
|
hegyi@88
|
487 |
{
|
hegyi@88
|
488 |
cancel=true;
|
hegyi@88
|
489 |
}
|
hegyi@88
|
490 |
}
|
hegyi@88
|
491 |
}
|
hegyi@88
|
492 |
}
|
hegyi@88
|
493 |
}
|
hegyi@88
|
494 |
if(cancel)
|
hegyi@88
|
495 |
{
|
hegyi@88
|
496 |
return false;
|
hegyi@88
|
497 |
}
|
hegyi@88
|
498 |
return true;
|
hegyi@88
|
499 |
}
|