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