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