[174] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
| 18 | |
---|
[106] | 19 | #include <algobox.h> |
---|
[194] | 20 | #include <mapstorage.h> |
---|
| 21 | #include <mapselector.h> |
---|
[106] | 22 | |
---|
| 23 | enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes; |
---|
| 24 | enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges; |
---|
| 25 | |
---|
[108] | 26 | AlgoBox::AlgoBox(std::vector<std::string> tabnames) |
---|
[106] | 27 | { |
---|
[108] | 28 | init(tabnames); |
---|
[106] | 29 | } |
---|
| 30 | |
---|
[108] | 31 | void AlgoBox::init(std::vector<std::string> tabnames) |
---|
[106] | 32 | { |
---|
| 33 | set_spacing(5); |
---|
| 34 | |
---|
| 35 | update_tablist(tabnames); |
---|
| 36 | |
---|
| 37 | //if active tab is changed, the map names in cbt/s have to be updated |
---|
| 38 | tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change)); |
---|
| 39 | |
---|
| 40 | pack_start(tabcbt); |
---|
| 41 | build_box(); |
---|
| 42 | |
---|
| 43 | show_all_children(); |
---|
| 44 | }; |
---|
| 45 | |
---|
| 46 | void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt) |
---|
| 47 | { |
---|
| 48 | std::string actname=cbt.get_active_text(); |
---|
| 49 | int prev_act=-1; |
---|
| 50 | |
---|
| 51 | cbt.clear(); |
---|
| 52 | int actptr=0; |
---|
| 53 | |
---|
| 54 | std::vector< std::string >::iterator emsi=stringlist.begin(); |
---|
| 55 | for(;emsi!=stringlist.end();emsi++) |
---|
| 56 | { |
---|
| 57 | if(actname==*emsi) |
---|
| 58 | { |
---|
| 59 | prev_act=actptr; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | cbt.append_text(*emsi); |
---|
| 63 | actptr++; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | if(prev_act!=-1) |
---|
| 67 | { |
---|
| 68 | cbt.set_active(prev_act); |
---|
| 69 | } |
---|
| 70 | else if(actptr>0) //so there is item in the list |
---|
| 71 | { |
---|
[108] | 72 | //cbt.set_active(0); |
---|
[106] | 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void AlgoBox::update_tablist( std::vector< std::string > tl ) |
---|
| 77 | { |
---|
| 78 | update_cbt(tl, tabcbt); |
---|
| 79 | emit_tab_change(); |
---|
| 80 | } |
---|
| 81 | |
---|
[109] | 82 | void AlgoBox::update_maplist(MapStorage * ms) |
---|
[106] | 83 | { |
---|
[109] | 84 | mapstorage=ms; |
---|
[108] | 85 | std::vector<std::string> nml; |
---|
| 86 | std::vector<std::string> eml; |
---|
| 87 | if(mapstorage!=NULL) |
---|
| 88 | { |
---|
| 89 | mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); |
---|
| 90 | mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed)); |
---|
| 91 | nml=mapstorage->getNodeMapList(); |
---|
[109] | 92 | eml=mapstorage->getEdgeMapList(); |
---|
[108] | 93 | } |
---|
[106] | 94 | for(int i=0;i<(int)nodemapcbts.size();i++) |
---|
| 95 | { |
---|
[114] | 96 | (nodemapcbts[i])->update_list(nml); |
---|
| 97 | //update_cbt(nml, *(nodemapcbts[i])); |
---|
[106] | 98 | } |
---|
| 99 | for(int i=0;i<(int)edgemapcbts.size();i++) |
---|
| 100 | { |
---|
[114] | 101 | (edgemapcbts[i])->update_list(eml); |
---|
| 102 | //update_cbt(eml, *(edgemapcbts[i])); |
---|
[106] | 103 | } |
---|
[162] | 104 | signal_maplist_updated.emit(); |
---|
[106] | 105 | } |
---|
| 106 | |
---|
[108] | 107 | void AlgoBox::nodemaplist_changed(std::string newmap) |
---|
| 108 | { |
---|
| 109 | for(int i=0;i<(int)nodemapcbts.size();i++) |
---|
| 110 | { |
---|
| 111 | (nodemapcbts[i])->append_text(newmap); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void AlgoBox::edgemaplist_changed(std::string newmap) |
---|
| 116 | { |
---|
| 117 | for(int i=0;i<(int)edgemapcbts.size();i++) |
---|
| 118 | { |
---|
| 119 | (edgemapcbts[i])->append_text(newmap); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
[106] | 123 | void AlgoBox::run() |
---|
| 124 | { |
---|
| 125 | std::cout << "Start algorithm." << std::endl; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void AlgoBox::build_box() |
---|
| 129 | { |
---|
| 130 | pack_start(*(new Gtk::HSeparator())); |
---|
| 131 | |
---|
[114] | 132 | Gtk::Label * label=new Gtk::Label("Specific part for each algorithm."); |
---|
[106] | 133 | |
---|
| 134 | pack_start(*label); |
---|
| 135 | pack_start(*(new Gtk::HSeparator())); |
---|
| 136 | |
---|
| 137 | label=new Gtk::Label("Maps in chosen tab:"); |
---|
| 138 | |
---|
| 139 | pack_start(*label); |
---|
| 140 | |
---|
[116] | 141 | for(int i=0;i<NODE_INPUT_NUM;i++) |
---|
[106] | 142 | { |
---|
| 143 | std::ostringstream o; |
---|
| 144 | o << "NodeInput " << i+1 << ":"; |
---|
| 145 | |
---|
[116] | 146 | addMapSelector(o.str(), false); |
---|
[106] | 147 | } |
---|
| 148 | |
---|
| 149 | pack_start(*(new Gtk::HSeparator())); |
---|
| 150 | |
---|
[116] | 151 | for(int i=0;i<EDGE_INPUT_NUM;i++) |
---|
[106] | 152 | { |
---|
| 153 | |
---|
| 154 | std::ostringstream o; |
---|
| 155 | o << "EdgeInput " << i+1 << ":"; |
---|
| 156 | |
---|
[116] | 157 | addMapSelector(o.str(), true); |
---|
[106] | 158 | } |
---|
| 159 | |
---|
| 160 | pack_start(*(new Gtk::HSeparator())); |
---|
| 161 | } |
---|
| 162 | |
---|
[116] | 163 | void AlgoBox::addMapSelector(std::string inputname, bool itisedge) |
---|
| 164 | { |
---|
| 165 | std::vector<std::string> empty_vector; |
---|
| 166 | |
---|
| 167 | MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false); |
---|
| 168 | |
---|
| 169 | if(itisedge) |
---|
| 170 | { |
---|
| 171 | edgemapcbts.resize(edgemapcbts.size()+1); |
---|
| 172 | edgemapcbts[edgemapcbts.size()-1]=msp; |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | nodemapcbts.resize(nodemapcbts.size()+1); |
---|
| 177 | nodemapcbts[nodemapcbts.size()-1]=msp; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal)); |
---|
| 181 | |
---|
| 182 | pack_start(*msp); |
---|
| 183 | } |
---|
| 184 | |
---|
[106] | 185 | sigc::signal<void, std::string> AlgoBox::signal_maplist_needed() |
---|
| 186 | { |
---|
| 187 | return signal_maplist_need; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | void AlgoBox::emit_tab_change() |
---|
| 191 | { |
---|
[108] | 192 | std::string active_tab=tabcbt.get_active_text(); |
---|
| 193 | if(active_tab!="") |
---|
| 194 | { |
---|
| 195 | signal_maplist_need.emit(active_tab); |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | std::vector<std::string> empty_vector; |
---|
| 200 | update_maplist(NULL); |
---|
| 201 | } |
---|
[106] | 202 | } |
---|
[114] | 203 | |
---|
| 204 | void AlgoBox::emit_new_map_signal(bool itisedge) |
---|
| 205 | { |
---|
| 206 | signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge); |
---|
| 207 | } |
---|