35 (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); |
35 (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); |
36 |
36 |
37 //node vs. edge map selector |
37 //node vs. edge map selector |
38 Gtk::RadioButton::Group group = node.get_group(); |
38 Gtk::RadioButton::Group group = node.get_group(); |
39 edge.set_group(group); |
39 edge.set_group(group); |
40 |
40 |
41 (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); |
41 if(edgenode) |
42 (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); |
42 { |
43 |
43 (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); |
44 vbox.pack_start(*table); |
44 (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|
45 } |
|
46 else |
|
47 { |
|
48 if(itisedge) |
|
49 { |
|
50 edge.set_active(); |
|
51 } |
|
52 else |
|
53 { |
|
54 node.set_active(); |
|
55 } |
|
56 } |
|
57 |
|
58 vbox->pack_start(*table); |
45 |
59 |
46 //OK button |
60 //OK button |
47 button=new Gtk::Button("OK"); |
61 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); |
48 |
|
49 button->signal_clicked().connect |
|
50 ( |
|
51 sigc::mem_fun(*this, &NewMapWin::buttonPressed) |
|
52 ); |
|
53 |
|
54 |
|
55 vbox.pack_start(*button); |
|
56 |
|
57 add(vbox); |
|
58 |
62 |
59 show_all_children(); |
63 show_all_children(); |
60 |
64 |
61 } |
65 } |
62 |
66 |
63 void NewMapWin::showByPreChoose(bool itisedge) |
67 void NewMapWin::on_response(int response_id) |
64 { |
68 { |
65 if(itisedge) |
69 if(response_id==Gtk::RESPONSE_OK) |
66 { |
70 { |
67 edge.set_active(); |
71 double def_val=0; |
68 } |
72 |
69 else |
73 //get and formulate text |
70 { |
74 std::string def_val_str=default_value.get_text(); |
71 node.set_active(); |
75 std::string polishform=string2Polishform(def_val_str,edge.get_active()); |
72 } |
76 |
73 node.hide(); |
77 //get name of text |
74 edge.hide(); |
78 std::string mapname=name.get_text(); |
75 show(); |
79 |
76 } |
80 if(!mapname.empty()&&!polishform.empty()) |
77 |
81 { |
78 void NewMapWin::buttonPressed() |
82 int abortion=0; |
79 { |
83 if(edge.get_active()) |
80 double def_val=0; |
84 { |
81 |
85 //create the new map |
82 //get and formulate text |
86 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph); |
83 std::string def_val_str=default_value.get_text(); |
87 |
84 std::string polishform=string2Polishform(def_val_str,edge.get_active()); |
88 std::stack<double> polishstack; |
85 |
|
86 //get name of text |
|
87 std::string mapname=name.get_text(); |
|
88 |
|
89 if(!mapname.empty()&&!polishform.empty()) |
|
90 { |
|
91 int abortion=0; |
|
92 if(edge.get_active()) |
|
93 { |
|
94 //create the new map |
|
95 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph); |
|
96 |
|
97 std::stack<double> polishstack; |
|
98 |
89 |
99 for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) |
90 for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) |
100 { |
91 { |
101 for(int i=0;i<(int)polishform.size();i++) |
92 for(int i=0;i<(int)polishform.size();i++) |
102 { |
|
103 double op1, op2; |
|
104 bool operation=true; |
|
105 switch(polishform[i]) |
|
106 { |
93 { |
107 case '+': |
94 double op1, op2; |
108 case '-': |
95 bool operation=true; |
109 case '/': |
|
110 case '*': |
|
111 op1=polishstack.top(); |
|
112 polishstack.pop(); |
|
113 op2=polishstack.top(); |
|
114 polishstack.pop(); |
|
115 break; |
|
116 default: |
|
117 //substitute variable |
|
118 std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage; |
|
119 bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end()); |
|
120 if(itisvar) |
|
121 { |
|
122 polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]); |
|
123 } |
|
124 else |
|
125 { |
|
126 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())]; |
|
127 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++) |
|
128 { |
|
129 def_val_ch[j]=ch2var[ polishform[i] ][j]; |
|
130 } |
|
131 polishstack.push(atof(def_val_ch)); |
|
132 } |
|
133 operation=false; |
|
134 break; |
|
135 } |
|
136 if(operation) |
|
137 { |
|
138 double res; |
|
139 switch(polishform[i]) |
96 switch(polishform[i]) |
140 { |
97 { |
141 case '+': |
98 case '+': |
142 res=op1+op2; |
|
143 break; |
|
144 case '-': |
99 case '-': |
145 res=op2-op1; |
|
146 break; |
|
147 case '/': |
100 case '/': |
148 res=op2/op1; |
|
149 break; |
|
150 case '*': |
101 case '*': |
151 res=op1*op2; |
102 op1=polishstack.top(); |
|
103 polishstack.pop(); |
|
104 op2=polishstack.top(); |
|
105 polishstack.pop(); |
152 break; |
106 break; |
153 default: |
107 default: |
154 std::cout << "How could we get here?" << std::endl; |
108 //substitute variable |
|
109 std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage; |
|
110 bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end()); |
|
111 if(itisvar) |
|
112 { |
|
113 polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]); |
|
114 } |
|
115 else |
|
116 { |
|
117 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())]; |
|
118 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++) |
|
119 { |
|
120 def_val_ch[j]=ch2var[ polishform[i] ][j]; |
|
121 } |
|
122 polishstack.push(atof(def_val_ch)); |
|
123 } |
|
124 operation=false; |
155 break; |
125 break; |
156 } |
126 } |
157 polishstack.push(res); |
127 if(operation) |
|
128 { |
|
129 double res; |
|
130 switch(polishform[i]) |
|
131 { |
|
132 case '+': |
|
133 res=op1+op2; |
|
134 break; |
|
135 case '-': |
|
136 res=op2-op1; |
|
137 break; |
|
138 case '/': |
|
139 res=op2/op1; |
|
140 break; |
|
141 case '*': |
|
142 res=op1*op2; |
|
143 break; |
|
144 default: |
|
145 std::cout << "How could we get here?" << std::endl; |
|
146 break; |
|
147 } |
|
148 polishstack.push(res); |
|
149 } |
158 } |
150 } |
159 } |
151 (*emptr)[k]=polishstack.top(); |
160 (*emptr)[k]=polishstack.top(); |
152 } |
161 } |
153 |
162 |
154 //if addition was not successful addEdgeMap returns one. |
163 //if addition was not successful addEdgeMap returns one. |
155 //cause can be that there is already a map named like the new one |
164 //cause can be that there is already a map named like the new one |
156 if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val)) |
165 if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val)) |
157 { |
166 { |
158 abortion=1; |
167 abortion=1; |
159 } |
168 } |
160 |
169 |
161 //add it to the list of the displayable maps |
170 //add it to the list of the displayable maps |
162 gdc.mapwin.registerNewEdgeMap(mapname); |
171 gdc.mapwin.registerNewEdgeMap(mapname); |
163 |
172 |
164 //display it |
173 //display it |
165 gdc.changeEdgeText(mapname); |
174 gdc.changeEdgeText(mapname); |
166 } |
175 } |
167 else //!edge.get_active() |
176 else //!edge.get_active() |
168 { |
177 { |
169 //create the new map |
178 //create the new map |
170 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph); |
179 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph); |
171 |
180 |
172 std::stack<double> polishstack; |
181 std::stack<double> polishstack; |
|
182 |
173 |
183 for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) |
174 for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) |
184 { |
175 { |
185 for(int i=0;i<(int)polishform.size();i++) |
176 for(int i=0;i<(int)polishform.size();i++) |
186 { |
|
187 double op1, op2; |
|
188 bool operation=true; |
|
189 switch(polishform[i]) |
|
190 { |
177 { |
191 case '+': |
178 double op1, op2; |
192 case '-': |
179 bool operation=true; |
193 case '/': |
|
194 case '*': |
|
195 op1=polishstack.top(); |
|
196 polishstack.pop(); |
|
197 op2=polishstack.top(); |
|
198 polishstack.pop(); |
|
199 break; |
|
200 default: |
|
201 std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage; |
|
202 bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end()); |
|
203 if(itisvar) |
|
204 { |
|
205 polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]); |
|
206 } |
|
207 else |
|
208 { |
|
209 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())]; |
|
210 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++) |
|
211 { |
|
212 def_val_ch[j]=ch2var[ polishform[i] ][j]; |
|
213 } |
|
214 polishstack.push(atof(def_val_ch)); |
|
215 } |
|
216 operation=false; |
|
217 break; |
|
218 } |
|
219 if(operation) |
|
220 { |
|
221 double res; |
|
222 switch(polishform[i]) |
180 switch(polishform[i]) |
223 { |
181 { |
224 case '+': |
182 case '+': |
225 res=op1+op2; |
|
226 break; |
|
227 case '-': |
183 case '-': |
228 res=op2-op1; |
|
229 break; |
|
230 case '/': |
184 case '/': |
231 res=op2/op1; |
|
232 break; |
|
233 case '*': |
185 case '*': |
234 res=op1*op2; |
186 op1=polishstack.top(); |
|
187 polishstack.pop(); |
|
188 op2=polishstack.top(); |
|
189 polishstack.pop(); |
235 break; |
190 break; |
236 default: |
191 default: |
237 std::cout << "How could we get here?" << std::endl; |
192 std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage; |
|
193 bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end()); |
|
194 if(itisvar) |
|
195 { |
|
196 polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]); |
|
197 } |
|
198 else |
|
199 { |
|
200 char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())]; |
|
201 for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++) |
|
202 { |
|
203 def_val_ch[j]=ch2var[ polishform[i] ][j]; |
|
204 } |
|
205 polishstack.push(atof(def_val_ch)); |
|
206 } |
|
207 operation=false; |
238 break; |
208 break; |
239 } |
209 } |
240 polishstack.push(res); |
210 if(operation) |
|
211 { |
|
212 double res; |
|
213 switch(polishform[i]) |
|
214 { |
|
215 case '+': |
|
216 res=op1+op2; |
|
217 break; |
|
218 case '-': |
|
219 res=op2-op1; |
|
220 break; |
|
221 case '/': |
|
222 res=op2/op1; |
|
223 break; |
|
224 case '*': |
|
225 res=op1*op2; |
|
226 break; |
|
227 default: |
|
228 std::cout << "How could we get here?" << std::endl; |
|
229 break; |
|
230 } |
|
231 polishstack.push(res); |
|
232 } |
241 } |
233 } |
242 } |
234 (*emptr)[k]=polishstack.top(); |
243 (*emptr)[k]=polishstack.top(); |
235 } |
244 } |
236 |
245 |
237 //if addition was not successful addNodeMap returns one. |
246 //if addition was not successful addNodeMap returns one. |
238 //cause can be that there is already a map named like the new one |
247 //cause can be that there is already a map named like the new one |
239 if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val)) |
248 if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val)) |
240 { |
249 { |
241 abortion=1; |
250 abortion=1; |
242 } |
251 } |
243 |
252 |
244 //add it to the list of the displayable maps |
253 //add it to the list of the displayable maps |
245 gdc.mapwin.registerNewNodeMap(mapname); |
254 gdc.mapwin.registerNewNodeMap(mapname); |
246 |
255 |
247 //display it |
256 //display it |
248 //gdc.changeNodeText(mapname); |
257 gdc.changeNodeText(mapname); |
249 } |
258 } |
250 if(!abortion) |
259 if(!abortion) |
251 { |
260 { |
252 name.set_text(""); |
261 name.set_text(""); |
253 default_value.set_text("0"); |
262 default_value.set_text("0"); |
254 edge.show(); |
263 edge.show(); |
255 node.show(); |
264 node.show(); |
256 hide(); |
265 hide(); |
257 } |
266 } |
258 } |
267 } |
259 } |
268 } |
260 } |
|
261 |
269 |
262 |
270 std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge) |
263 std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge) |
271 { |
264 { |
272 bool valid_entry=true; |
265 bool valid_entry=true; |
273 |
266 |