1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/algobox.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,211 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <algobox.h>
1.23 +#include <mapstorage.h>
1.24 +#include <mapselector.h>
1.25 +
1.26 +enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
1.27 +enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for arcs;
1.28 +
1.29 +AlgoBox::AlgoBox(std::vector<std::string> tabnames)
1.30 +{
1.31 + init(tabnames);
1.32 +}
1.33 +
1.34 +void AlgoBox::init(std::vector<std::string> tabnames)
1.35 +{
1.36 + set_spacing(5);
1.37 +
1.38 + update_tablist(tabnames);
1.39 +
1.40 + //if active tab is changed, the map names in cbt/s have to be updated
1.41 + tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
1.42 +
1.43 + pack_start(tabcbt);
1.44 + build_box();
1.45 +
1.46 + show_all_children();
1.47 +};
1.48 +
1.49 +void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
1.50 +{
1.51 + std::string actname=cbt.get_active_text();
1.52 + int prev_act=-1;
1.53 +
1.54 + cbt.clear();
1.55 + int actptr=0;
1.56 +
1.57 + std::vector< std::string >::iterator emsi=stringlist.begin();
1.58 + for(;emsi!=stringlist.end();emsi++)
1.59 + {
1.60 + if(actname==*emsi)
1.61 + {
1.62 + prev_act=actptr;
1.63 + }
1.64 +
1.65 + cbt.append_text(*emsi);
1.66 + actptr++;
1.67 + }
1.68 +
1.69 + if(prev_act!=-1)
1.70 + {
1.71 + cbt.set_active(prev_act);
1.72 + }
1.73 + else if(actptr>0) //so there is item in the list
1.74 + {
1.75 + //cbt.set_active(0);
1.76 + }
1.77 +}
1.78 +
1.79 +void AlgoBox::update_tablist( std::vector< std::string > tl )
1.80 +{
1.81 + update_cbt(tl, tabcbt);
1.82 + emit_tab_change();
1.83 +}
1.84 +
1.85 +void AlgoBox::update_maplist(MapStorage * ms)
1.86 +{
1.87 + mapstorage=ms;
1.88 + std::vector<std::string> n_nml;
1.89 + std::vector<std::string> s_nml;
1.90 + std::vector<std::string> n_eml;
1.91 + std::vector<std::string> s_eml;
1.92 + if(mapstorage!=NULL)
1.93 + {
1.94 + mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
1.95 + mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::arcmaplist_changed));
1.96 + n_nml=mapstorage->getNodeMapList(NUM);
1.97 + s_nml=mapstorage->getNodeMapList(STR);
1.98 + n_eml=mapstorage->getArcMapList(NUM);
1.99 + s_eml=mapstorage->getArcMapList(STR);
1.100 + }
1.101 + for(int i=0;i<(int)nodemapcbts.size();i++)
1.102 + {
1.103 + (nodemapcbts[i])->update_list(n_nml, s_nml);
1.104 + //update_cbt(nml, *(nodemapcbts[i]));
1.105 + }
1.106 + for(int i=0;i<(int)arcmapcbts.size();i++)
1.107 + {
1.108 + (arcmapcbts[i])->update_list(n_eml, s_eml);
1.109 + //update_cbt(eml, *(arcmapcbts[i]));
1.110 + }
1.111 + signal_maplist_updated.emit();
1.112 +}
1.113 +
1.114 +void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type)
1.115 +{
1.116 + for(int i=0;i<(int)nodemapcbts.size();i++)
1.117 + {
1.118 + (nodemapcbts[i])->append_text(newmap, type);
1.119 + }
1.120 +}
1.121 +
1.122 +void AlgoBox::arcmaplist_changed(std::string newmap, MapValue::Type type)
1.123 +{
1.124 + for(int i=0;i<(int)arcmapcbts.size();i++)
1.125 + {
1.126 + (arcmapcbts[i])->append_text(newmap, type);
1.127 + }
1.128 +}
1.129 +
1.130 +void AlgoBox::run()
1.131 +{
1.132 + std::cout << "Start algorithm." << std::endl;
1.133 +}
1.134 +
1.135 +void AlgoBox::build_box()
1.136 +{
1.137 + pack_start(*(new Gtk::HSeparator()));
1.138 +
1.139 + Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
1.140 +
1.141 + pack_start(*label);
1.142 + pack_start(*(new Gtk::HSeparator()));
1.143 +
1.144 + label=new Gtk::Label("Maps in chosen tab:");
1.145 +
1.146 + pack_start(*label);
1.147 +
1.148 + for(int i=0;i<NODE_INPUT_NUM;i++)
1.149 + {
1.150 + std::ostringstream o;
1.151 + o << "NodeInput " << i+1 << ":";
1.152 +
1.153 + addMapSelector(o.str(), false);
1.154 + }
1.155 +
1.156 + pack_start(*(new Gtk::HSeparator()));
1.157 +
1.158 + for(int i=0;i<EDGE_INPUT_NUM;i++)
1.159 + {
1.160 +
1.161 + std::ostringstream o;
1.162 + o << "ArcInput " << i+1 << ":";
1.163 +
1.164 + addMapSelector(o.str(), true);
1.165 + }
1.166 +
1.167 + pack_start(*(new Gtk::HSeparator()));
1.168 +}
1.169 +
1.170 +void AlgoBox::addMapSelector(std::string inputname, bool itisarc, MapType type)
1.171 +{
1.172 + std::vector<std::string> empty_vector;
1.173 +
1.174 + MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisarc, false, type);
1.175 +
1.176 + if(itisarc)
1.177 + {
1.178 + arcmapcbts.resize(arcmapcbts.size()+1);
1.179 + arcmapcbts[arcmapcbts.size()-1]=msp;
1.180 + }
1.181 + else
1.182 + {
1.183 + nodemapcbts.resize(nodemapcbts.size()+1);
1.184 + nodemapcbts[nodemapcbts.size()-1]=msp;
1.185 + }
1.186 +
1.187 + msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
1.188 +
1.189 + pack_start(*msp);
1.190 +}
1.191 +
1.192 +sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
1.193 +{
1.194 + return signal_maplist_need;
1.195 +}
1.196 +
1.197 +void AlgoBox::emit_tab_change()
1.198 +{
1.199 + std::string active_tab=tabcbt.get_active_text();
1.200 + if(active_tab!="")
1.201 + {
1.202 + signal_maplist_need.emit(active_tab);
1.203 + }
1.204 + else
1.205 + {
1.206 + std::vector<std::string> empty_vector;
1.207 + update_maplist(NULL);
1.208 + }
1.209 +}
1.210 +
1.211 +void AlgoBox::emit_new_map_signal(bool itisarc)
1.212 +{
1.213 + signal_newmapwin_need.emit(tabcbt.get_active_text(), itisarc);
1.214 +}