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