| 1 | #include <map_win.h> |
|---|
| 2 | #include <set> |
|---|
| 3 | |
|---|
| 4 | bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e) |
|---|
| 5 | { |
|---|
| 6 | if(e->keyval==GDK_Escape) |
|---|
| 7 | { |
|---|
| 8 | hide(); |
|---|
| 9 | } |
|---|
| 10 | return true; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst) |
|---|
| 14 | { |
|---|
| 15 | set_title(title); |
|---|
| 16 | set_default_size(200, 50); |
|---|
| 17 | |
|---|
| 18 | signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed)); |
|---|
| 19 | |
|---|
| 20 | e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM]; |
|---|
| 21 | |
|---|
| 22 | table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false); |
|---|
| 23 | |
|---|
| 24 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
|---|
| 25 | { |
|---|
| 26 | |
|---|
| 27 | std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps(); |
|---|
| 28 | std::set<int> props; |
|---|
| 29 | |
|---|
| 30 | int actprop; |
|---|
| 31 | |
|---|
| 32 | //here we find out, which map is the default in MapStorage for this property, which are not |
|---|
| 33 | for(int j=0;j<ms.numOfEdgeMaps();j++) |
|---|
| 34 | { |
|---|
| 35 | //this is the default value for this property |
|---|
| 36 | if(emsi->second==&(ms.default_edgemaps[i])) |
|---|
| 37 | { |
|---|
| 38 | actprop=j; |
|---|
| 39 | } |
|---|
| 40 | //these are the maps NOT to show for this property |
|---|
| 41 | for(int k=0;k<EDGE_PROPERTY_NUM;k++) |
|---|
| 42 | { |
|---|
| 43 | if(emsi->second==&(ms.default_edgemaps[k])) |
|---|
| 44 | { |
|---|
| 45 | props.insert(j); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | emsi++; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | //filling in combo box with choices |
|---|
| 52 | std::list<Glib::ustring> listStrings; |
|---|
| 53 | |
|---|
| 54 | listStrings.push_back("Default"); |
|---|
| 55 | |
|---|
| 56 | emsi=ms.beginOfEdgeMaps(); |
|---|
| 57 | |
|---|
| 58 | for(int j=0;j<ms.numOfEdgeMaps();j++) |
|---|
| 59 | { |
|---|
| 60 | if( ( props.find(j) )==( props.end() ) ) |
|---|
| 61 | { |
|---|
| 62 | listStrings.push_back(emsi->first); |
|---|
| 63 | } |
|---|
| 64 | emsi++; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | e_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 68 | |
|---|
| 69 | //Restrict it to these choices only: |
|---|
| 70 | e_combo_array[i].set_value_in_list(); |
|---|
| 71 | |
|---|
| 72 | //binding signal to the actual entry |
|---|
| 73 | e_combo_array[i].get_entry()->signal_changed().connect |
|---|
| 74 | ( |
|---|
| 75 | sigc::bind |
|---|
| 76 | ( |
|---|
| 77 | sigc::mem_fun(*this, &MapWin::eComboChanged), |
|---|
| 78 | i |
|---|
| 79 | ) |
|---|
| 80 | ); |
|---|
| 81 | |
|---|
| 82 | //placing actual entry in the right place |
|---|
| 83 | |
|---|
| 84 | label=new Gtk::Label; |
|---|
| 85 | label->set_text(edge_property_strings[i]); |
|---|
| 86 | |
|---|
| 87 | (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 88 | (*table).attach(e_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | vbox.pack_start(*(new Gtk::Label("Edge properties"))); |
|---|
| 94 | |
|---|
| 95 | vbox.pack_start(*table); |
|---|
| 96 | |
|---|
| 97 | vbox.pack_start(*(new Gtk::HSeparator)); |
|---|
| 98 | |
|---|
| 99 | n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM]; |
|---|
| 100 | |
|---|
| 101 | table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false); |
|---|
| 102 | |
|---|
| 103 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
|---|
| 104 | { |
|---|
| 105 | |
|---|
| 106 | std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps(); |
|---|
| 107 | std::set<int> props; |
|---|
| 108 | |
|---|
| 109 | int actprop; |
|---|
| 110 | |
|---|
| 111 | //here we find out, which map is the default in MapStorage for this property, which are not |
|---|
| 112 | for(int j=0;j<ms.numOfNodeMaps();j++) |
|---|
| 113 | { |
|---|
| 114 | //these are the maps NOT to show for this property |
|---|
| 115 | if(emsi->second==&(ms.default_nodemaps[i])) |
|---|
| 116 | { |
|---|
| 117 | actprop=j; |
|---|
| 118 | } |
|---|
| 119 | //this is the other maps to show for this property |
|---|
| 120 | for(int k=0;k<NODE_PROPERTY_NUM;k++) |
|---|
| 121 | { |
|---|
| 122 | if(emsi->second==&(ms.default_nodemaps[k])) |
|---|
| 123 | { |
|---|
| 124 | props.insert(j); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | emsi++; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | //filling in combo box with choices |
|---|
| 131 | std::list<Glib::ustring> listStrings; |
|---|
| 132 | |
|---|
| 133 | listStrings.push_back("Default"); |
|---|
| 134 | |
|---|
| 135 | emsi=ms.beginOfNodeMaps(); |
|---|
| 136 | |
|---|
| 137 | for(int j=0;j<ms.numOfNodeMaps();j++) |
|---|
| 138 | { |
|---|
| 139 | if( ( props.find(j) )==( props.end() ) ) |
|---|
| 140 | { |
|---|
| 141 | listStrings.push_back(emsi->first); |
|---|
| 142 | } |
|---|
| 143 | emsi++; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | n_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 147 | |
|---|
| 148 | //Restrict it to these choices only: |
|---|
| 149 | n_combo_array[i].set_value_in_list(); |
|---|
| 150 | |
|---|
| 151 | //binding signal to thew actual entry |
|---|
| 152 | n_combo_array[i].get_entry()->signal_changed().connect |
|---|
| 153 | ( |
|---|
| 154 | sigc::bind |
|---|
| 155 | ( |
|---|
| 156 | sigc::mem_fun(*this, &MapWin::nComboChanged), |
|---|
| 157 | i |
|---|
| 158 | ) |
|---|
| 159 | ); |
|---|
| 160 | |
|---|
| 161 | //placing actual entry in the right place |
|---|
| 162 | |
|---|
| 163 | label=new Gtk::Label; |
|---|
| 164 | label->set_text(node_property_strings[i]); |
|---|
| 165 | |
|---|
| 166 | (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 167 | (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | add(vbox); |
|---|
| 173 | |
|---|
| 174 | vbox.pack_start(*(new Gtk::Label("Node properties"))); |
|---|
| 175 | |
|---|
| 176 | vbox.pack_start(*table); |
|---|
| 177 | |
|---|
| 178 | show_all_children(); |
|---|
| 179 | |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | void MapWin::eComboChanged(int prop) |
|---|
| 183 | { |
|---|
| 184 | Gtk::Entry* entry = e_combo_array[prop].get_entry(); |
|---|
| 185 | |
|---|
| 186 | if(entry) |
|---|
| 187 | { |
|---|
| 188 | Glib::ustring mapname = entry->get_text(); |
|---|
| 189 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 190 | { |
|---|
| 191 | if(mapname=="Default") |
|---|
| 192 | { |
|---|
| 193 | mapname=edge_property_strings[prop]; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) |
|---|
| 197 | { |
|---|
| 198 | switch(prop) |
|---|
| 199 | { |
|---|
| 200 | case E_WIDTH: |
|---|
| 201 | gdc.changeEdgeWidth(mapname); |
|---|
| 202 | break; |
|---|
| 203 | case E_COLOR: |
|---|
| 204 | gdc.changeEdgeColor(mapname); |
|---|
| 205 | break; |
|---|
| 206 | case E_TEXT: |
|---|
| 207 | gdc.changeEdgeText(mapname); |
|---|
| 208 | break; |
|---|
| 209 | default: |
|---|
| 210 | std::cout<<"Error\n"; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | }; |
|---|
| 216 | |
|---|
| 217 | void MapWin::nComboChanged(int prop) |
|---|
| 218 | { |
|---|
| 219 | |
|---|
| 220 | Gtk::Entry* entry = n_combo_array[prop].get_entry(); |
|---|
| 221 | |
|---|
| 222 | if(entry) |
|---|
| 223 | { |
|---|
| 224 | Glib::ustring mapname = entry->get_text(); |
|---|
| 225 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 226 | { |
|---|
| 227 | if(mapname=="Default") |
|---|
| 228 | { |
|---|
| 229 | mapname=node_property_strings[prop]; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) |
|---|
| 233 | { |
|---|
| 234 | switch(prop) |
|---|
| 235 | { |
|---|
| 236 | case N_RADIUS: |
|---|
| 237 | gdc.changeNodeRadius(mapname); |
|---|
| 238 | break; |
|---|
| 239 | case N_COLOR: |
|---|
| 240 | gdc.changeNodeColor(mapname); |
|---|
| 241 | break; |
|---|
| 242 | case N_TEXT: |
|---|
| 243 | gdc.changeNodeText(mapname); |
|---|
| 244 | break; |
|---|
| 245 | default: |
|---|
| 246 | std::cout<<"Error\n"; |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | void MapWin::updateNode(Graph::Node node) |
|---|
| 254 | { |
|---|
| 255 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
|---|
| 256 | { |
|---|
| 257 | Gtk::Entry* entry = n_combo_array[i].get_entry(); |
|---|
| 258 | |
|---|
| 259 | if(entry) |
|---|
| 260 | { |
|---|
| 261 | Glib::ustring mapname = entry->get_text(); |
|---|
| 262 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 263 | { |
|---|
| 264 | if(mapname=="Default") |
|---|
| 265 | { |
|---|
| 266 | mapname=node_property_strings[i]; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) |
|---|
| 270 | { |
|---|
| 271 | switch(i) |
|---|
| 272 | { |
|---|
| 273 | case N_RADIUS: |
|---|
| 274 | //gdc.changeNodeRadius(mapname, node); |
|---|
| 275 | std::cout << "If default map-value problem is solved, uncomment line in MapWin::node_update!" << std::endl; |
|---|
| 276 | break; |
|---|
| 277 | case N_COLOR: |
|---|
| 278 | gdc.changeNodeColor(mapname, node); |
|---|
| 279 | break; |
|---|
| 280 | case N_TEXT: |
|---|
| 281 | gdc.changeNodeText(mapname, node); |
|---|
| 282 | break; |
|---|
| 283 | default: |
|---|
| 284 | std::cout<<"Error\n"; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | } |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | void MapWin::updateEdge(Graph::Edge edge) |
|---|
| 293 | { |
|---|
| 294 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
|---|
| 295 | { |
|---|
| 296 | |
|---|
| 297 | Gtk::Entry* entry = e_combo_array[i].get_entry(); |
|---|
| 298 | |
|---|
| 299 | if(entry) |
|---|
| 300 | { |
|---|
| 301 | Glib::ustring mapname = entry->get_text(); |
|---|
| 302 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 303 | { |
|---|
| 304 | if(mapname=="Default") |
|---|
| 305 | { |
|---|
| 306 | mapname=edge_property_strings[i]; |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) |
|---|
| 310 | { |
|---|
| 311 | switch(i) |
|---|
| 312 | { |
|---|
| 313 | case E_WIDTH: |
|---|
| 314 | //gdc.changeEdgeWidth(mapname, edge); |
|---|
| 315 | std::cout << "If default map-value problem is solved, uncomment line in MapWin::edge_update!" << std::endl; |
|---|
| 316 | break; |
|---|
| 317 | case E_COLOR: |
|---|
| 318 | gdc.changeEdgeColor(mapname, edge); |
|---|
| 319 | break; |
|---|
| 320 | case E_TEXT: |
|---|
| 321 | gdc.changeEdgeText(mapname, edge); |
|---|
| 322 | break; |
|---|
| 323 | default: |
|---|
| 324 | std::cout<<"Error\n"; |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | } |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | } |
|---|