| [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 | { |
|---|
| [1525] | 84 | listStrings.push_back(emsi->first); |
|---|
| [1512] | 85 | } |
|---|
| 86 | |
|---|
| 87 | n_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 88 | |
|---|
| 89 | //Restrict it to these choices only: |
|---|
| 90 | n_combo_array[i].set_value_in_list(); |
|---|
| 91 | |
|---|
| 92 | //binding signal to thew actual entry |
|---|
| 93 | n_combo_array[i].get_entry()->signal_changed().connect |
|---|
| 94 | ( |
|---|
| 95 | sigc::bind |
|---|
| 96 | ( |
|---|
| [1524] | 97 | sigc::mem_fun(*this, &MapWin::nComboChanged), |
|---|
| [1512] | 98 | i |
|---|
| 99 | ) |
|---|
| 100 | ); |
|---|
| 101 | |
|---|
| 102 | //placing actual entry in the right place |
|---|
| 103 | |
|---|
| 104 | label=new Gtk::Label; |
|---|
| 105 | label->set_text(node_property_strings[i]); |
|---|
| 106 | |
|---|
| 107 | (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 108 | (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | add(vbox); |
|---|
| 114 | |
|---|
| 115 | vbox.pack_start(*(new Gtk::Label("Node properties"))); |
|---|
| 116 | |
|---|
| 117 | vbox.pack_start(*table); |
|---|
| [1442] | 118 | |
|---|
| 119 | show_all_children(); |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| [1606] | 123 | void MapWin::update() |
|---|
| 124 | { |
|---|
| 125 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
|---|
| 126 | { |
|---|
| 127 | //filling in combo box with choices |
|---|
| 128 | std::list<Glib::ustring> listStrings; |
|---|
| 129 | |
|---|
| 130 | listStrings.push_back("Default"); |
|---|
| 131 | |
|---|
| 132 | std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps(); |
|---|
| 133 | for(;emsi!=ms.endOfEdgeMaps();emsi++) |
|---|
| 134 | { |
|---|
| 135 | listStrings.push_back(emsi->first); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | e_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 139 | } |
|---|
| 140 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
|---|
| 141 | { |
|---|
| 142 | //filling in combo box with choices |
|---|
| 143 | std::list<Glib::ustring> listStrings; |
|---|
| 144 | |
|---|
| 145 | listStrings.push_back("Default"); |
|---|
| 146 | |
|---|
| 147 | std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps(); |
|---|
| 148 | |
|---|
| 149 | for(;emsi!=ms.endOfNodeMaps();emsi++) |
|---|
| 150 | { |
|---|
| 151 | listStrings.push_back(emsi->first); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | n_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| [1524] | 158 | void MapWin::eComboChanged(int prop) |
|---|
| [1442] | 159 | { |
|---|
| [1589] | 160 | |
|---|
| [1512] | 161 | Gtk::Entry* entry = e_combo_array[prop].get_entry(); |
|---|
| [1442] | 162 | |
|---|
| [1446] | 163 | if(entry) |
|---|
| [1442] | 164 | { |
|---|
| [1446] | 165 | Glib::ustring mapname = entry->get_text(); |
|---|
| 166 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 167 | { |
|---|
| [1525] | 168 | if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") ) |
|---|
| [1446] | 169 | { |
|---|
| 170 | switch(prop) |
|---|
| 171 | { |
|---|
| [1512] | 172 | case E_WIDTH: |
|---|
| 173 | gdc.changeEdgeWidth(mapname); |
|---|
| [1446] | 174 | break; |
|---|
| [1512] | 175 | case E_COLOR: |
|---|
| 176 | gdc.changeEdgeColor(mapname); |
|---|
| [1446] | 177 | break; |
|---|
| [1512] | 178 | case E_TEXT: |
|---|
| 179 | gdc.changeEdgeText(mapname); |
|---|
| [1446] | 180 | break; |
|---|
| 181 | default: |
|---|
| [1599] | 182 | std::cerr<<"Error\n"; |
|---|
| [1446] | 183 | } |
|---|
| 184 | } |
|---|
| [1442] | 185 | } |
|---|
| 186 | } |
|---|
| 187 | }; |
|---|
| [1512] | 188 | |
|---|
| [1524] | 189 | void MapWin::nComboChanged(int prop) |
|---|
| [1512] | 190 | { |
|---|
| 191 | |
|---|
| 192 | Gtk::Entry* entry = n_combo_array[prop].get_entry(); |
|---|
| 193 | |
|---|
| 194 | if(entry) |
|---|
| 195 | { |
|---|
| 196 | Glib::ustring mapname = entry->get_text(); |
|---|
| 197 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 198 | { |
|---|
| [1525] | 199 | if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") ) |
|---|
| [1512] | 200 | { |
|---|
| 201 | switch(prop) |
|---|
| 202 | { |
|---|
| 203 | case N_RADIUS: |
|---|
| 204 | gdc.changeNodeRadius(mapname); |
|---|
| 205 | break; |
|---|
| 206 | case N_COLOR: |
|---|
| 207 | gdc.changeNodeColor(mapname); |
|---|
| 208 | break; |
|---|
| 209 | case N_TEXT: |
|---|
| 210 | gdc.changeNodeText(mapname); |
|---|
| 211 | break; |
|---|
| 212 | default: |
|---|
| [1599] | 213 | std::cerr<<"Error\n"; |
|---|
| [1512] | 214 | } |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | }; |
|---|
| 219 | |
|---|
| [1524] | 220 | void MapWin::updateNode(Graph::Node node) |
|---|
| [1512] | 221 | { |
|---|
| 222 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
|---|
| 223 | { |
|---|
| 224 | Gtk::Entry* entry = n_combo_array[i].get_entry(); |
|---|
| 225 | |
|---|
| 226 | if(entry) |
|---|
| 227 | { |
|---|
| 228 | Glib::ustring mapname = entry->get_text(); |
|---|
| 229 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 230 | { |
|---|
| [1525] | 231 | if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") ) |
|---|
| [1512] | 232 | { |
|---|
| 233 | switch(i) |
|---|
| 234 | { |
|---|
| 235 | case N_RADIUS: |
|---|
| [1525] | 236 | gdc.changeNodeRadius(mapname, node); |
|---|
| [1512] | 237 | break; |
|---|
| 238 | case N_COLOR: |
|---|
| 239 | gdc.changeNodeColor(mapname, node); |
|---|
| 240 | break; |
|---|
| 241 | case N_TEXT: |
|---|
| 242 | gdc.changeNodeText(mapname, node); |
|---|
| 243 | break; |
|---|
| 244 | default: |
|---|
| [1599] | 245 | std::cerr<<"Error\n"; |
|---|
| [1512] | 246 | } |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| [1524] | 253 | void MapWin::updateEdge(Graph::Edge edge) |
|---|
| [1512] | 254 | { |
|---|
| 255 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
|---|
| 256 | { |
|---|
| 257 | |
|---|
| 258 | Gtk::Entry* entry = e_combo_array[i].get_entry(); |
|---|
| 259 | |
|---|
| 260 | if(entry) |
|---|
| 261 | { |
|---|
| 262 | Glib::ustring mapname = entry->get_text(); |
|---|
| 263 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
|---|
| 264 | { |
|---|
| 265 | |
|---|
| [1525] | 266 | if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") ) |
|---|
| [1512] | 267 | { |
|---|
| 268 | switch(i) |
|---|
| 269 | { |
|---|
| 270 | case E_WIDTH: |
|---|
| [1525] | 271 | gdc.changeEdgeWidth(mapname, edge); |
|---|
| [1512] | 272 | break; |
|---|
| 273 | case E_COLOR: |
|---|
| 274 | gdc.changeEdgeColor(mapname, edge); |
|---|
| 275 | break; |
|---|
| 276 | case E_TEXT: |
|---|
| 277 | gdc.changeEdgeText(mapname, edge); |
|---|
| 278 | break; |
|---|
| 279 | default: |
|---|
| [1599] | 280 | std::cerr<<"Error\n"; |
|---|
| [1512] | 281 | } |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | } |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| [1586] | 287 | |
|---|
| [1589] | 288 | void MapWin::registerNewEdgeMap(std::string newmapname) |
|---|
| [1586] | 289 | { |
|---|
| [1589] | 290 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
|---|
| 291 | { |
|---|
| 292 | //filling in combo box with choices |
|---|
| 293 | std::list<Glib::ustring> listStrings=e_combo_array[i].get_popdown_strings(); |
|---|
| 294 | listStrings.push_back(newmapname); |
|---|
| 295 | e_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 296 | } |
|---|
| [1594] | 297 | //setting text property for the new map |
|---|
| [1589] | 298 | Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry(); |
|---|
| 299 | entry->set_text((Glib::ustring)newmapname); |
|---|
| [1586] | 300 | } |
|---|
| 301 | |
|---|
| [1589] | 302 | void MapWin::registerNewNodeMap(std::string newmapname) |
|---|
| [1586] | 303 | { |
|---|
| [1592] | 304 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
|---|
| [1589] | 305 | { |
|---|
| 306 | //filling in combo box with choices |
|---|
| 307 | std::list<Glib::ustring> listStrings=n_combo_array[i].get_popdown_strings(); |
|---|
| 308 | listStrings.push_back(newmapname); |
|---|
| 309 | n_combo_array[i].set_popdown_strings(listStrings); |
|---|
| 310 | } |
|---|
| [1594] | 311 | //setting text property for the new map |
|---|
| [1592] | 312 | Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry(); |
|---|
| 313 | entry->set_text((Glib::ustring)newmapname); |
|---|
| [1586] | 314 | } |
|---|