hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes; hegyi@1: enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for arcs; hegyi@1: hegyi@1: AlgoBox::AlgoBox(std::vector tabnames) hegyi@1: { hegyi@1: init(tabnames); hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::init(std::vector tabnames) hegyi@1: { hegyi@1: set_spacing(5); hegyi@1: hegyi@1: update_tablist(tabnames); hegyi@1: hegyi@1: //if active tab is changed, the map names in cbt/s have to be updated hegyi@1: tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change)); hegyi@1: hegyi@1: pack_start(tabcbt); hegyi@1: build_box(); hegyi@1: hegyi@1: show_all_children(); hegyi@1: }; hegyi@1: hegyi@1: void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt) hegyi@1: { hegyi@1: std::string actname=cbt.get_active_text(); hegyi@1: int prev_act=-1; hegyi@1: hegyi@1: cbt.clear(); hegyi@1: int actptr=0; hegyi@1: hegyi@1: std::vector< std::string >::iterator emsi=stringlist.begin(); hegyi@1: for(;emsi!=stringlist.end();emsi++) hegyi@1: { hegyi@1: if(actname==*emsi) hegyi@1: { hegyi@1: prev_act=actptr; hegyi@1: } hegyi@1: hegyi@1: cbt.append_text(*emsi); hegyi@1: actptr++; hegyi@1: } hegyi@1: hegyi@1: if(prev_act!=-1) hegyi@1: { hegyi@1: cbt.set_active(prev_act); hegyi@1: } hegyi@1: else if(actptr>0) //so there is item in the list hegyi@1: { hegyi@1: //cbt.set_active(0); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::update_tablist( std::vector< std::string > tl ) hegyi@1: { hegyi@1: update_cbt(tl, tabcbt); hegyi@1: emit_tab_change(); hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::update_maplist(MapStorage * ms) hegyi@1: { hegyi@1: mapstorage=ms; hegyi@1: std::vector n_nml; hegyi@1: std::vector s_nml; hegyi@1: std::vector n_eml; hegyi@1: std::vector s_eml; hegyi@1: if(mapstorage!=NULL) hegyi@1: { hegyi@1: mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); hegyi@1: mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::arcmaplist_changed)); hegyi@1: n_nml=mapstorage->getNodeMapList(NUM); hegyi@1: s_nml=mapstorage->getNodeMapList(STR); hegyi@1: n_eml=mapstorage->getArcMapList(NUM); hegyi@1: s_eml=mapstorage->getArcMapList(STR); hegyi@1: } hegyi@1: for(int i=0;i<(int)nodemapcbts.size();i++) hegyi@1: { hegyi@1: (nodemapcbts[i])->update_list(n_nml, s_nml); hegyi@1: //update_cbt(nml, *(nodemapcbts[i])); hegyi@1: } hegyi@1: for(int i=0;i<(int)arcmapcbts.size();i++) hegyi@1: { hegyi@1: (arcmapcbts[i])->update_list(n_eml, s_eml); hegyi@1: //update_cbt(eml, *(arcmapcbts[i])); hegyi@1: } hegyi@1: signal_maplist_updated.emit(); hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type) hegyi@1: { hegyi@1: for(int i=0;i<(int)nodemapcbts.size();i++) hegyi@1: { hegyi@1: (nodemapcbts[i])->append_text(newmap, type); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::arcmaplist_changed(std::string newmap, MapValue::Type type) hegyi@1: { hegyi@1: for(int i=0;i<(int)arcmapcbts.size();i++) hegyi@1: { hegyi@1: (arcmapcbts[i])->append_text(newmap, type); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::run() hegyi@1: { hegyi@1: std::cout << "Start algorithm." << std::endl; hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::build_box() hegyi@1: { hegyi@1: pack_start(*(new Gtk::HSeparator())); hegyi@1: hegyi@1: Gtk::Label * label=new Gtk::Label("Specific part for each algorithm."); hegyi@1: hegyi@1: pack_start(*label); hegyi@1: pack_start(*(new Gtk::HSeparator())); hegyi@1: hegyi@1: label=new Gtk::Label("Maps in chosen tab:"); hegyi@1: hegyi@1: pack_start(*label); hegyi@1: hegyi@1: for(int i=0;i empty_vector; hegyi@1: hegyi@1: MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisarc, false, type); hegyi@1: hegyi@1: if(itisarc) hegyi@1: { hegyi@1: arcmapcbts.resize(arcmapcbts.size()+1); hegyi@1: arcmapcbts[arcmapcbts.size()-1]=msp; hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: nodemapcbts.resize(nodemapcbts.size()+1); hegyi@1: nodemapcbts[nodemapcbts.size()-1]=msp; hegyi@1: } hegyi@1: hegyi@1: msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal)); hegyi@1: hegyi@1: pack_start(*msp); hegyi@1: } hegyi@1: hegyi@1: sigc::signal AlgoBox::signal_maplist_needed() hegyi@1: { hegyi@1: return signal_maplist_need; hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::emit_tab_change() hegyi@1: { hegyi@1: std::string active_tab=tabcbt.get_active_text(); hegyi@1: if(active_tab!="") hegyi@1: { hegyi@1: signal_maplist_need.emit(active_tab); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: std::vector empty_vector; hegyi@1: update_maplist(NULL); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void AlgoBox::emit_new_map_signal(bool itisarc) hegyi@1: { hegyi@1: signal_newmapwin_need.emit(tabcbt.get_active_text(), itisarc); hegyi@1: }