Changeset 90:e9f8f44f12a3 in glemon-0.x for new_map_win.cc
- Timestamp:
- 11/21/05 19:03:20 (19 years ago)
- Branch:
- gui
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2373
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new_map_win.cc
r89 r90 10 10 } 11 11 12 NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap") 13 { 14 set_title(title); 12 NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap") 13 { 15 14 set_default_size(200, 50); 16 15 17 16 signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed)); 18 17 18 Gtk::VBox * vbox=get_vbox(); 19 19 20 20 //entries … … 38 38 Gtk::RadioButton::Group group = node.get_group(); 39 39 edge.set_group(group); 40 41 (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); 42 (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); 43 44 vbox.pack_start(*table); 40 41 if(edgenode) 42 { 43 (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); 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 60 //OK button 47 button=new Gtk::Button("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); 61 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); 58 62 59 63 show_all_children(); … … 61 65 } 62 66 63 void NewMapWin::showByPreChoose(bool itisedge) 64 { 65 if(itisedge) 66 { 67 edge.set_active(); 68 } 69 else 70 { 71 node.set_active(); 72 } 73 node.hide(); 74 edge.hide(); 75 show(); 76 } 77 78 void NewMapWin::buttonPressed() 79 { 80 double def_val=0; 81 82 //get and formulate text 83 std::string def_val_str=default_value.get_text(); 84 std::string polishform=string2Polishform(def_val_str,edge.get_active()); 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; 67 void NewMapWin::on_response(int response_id) 68 { 69 if(response_id==Gtk::RESPONSE_OK) 70 { 71 double def_val=0; 72 73 //get and formulate text 74 std::string def_val_str=default_value.get_text(); 75 std::string polishform=string2Polishform(def_val_str,edge.get_active()); 76 77 //get name of text 78 std::string mapname=name.get_text(); 79 80 if(!mapname.empty()&&!polishform.empty()) 81 { 82 int abortion=0; 83 if(edge.get_active()) 84 { 85 //create the new map 86 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph); 87 88 std::stack<double> polishstack; 98 89 99 for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) 100 { 101 for(int i=0;i<(int)polishform.size();i++) 102 { 103 double op1, op2; 104 bool operation=true; 105 switch(polishform[i]) 90 for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) 91 { 92 for(int i=0;i<(int)polishform.size();i++) 106 93 { 107 case '+': 108 case '-': 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; 94 double op1, op2; 95 bool operation=true; 139 96 switch(polishform[i]) 140 97 { 141 98 case '+': 142 res=op1+op2;143 break;144 99 case '-': 145 res=op2-op1;146 break;147 100 case '/': 148 res=op2/op1;149 break;150 101 case '*': 151 res=op1*op2; 102 op1=polishstack.top(); 103 polishstack.pop(); 104 op2=polishstack.top(); 105 polishstack.pop(); 152 106 break; 153 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 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 } 160 (*emptr)[k]=polishstack.top(); 161 } 162 163 //if addition was not successful addEdgeMap returns one. 164 //cause can be that there is already a map named like the new one 165 if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val)) 166 { 167 abortion=1; 168 } 169 170 //add it to the list of the displayable maps 171 gdc.mapwin.registerNewEdgeMap(mapname); 172 173 //display it 174 gdc.changeEdgeText(mapname); 175 } 176 else //!edge.get_active() 177 { 178 //create the new map 179 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph); 180 181 std::stack<double> polishstack; 151 (*emptr)[k]=polishstack.top(); 152 } 153 154 //if addition was not successful addEdgeMap returns one. 155 //cause can be that there is already a map named like the new one 156 if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val)) 157 { 158 abortion=1; 159 } 160 161 //add it to the list of the displayable maps 162 gdc.mapwin.registerNewEdgeMap(mapname); 163 164 //display it 165 gdc.changeEdgeText(mapname); 166 } 167 else //!edge.get_active() 168 { 169 //create the new map 170 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph); 171 172 std::stack<double> polishstack; 182 173 183 for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) 184 { 185 for(int i=0;i<(int)polishform.size();i++) 186 { 187 double op1, op2; 188 bool operation=true; 189 switch(polishform[i]) 174 for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k) 175 { 176 for(int i=0;i<(int)polishform.size();i++) 190 177 { 191 case '+': 192 case '-': 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; 178 double op1, op2; 179 bool operation=true; 222 180 switch(polishform[i]) 223 181 { 224 182 case '+': 225 res=op1+op2;226 break;227 183 case '-': 228 res=op2-op1;229 break;230 184 case '/': 231 res=op2/op1;232 break;233 185 case '*': 234 res=op1*op2; 186 op1=polishstack.top(); 187 polishstack.pop(); 188 op2=polishstack.top(); 189 polishstack.pop(); 235 190 break; 236 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 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 } 243 (*emptr)[k]=polishstack.top(); 244 } 245 246 //if addition was not successful addNodeMap returns one. 247 //cause can be that there is already a map named like the new one 248 if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val)) 249 { 250 abortion=1; 251 } 252 253 //add it to the list of the displayable maps 254 gdc.mapwin.registerNewNodeMap(mapname); 255 256 //display it 257 gdc.changeNodeText(mapname); 258 } 259 if(!abortion) 260 { 261 name.set_text(""); 262 default_value.set_text("0"); 263 edge.show(); 264 node.show(); 265 hide(); 266 } 267 } 268 } 234 (*emptr)[k]=polishstack.top(); 235 } 236 237 //if addition was not successful addNodeMap returns one. 238 //cause can be that there is already a map named like the new one 239 if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val)) 240 { 241 abortion=1; 242 } 243 244 //add it to the list of the displayable maps 245 gdc.mapwin.registerNewNodeMap(mapname); 246 247 //display it 248 //gdc.changeNodeText(mapname); 249 } 250 if(!abortion) 251 { 252 name.set_text(""); 253 default_value.set_text("0"); 254 edge.show(); 255 node.show(); 256 hide(); 257 } 258 } 259 } 260 } 261 269 262 270 263 std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
Note: See TracChangeset
for help on using the changeset viewer.