diff -r 9e78d14fd0ba -r 853dd852abc7 algobox.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/algobox.cc Wed Jan 04 18:05:55 2006 +0000 @@ -0,0 +1,140 @@ +#include + +enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes; +enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges; + +AlgoBox::AlgoBox(std::vector tabnames, std::vector nodemapnames, std::vector edgemapnames) +{ + init(tabnames, nodemapnames, edgemapnames); +} + +void AlgoBox::init(std::vector tabnames, std::vector nodemapnames, std::vector edgemapnames) +{ + set_spacing(5); + + update_tablist(tabnames); + + //if active tab is changed, the map names in cbt/s have to be updated + tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change)); + + pack_start(tabcbt); + + build_box(); + + update_maplist(nodemapnames, edgemapnames); + + show_all_children(); +}; + +void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt) +{ + std::string actname=cbt.get_active_text(); + int prev_act=-1; + + cbt.clear(); + int actptr=0; + + std::vector< std::string >::iterator emsi=stringlist.begin(); + for(;emsi!=stringlist.end();emsi++) + { + if(actname==*emsi) + { + prev_act=actptr; + } + + cbt.append_text(*emsi); + actptr++; + } + + if(prev_act!=-1) + { + cbt.set_active(prev_act); + } + else if(actptr>0) //so there is item in the list + { + cbt.set_active(0); + } +} + +void AlgoBox::update_tablist( std::vector< std::string > tl ) +{ + update_cbt(tl, tabcbt); + emit_tab_change(); +} + +void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml ) +{ + for(int i=0;i<(int)nodemapcbts.size();i++) + { + update_cbt(nml, *(nodemapcbts[i])); + } + for(int i=0;i<(int)edgemapcbts.size();i++) + { + update_cbt(eml, *(edgemapcbts[i])); + } +} + +void AlgoBox::run() +{ + std::cout << "Start algorithm." << std::endl; +} + +void AlgoBox::build_box() +{ + pack_start(*(new Gtk::HSeparator())); + + label=new Gtk::Label("Specific part for each algorithm."); + + pack_start(*label); + pack_start(*(new Gtk::HSeparator())); + + label=new Gtk::Label("Maps in chosen tab:"); + + pack_start(*label); + + nodemapcbts.resize(NODE_INPUT_NUM); + for(int i=0;i<(int)nodemapcbts.size();i++) + { + Gtk::HBox * hbox=new Gtk::HBox(); + + std::ostringstream o; + o << "NodeInput " << i+1 << ":"; + label=new Gtk::Label(o.str()); + + nodemapcbts[i]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(nodemapcbts[i])); + pack_start(*hbox); + } + + pack_start(*(new Gtk::HSeparator())); + + edgemapcbts.resize(EDGE_INPUT_NUM); + for(int i=0;i<(int)edgemapcbts.size();i++) + { + Gtk::HBox * hbox=new Gtk::HBox(); + + std::ostringstream o; + o << "EdgeInput " << i+1 << ":"; + label=new Gtk::Label(o.str()); + + edgemapcbts[i]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(edgemapcbts[i])); + pack_start(*hbox); + } + + pack_start(*(new Gtk::HSeparator())); +} + +sigc::signal AlgoBox::signal_maplist_needed() +{ + return signal_maplist_need; +} + +void AlgoBox::emit_tab_change() +{ + signal_maplist_need.emit(tabcbt.get_active_text()); +}