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