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