hegyi@1
|
1 |
/* -*- C++ -*-
|
hegyi@1
|
2 |
*
|
hegyi@1
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
hegyi@1
|
4 |
*
|
hegyi@1
|
5 |
* Copyright (C) 2003-2006
|
hegyi@1
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
hegyi@1
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
hegyi@1
|
8 |
*
|
hegyi@1
|
9 |
* Permission to use, modify and distribute this software is granted
|
hegyi@1
|
10 |
* provided that this copyright notice appears in all copies. For
|
hegyi@1
|
11 |
* precise terms see the accompanying LICENSE file.
|
hegyi@1
|
12 |
*
|
hegyi@1
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
hegyi@1
|
14 |
* express or implied, and with no claim as to its suitability for any
|
hegyi@1
|
15 |
* purpose.
|
hegyi@1
|
16 |
*
|
hegyi@1
|
17 |
*/
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#include <new_map_win.h>
|
hegyi@1
|
20 |
#include <nbtab.h>
|
hegyi@1
|
21 |
#include <mapstorage.h>
|
hegyi@1
|
22 |
|
hegyi@1
|
23 |
bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
|
hegyi@1
|
24 |
{
|
hegyi@1
|
25 |
if(e->keyval==GDK_Escape)
|
hegyi@1
|
26 |
{
|
hegyi@1
|
27 |
hide();
|
hegyi@1
|
28 |
}
|
hegyi@1
|
29 |
return true;
|
hegyi@1
|
30 |
}
|
hegyi@1
|
31 |
|
hegyi@1
|
32 |
NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisarc, bool arcnode, MapType type):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),arc("Create ArcMap"),map_type(type)
|
hegyi@1
|
33 |
{
|
hegyi@1
|
34 |
set_default_size(200, 50);
|
hegyi@1
|
35 |
|
hegyi@1
|
36 |
signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
|
hegyi@1
|
37 |
|
hegyi@1
|
38 |
Gtk::VBox * vbox=get_vbox();
|
hegyi@1
|
39 |
|
hegyi@1
|
40 |
//entries
|
hegyi@1
|
41 |
table=new Gtk::Table(5, 2, false);
|
hegyi@1
|
42 |
|
hegyi@1
|
43 |
label=new Gtk::Label;
|
hegyi@1
|
44 |
label->set_text("Name of new map:");
|
hegyi@1
|
45 |
name.set_text("");
|
hegyi@1
|
46 |
|
hegyi@1
|
47 |
(*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
48 |
(*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
49 |
|
hegyi@1
|
50 |
lblType.set_label("Element type:");
|
hegyi@1
|
51 |
if (map_type & NUM)
|
hegyi@1
|
52 |
cbType.append_text("Numeric");
|
hegyi@1
|
53 |
if (map_type & STR)
|
hegyi@1
|
54 |
cbType.append_text("String");
|
hegyi@1
|
55 |
cbType.set_active(0);
|
hegyi@1
|
56 |
|
hegyi@1
|
57 |
(*table).attach(lblType,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
58 |
(*table).attach(cbType, 1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
59 |
|
hegyi@1
|
60 |
label=new Gtk::Label;
|
hegyi@1
|
61 |
label->set_text("Default value in the map:");
|
hegyi@1
|
62 |
default_value.set_text("0");
|
hegyi@1
|
63 |
|
hegyi@1
|
64 |
(*table).attach(*label,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
65 |
(*table).attach(default_value,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
66 |
|
hegyi@1
|
67 |
//node vs. arc map selector
|
hegyi@1
|
68 |
Gtk::RadioButton::Group group = node.get_group();
|
hegyi@1
|
69 |
arc.set_group(group);
|
hegyi@1
|
70 |
|
hegyi@1
|
71 |
if(arcnode)
|
hegyi@1
|
72 |
{
|
hegyi@1
|
73 |
(*table).attach(node,0,1,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
74 |
(*table).attach(arc,1,2,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
75 |
}
|
hegyi@1
|
76 |
else
|
hegyi@1
|
77 |
{
|
hegyi@1
|
78 |
if(itisarc)
|
hegyi@1
|
79 |
{
|
hegyi@1
|
80 |
arc.set_active();
|
hegyi@1
|
81 |
}
|
hegyi@1
|
82 |
else
|
hegyi@1
|
83 |
{
|
hegyi@1
|
84 |
node.set_active();
|
hegyi@1
|
85 |
}
|
hegyi@1
|
86 |
}
|
hegyi@1
|
87 |
|
hegyi@1
|
88 |
(*table).attach(lblErrorMsg,0,2,4,5,Gtk::SHRINK,Gtk::SHRINK,10,3);
|
hegyi@1
|
89 |
|
hegyi@1
|
90 |
vbox->pack_start(*table);
|
hegyi@1
|
91 |
|
hegyi@1
|
92 |
//OK button
|
hegyi@1
|
93 |
add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
hegyi@1
|
94 |
|
hegyi@1
|
95 |
show_all_children();
|
hegyi@1
|
96 |
|
hegyi@1
|
97 |
}
|
hegyi@1
|
98 |
|
hegyi@1
|
99 |
void NewMapWin::setErrorMsg(const Glib::ustring& msg)
|
hegyi@1
|
100 |
{
|
hegyi@1
|
101 |
lblErrorMsg.set_markup("<i><small>" + msg + "</small></i>");
|
hegyi@1
|
102 |
}
|
hegyi@1
|
103 |
|
hegyi@1
|
104 |
std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform, bool itisarc)
|
hegyi@1
|
105 |
{
|
hegyi@1
|
106 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
107 |
|
hegyi@1
|
108 |
std::vector<double>* ret = new std::vector<double>;
|
hegyi@1
|
109 |
std::stack<double> polishstack;
|
hegyi@1
|
110 |
|
hegyi@1
|
111 |
if (itisarc)
|
hegyi@1
|
112 |
{
|
hegyi@1
|
113 |
for(ArcIt k(ms.digraph); k!=INVALID; ++k)
|
hegyi@1
|
114 |
{
|
hegyi@1
|
115 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@1
|
116 |
{
|
hegyi@1
|
117 |
double op1=0, op2=0;
|
hegyi@1
|
118 |
bool operation=true;
|
hegyi@1
|
119 |
switch(polishform[i])
|
hegyi@1
|
120 |
{
|
hegyi@1
|
121 |
case '+':
|
hegyi@1
|
122 |
case '-':
|
hegyi@1
|
123 |
case '/':
|
hegyi@1
|
124 |
case '*':
|
hegyi@1
|
125 |
op1=polishstack.top();
|
hegyi@1
|
126 |
polishstack.pop();
|
hegyi@1
|
127 |
op2=polishstack.top();
|
hegyi@1
|
128 |
polishstack.pop();
|
hegyi@1
|
129 |
break;
|
hegyi@1
|
130 |
default:
|
hegyi@1
|
131 |
//substitute variable
|
hegyi@1
|
132 |
std::vector<std::string> maps = ms.getArcMapList(NUM);
|
hegyi@1
|
133 |
bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
|
hegyi@1
|
134 |
if(itisvar)
|
hegyi@1
|
135 |
{
|
hegyi@1
|
136 |
polishstack.push(ms.get(ch2var[ polishform[i] ], k));
|
hegyi@1
|
137 |
}
|
hegyi@1
|
138 |
else
|
hegyi@1
|
139 |
{
|
hegyi@1
|
140 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@1
|
141 |
}
|
hegyi@1
|
142 |
operation=false;
|
hegyi@1
|
143 |
break;
|
hegyi@1
|
144 |
}
|
hegyi@1
|
145 |
if(operation)
|
hegyi@1
|
146 |
{
|
hegyi@1
|
147 |
double res;
|
hegyi@1
|
148 |
switch(polishform[i])
|
hegyi@1
|
149 |
{
|
hegyi@1
|
150 |
case '+':
|
hegyi@1
|
151 |
res=op1+op2;
|
hegyi@1
|
152 |
break;
|
hegyi@1
|
153 |
case '-':
|
hegyi@1
|
154 |
res=op2-op1;
|
hegyi@1
|
155 |
break;
|
hegyi@1
|
156 |
case '/':
|
hegyi@1
|
157 |
res=op2/op1;
|
hegyi@1
|
158 |
break;
|
hegyi@1
|
159 |
case '*':
|
hegyi@1
|
160 |
res=op1*op2;
|
hegyi@1
|
161 |
break;
|
hegyi@1
|
162 |
default:
|
hegyi@1
|
163 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@1
|
164 |
break;
|
hegyi@1
|
165 |
}
|
hegyi@1
|
166 |
polishstack.push(res);
|
hegyi@1
|
167 |
}
|
hegyi@1
|
168 |
}//foreach letter in polishform
|
hegyi@1
|
169 |
ret->push_back(polishstack.top());
|
hegyi@1
|
170 |
}//foreach arc
|
hegyi@1
|
171 |
}
|
hegyi@1
|
172 |
else
|
hegyi@1
|
173 |
{
|
hegyi@1
|
174 |
for(NodeIt k(ms.digraph); k!=INVALID; ++k)
|
hegyi@1
|
175 |
{
|
hegyi@1
|
176 |
for(int i=0;i<(int)polishform.size();i++)
|
hegyi@1
|
177 |
{
|
hegyi@1
|
178 |
double op1=0, op2=0;
|
hegyi@1
|
179 |
bool operation=true;
|
hegyi@1
|
180 |
switch(polishform[i])
|
hegyi@1
|
181 |
{
|
hegyi@1
|
182 |
case '+':
|
hegyi@1
|
183 |
case '-':
|
hegyi@1
|
184 |
case '/':
|
hegyi@1
|
185 |
case '*':
|
hegyi@1
|
186 |
op1=polishstack.top();
|
hegyi@1
|
187 |
polishstack.pop();
|
hegyi@1
|
188 |
op2=polishstack.top();
|
hegyi@1
|
189 |
polishstack.pop();
|
hegyi@1
|
190 |
break;
|
hegyi@1
|
191 |
default:
|
hegyi@1
|
192 |
//substitute variable
|
hegyi@1
|
193 |
std::vector<std::string> maps = ms.getNodeMapList(NUM);
|
hegyi@1
|
194 |
bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
|
hegyi@1
|
195 |
if(itisvar)
|
hegyi@1
|
196 |
{
|
hegyi@1
|
197 |
polishstack.push(ms.get(ch2var[ polishform[i] ], k));
|
hegyi@1
|
198 |
}
|
hegyi@1
|
199 |
else
|
hegyi@1
|
200 |
{
|
hegyi@1
|
201 |
polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
|
hegyi@1
|
202 |
}
|
hegyi@1
|
203 |
operation=false;
|
hegyi@1
|
204 |
break;
|
hegyi@1
|
205 |
}
|
hegyi@1
|
206 |
if(operation)
|
hegyi@1
|
207 |
{
|
hegyi@1
|
208 |
double res;
|
hegyi@1
|
209 |
switch(polishform[i])
|
hegyi@1
|
210 |
{
|
hegyi@1
|
211 |
case '+':
|
hegyi@1
|
212 |
res=op1+op2;
|
hegyi@1
|
213 |
break;
|
hegyi@1
|
214 |
case '-':
|
hegyi@1
|
215 |
res=op2-op1;
|
hegyi@1
|
216 |
break;
|
hegyi@1
|
217 |
case '/':
|
hegyi@1
|
218 |
res=op2/op1;
|
hegyi@1
|
219 |
break;
|
hegyi@1
|
220 |
case '*':
|
hegyi@1
|
221 |
res=op1*op2;
|
hegyi@1
|
222 |
break;
|
hegyi@1
|
223 |
default:
|
hegyi@1
|
224 |
std::cout << "How could we get here?" << std::endl;
|
hegyi@1
|
225 |
break;
|
hegyi@1
|
226 |
}
|
hegyi@1
|
227 |
polishstack.push(res);
|
hegyi@1
|
228 |
}
|
hegyi@1
|
229 |
}//foreach letter in polishform
|
hegyi@1
|
230 |
ret->push_back(polishstack.top());
|
hegyi@1
|
231 |
}//foreach arc
|
hegyi@1
|
232 |
}
|
hegyi@1
|
233 |
return ret;
|
hegyi@1
|
234 |
}
|
hegyi@1
|
235 |
|
hegyi@1
|
236 |
void NewMapWin::on_response(int response_id)
|
hegyi@1
|
237 |
{
|
hegyi@1
|
238 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
239 |
|
hegyi@1
|
240 |
if(response_id==Gtk::RESPONSE_OK)
|
hegyi@1
|
241 |
{
|
hegyi@1
|
242 |
std::string map_name = name.get_text();
|
hegyi@1
|
243 |
std::string def_val = default_value.get_text();
|
hegyi@1
|
244 |
|
hegyi@1
|
245 |
if (map_name.empty())
|
hegyi@1
|
246 |
{
|
hegyi@1
|
247 |
setErrorMsg("No map name given.");
|
hegyi@1
|
248 |
return;
|
hegyi@1
|
249 |
}
|
hegyi@1
|
250 |
|
hegyi@1
|
251 |
// check whether the map already exists
|
hegyi@1
|
252 |
if (arc.get_active())
|
hegyi@1
|
253 |
{
|
hegyi@1
|
254 |
if (ms.arcMapExists(map_name))
|
hegyi@1
|
255 |
{
|
hegyi@1
|
256 |
setErrorMsg("Map '" + map_name + "' already exists.");
|
hegyi@1
|
257 |
return;
|
hegyi@1
|
258 |
}
|
hegyi@1
|
259 |
}
|
hegyi@1
|
260 |
else
|
hegyi@1
|
261 |
{
|
hegyi@1
|
262 |
if (ms.nodeMapExists(map_name))
|
hegyi@1
|
263 |
{
|
hegyi@1
|
264 |
setErrorMsg("Map '" + map_name + "' already exists.");
|
hegyi@1
|
265 |
return;
|
hegyi@1
|
266 |
}
|
hegyi@1
|
267 |
}
|
hegyi@1
|
268 |
|
hegyi@1
|
269 |
Glib::ustring text = cbType.get_active_text();
|
hegyi@1
|
270 |
if (text == "Numeric")
|
hegyi@1
|
271 |
{
|
hegyi@1
|
272 |
double d;
|
hegyi@1
|
273 |
char *endptr;
|
hegyi@1
|
274 |
d = strtod(def_val.c_str(), &endptr);
|
hegyi@1
|
275 |
if (def_val.c_str() + def_val.length() == endptr)
|
hegyi@1
|
276 |
{
|
hegyi@1
|
277 |
// the full string was a number
|
hegyi@1
|
278 |
if (arc.get_active())
|
hegyi@1
|
279 |
ms.createArcMap(map_name, MapValue::NUMERIC,
|
hegyi@1
|
280 |
MapValue(d));
|
hegyi@1
|
281 |
else
|
hegyi@1
|
282 |
ms.createNodeMap(map_name, MapValue::NUMERIC,
|
hegyi@1
|
283 |
MapValue(d));
|
hegyi@1
|
284 |
}
|
hegyi@1
|
285 |
else
|
hegyi@1
|
286 |
{
|
hegyi@1
|
287 |
// let't try to evaluate the string as an arithmetic expression
|
hegyi@1
|
288 |
std::string polishform =
|
hegyi@1
|
289 |
string2Polishform(def_val, arc.get_active());
|
hegyi@1
|
290 |
if (polishform.empty())
|
hegyi@1
|
291 |
return;
|
hegyi@1
|
292 |
std::vector<double>* values =
|
hegyi@1
|
293 |
evaluate_expr(polishform, arc.get_active());
|
hegyi@1
|
294 |
if (arc.get_active())
|
hegyi@1
|
295 |
{
|
hegyi@1
|
296 |
ms.createArcMap(map_name, MapValue::NUMERIC,
|
hegyi@1
|
297 |
MapValue(0.0));
|
hegyi@1
|
298 |
std::vector<double>::const_iterator vit = values->begin();
|
hegyi@1
|
299 |
for (ArcIt it(ms.digraph); it != INVALID; ++it)
|
hegyi@1
|
300 |
{
|
hegyi@1
|
301 |
ms.set(map_name, it, MapValue(*vit));
|
hegyi@1
|
302 |
++vit;
|
hegyi@1
|
303 |
}
|
hegyi@1
|
304 |
}
|
hegyi@1
|
305 |
else
|
hegyi@1
|
306 |
{
|
hegyi@1
|
307 |
ms.createNodeMap(map_name, MapValue::NUMERIC,
|
hegyi@1
|
308 |
MapValue(0.0));
|
hegyi@1
|
309 |
std::vector<double>::const_iterator vit = values->begin();
|
hegyi@1
|
310 |
for (NodeIt it(ms.digraph); it != INVALID; ++it)
|
hegyi@1
|
311 |
{
|
hegyi@1
|
312 |
ms.set(map_name, it, MapValue(*vit));
|
hegyi@1
|
313 |
++vit;
|
hegyi@1
|
314 |
}
|
hegyi@1
|
315 |
}
|
hegyi@1
|
316 |
delete values;
|
hegyi@1
|
317 |
}
|
hegyi@1
|
318 |
}
|
hegyi@1
|
319 |
else if (text == "String")
|
hegyi@1
|
320 |
{
|
hegyi@1
|
321 |
if (arc.get_active())
|
hegyi@1
|
322 |
ms.createArcMap(map_name, MapValue::STRING,
|
hegyi@1
|
323 |
MapValue(def_val));
|
hegyi@1
|
324 |
else
|
hegyi@1
|
325 |
ms.createNodeMap(map_name, MapValue::STRING,
|
hegyi@1
|
326 |
MapValue(def_val));
|
hegyi@1
|
327 |
}
|
hegyi@1
|
328 |
|
hegyi@1
|
329 |
name.set_text("");
|
hegyi@1
|
330 |
default_value.set_text("0");
|
hegyi@1
|
331 |
arc.show();
|
hegyi@1
|
332 |
node.show();
|
hegyi@1
|
333 |
hide();
|
hegyi@1
|
334 |
}
|
hegyi@1
|
335 |
}
|
hegyi@1
|
336 |
|
hegyi@1
|
337 |
|
hegyi@1
|
338 |
std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisarc)
|
hegyi@1
|
339 |
{
|
hegyi@1
|
340 |
bool valid_entry=true;
|
hegyi@1
|
341 |
|
hegyi@1
|
342 |
std::map<std::string, int> str2i;
|
hegyi@1
|
343 |
|
hegyi@1
|
344 |
std::string command;
|
hegyi@1
|
345 |
|
hegyi@1
|
346 |
std::string variable;
|
hegyi@1
|
347 |
|
hegyi@1
|
348 |
char index='a';
|
hegyi@1
|
349 |
|
hegyi@1
|
350 |
for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
|
hegyi@1
|
351 |
{
|
hegyi@1
|
352 |
switch(rawcommand[i])
|
hegyi@1
|
353 |
{
|
hegyi@1
|
354 |
case '+':
|
hegyi@1
|
355 |
case '-':
|
hegyi@1
|
356 |
case '*':
|
hegyi@1
|
357 |
case '/':
|
hegyi@1
|
358 |
case ')':
|
hegyi@1
|
359 |
case '(':
|
hegyi@1
|
360 |
if(!variable.empty())
|
hegyi@1
|
361 |
{
|
hegyi@1
|
362 |
valid_entry=validVariable(variable, itisarc);
|
hegyi@1
|
363 |
ch2var[index]=variable;
|
hegyi@1
|
364 |
command+=index;
|
hegyi@1
|
365 |
index++;
|
hegyi@1
|
366 |
variable.erase(0,variable.size());
|
hegyi@1
|
367 |
}
|
hegyi@1
|
368 |
command+=rawcommand[i];
|
hegyi@1
|
369 |
break;
|
hegyi@1
|
370 |
default:
|
hegyi@1
|
371 |
variable+=rawcommand[i];
|
hegyi@1
|
372 |
break;
|
hegyi@1
|
373 |
}
|
hegyi@1
|
374 |
}
|
hegyi@1
|
375 |
|
hegyi@1
|
376 |
if(!variable.empty()&&valid_entry)
|
hegyi@1
|
377 |
{
|
hegyi@1
|
378 |
valid_entry=validVariable(variable, itisarc);
|
hegyi@1
|
379 |
ch2var[index]=variable;
|
hegyi@1
|
380 |
command+=index;
|
hegyi@1
|
381 |
index++;
|
hegyi@1
|
382 |
variable.erase(0,variable.size());
|
hegyi@1
|
383 |
}
|
hegyi@1
|
384 |
|
hegyi@1
|
385 |
if(valid_entry)
|
hegyi@1
|
386 |
{
|
hegyi@1
|
387 |
unsigned int pr=10000;
|
hegyi@1
|
388 |
bool prevmult=false;
|
hegyi@1
|
389 |
unsigned int prev_change=pr;
|
hegyi@1
|
390 |
unsigned int prev_br=pr;
|
hegyi@1
|
391 |
int counter=0;
|
hegyi@1
|
392 |
std::string comm_nobr="";
|
hegyi@1
|
393 |
std::vector<unsigned int> p;
|
hegyi@1
|
394 |
p.resize(counter+1);
|
hegyi@1
|
395 |
|
hegyi@1
|
396 |
//limits
|
hegyi@1
|
397 |
//6 brackets embedded
|
hegyi@1
|
398 |
//100 operation in a row from the same priority
|
hegyi@1
|
399 |
|
hegyi@1
|
400 |
for(int i=0;i<(int)command.size();i++)
|
hegyi@1
|
401 |
{
|
hegyi@1
|
402 |
bool put_in_string=true;
|
hegyi@1
|
403 |
switch(command[i])
|
hegyi@1
|
404 |
{
|
hegyi@1
|
405 |
case '(':
|
hegyi@1
|
406 |
pr=prev_br+10000;
|
hegyi@1
|
407 |
prev_br=pr;
|
hegyi@1
|
408 |
prevmult=false;
|
hegyi@1
|
409 |
put_in_string=false;
|
hegyi@1
|
410 |
break;
|
hegyi@1
|
411 |
case ')':
|
hegyi@1
|
412 |
pr=prev_br-10000;
|
hegyi@1
|
413 |
prev_br=pr;
|
hegyi@1
|
414 |
prevmult=false;
|
hegyi@1
|
415 |
put_in_string=false;
|
hegyi@1
|
416 |
break;
|
hegyi@1
|
417 |
case '+':
|
hegyi@1
|
418 |
case '-':
|
hegyi@1
|
419 |
if(prevmult)
|
hegyi@1
|
420 |
{
|
hegyi@1
|
421 |
pr=prev_change;
|
hegyi@1
|
422 |
}
|
hegyi@1
|
423 |
p[counter]=pr;
|
hegyi@1
|
424 |
pr-=100;
|
hegyi@1
|
425 |
|
hegyi@1
|
426 |
prevmult=false;
|
hegyi@1
|
427 |
break;
|
hegyi@1
|
428 |
case '/':
|
hegyi@1
|
429 |
case '*':
|
hegyi@1
|
430 |
if(!prevmult)
|
hegyi@1
|
431 |
{
|
hegyi@1
|
432 |
prev_change=pr;
|
hegyi@1
|
433 |
pr+=200;
|
hegyi@1
|
434 |
pr-=1;
|
hegyi@1
|
435 |
}
|
hegyi@1
|
436 |
p[counter]=pr;
|
hegyi@1
|
437 |
pr-=1;
|
hegyi@1
|
438 |
prevmult=true;
|
hegyi@1
|
439 |
break;
|
hegyi@1
|
440 |
default:
|
hegyi@1
|
441 |
p[counter]=65000;
|
hegyi@1
|
442 |
break;
|
hegyi@1
|
443 |
}
|
hegyi@1
|
444 |
if(put_in_string)
|
hegyi@1
|
445 |
{
|
hegyi@1
|
446 |
counter++;
|
hegyi@1
|
447 |
p.resize(counter+1);
|
hegyi@1
|
448 |
comm_nobr=comm_nobr+command[i];
|
hegyi@1
|
449 |
}
|
hegyi@1
|
450 |
}
|
hegyi@1
|
451 |
|
hegyi@1
|
452 |
tree_node * root=weightedString2Tree(comm_nobr, p, 0);
|
hegyi@1
|
453 |
|
hegyi@1
|
454 |
std::string polishform=postOrder(root);
|
hegyi@1
|
455 |
|
hegyi@1
|
456 |
deleteTree(root);
|
hegyi@1
|
457 |
|
hegyi@1
|
458 |
return polishform;
|
hegyi@1
|
459 |
}
|
hegyi@1
|
460 |
return "";
|
hegyi@1
|
461 |
}
|
hegyi@1
|
462 |
|
hegyi@1
|
463 |
void NewMapWin::deleteTree(NewMapWin::tree_node * node)
|
hegyi@1
|
464 |
{
|
hegyi@1
|
465 |
if(node->left_child!=NULL)
|
hegyi@1
|
466 |
{
|
hegyi@1
|
467 |
deleteTree(node->left_child);
|
hegyi@1
|
468 |
}
|
hegyi@1
|
469 |
if(node->right_child!=NULL)
|
hegyi@1
|
470 |
{
|
hegyi@1
|
471 |
deleteTree(node->right_child);
|
hegyi@1
|
472 |
}
|
hegyi@1
|
473 |
delete node;
|
hegyi@1
|
474 |
}
|
hegyi@1
|
475 |
|
hegyi@1
|
476 |
NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector<unsigned int> & p, int offset)
|
hegyi@1
|
477 |
{
|
hegyi@1
|
478 |
unsigned int min=p[offset];
|
hegyi@1
|
479 |
int minplace=0;
|
hegyi@1
|
480 |
for(int i=0;i<(int)to_tree.size();i++)
|
hegyi@1
|
481 |
{
|
hegyi@1
|
482 |
if(min>p[offset+i])
|
hegyi@1
|
483 |
{
|
hegyi@1
|
484 |
min=p[offset+i];
|
hegyi@1
|
485 |
minplace=i;
|
hegyi@1
|
486 |
}
|
hegyi@1
|
487 |
}
|
hegyi@1
|
488 |
tree_node * act_node=new tree_node;
|
hegyi@1
|
489 |
act_node->ch=to_tree[minplace];
|
hegyi@1
|
490 |
if(to_tree.size()>=3)
|
hegyi@1
|
491 |
{
|
hegyi@1
|
492 |
act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
|
hegyi@1
|
493 |
act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
|
hegyi@1
|
494 |
}
|
hegyi@1
|
495 |
else
|
hegyi@1
|
496 |
{
|
hegyi@1
|
497 |
act_node->left_child=NULL;
|
hegyi@1
|
498 |
act_node->right_child=NULL;
|
hegyi@1
|
499 |
}
|
hegyi@1
|
500 |
return act_node;
|
hegyi@1
|
501 |
}
|
hegyi@1
|
502 |
|
hegyi@1
|
503 |
std::string NewMapWin::postOrder(tree_node * subtree)
|
hegyi@1
|
504 |
{
|
hegyi@1
|
505 |
std::string subtree_to_string;
|
hegyi@1
|
506 |
if(subtree->left_child)
|
hegyi@1
|
507 |
{
|
hegyi@1
|
508 |
subtree_to_string=postOrder(subtree->left_child);
|
hegyi@1
|
509 |
}
|
hegyi@1
|
510 |
if(subtree->right_child)
|
hegyi@1
|
511 |
{
|
hegyi@1
|
512 |
subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
|
hegyi@1
|
513 |
}
|
hegyi@1
|
514 |
subtree_to_string=subtree_to_string+subtree->ch;
|
hegyi@1
|
515 |
return subtree_to_string;
|
hegyi@1
|
516 |
}
|
hegyi@1
|
517 |
|
hegyi@1
|
518 |
bool NewMapWin::validVariable(std::string variable, bool itisarc)
|
hegyi@1
|
519 |
{
|
hegyi@1
|
520 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
521 |
|
hegyi@1
|
522 |
bool cancel;
|
hegyi@1
|
523 |
//is it mapname?
|
hegyi@1
|
524 |
if(itisarc)
|
hegyi@1
|
525 |
{
|
hegyi@1
|
526 |
std::vector<std::string> arc_maps =
|
hegyi@1
|
527 |
ms.getArcMapList(NUM);
|
hegyi@1
|
528 |
cancel=(std::find(arc_maps.begin(), arc_maps.end(), variable)==arc_maps.end());
|
hegyi@1
|
529 |
}
|
hegyi@1
|
530 |
else
|
hegyi@1
|
531 |
{
|
hegyi@1
|
532 |
std::vector<std::string> node_maps =
|
hegyi@1
|
533 |
ms.getNodeMapList(NUM);
|
hegyi@1
|
534 |
cancel=(std::find(node_maps.begin(), node_maps.end(), variable)==node_maps.end());
|
hegyi@1
|
535 |
}
|
hegyi@1
|
536 |
//maybe it is number
|
hegyi@1
|
537 |
int point_num=0;
|
hegyi@1
|
538 |
if(cancel)
|
hegyi@1
|
539 |
{
|
hegyi@1
|
540 |
cancel=false;
|
hegyi@1
|
541 |
for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
|
hegyi@1
|
542 |
{
|
hegyi@1
|
543 |
if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
|
hegyi@1
|
544 |
{
|
hegyi@1
|
545 |
cancel=true;
|
hegyi@1
|
546 |
}
|
hegyi@1
|
547 |
else
|
hegyi@1
|
548 |
{
|
hegyi@1
|
549 |
if(variable[j]=='.')
|
hegyi@1
|
550 |
{
|
hegyi@1
|
551 |
point_num++;
|
hegyi@1
|
552 |
if(point_num>1)
|
hegyi@1
|
553 |
{
|
hegyi@1
|
554 |
cancel=true;
|
hegyi@1
|
555 |
}
|
hegyi@1
|
556 |
}
|
hegyi@1
|
557 |
}
|
hegyi@1
|
558 |
}
|
hegyi@1
|
559 |
}
|
hegyi@1
|
560 |
if(cancel)
|
hegyi@1
|
561 |
{
|
hegyi@1
|
562 |
return false;
|
hegyi@1
|
563 |
}
|
hegyi@1
|
564 |
return true;
|
hegyi@1
|
565 |
}
|