#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) { init(tabnames); } void AlgoBox::init(std::vector tabnames) { 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(); 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( void * ms) { mapstorage=(MapStorage *)ms; std::vector nml; std::vector eml; if(mapstorage!=NULL) { mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed)); nml=mapstorage->getNodeMapList(); eml=mapstorage->getNodeMapList(); } 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::nodemaplist_changed(std::string newmap) { for(int i=0;i<(int)nodemapcbts.size();i++) { (nodemapcbts[i])->append_text(newmap); } } void AlgoBox::edgemaplist_changed(std::string newmap) { for(int i=0;i<(int)edgemapcbts.size();i++) { (edgemapcbts[i])->append_text(newmap); } } 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() { std::string active_tab=tabcbt.get_active_text(); if(active_tab!="") { signal_maplist_need.emit(active_tab); } else { std::vector empty_vector; update_maplist(NULL); } }