algobox.cc
branchgui
changeset 106 853dd852abc7
child 108 bf355fd6563e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/algobox.cc	Wed Jan 04 18:05:55 2006 +0000
     1.3 @@ -0,0 +1,140 @@
     1.4 +#include <algobox.h>
     1.5 +
     1.6 +enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
     1.7 +enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
     1.8 +
     1.9 +AlgoBox::AlgoBox(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
    1.10 +{
    1.11 +  init(tabnames, nodemapnames, edgemapnames);
    1.12 +}
    1.13 +
    1.14 +void AlgoBox::init(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
    1.15 +{
    1.16 +  set_spacing(5);
    1.17 +
    1.18 +  update_tablist(tabnames);
    1.19 +
    1.20 +  //if active tab is changed, the map names in cbt/s have to be updated
    1.21 +  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
    1.22 +
    1.23 +  pack_start(tabcbt);
    1.24 +
    1.25 +  build_box();
    1.26 +
    1.27 +  update_maplist(nodemapnames, edgemapnames);
    1.28 +
    1.29 +  show_all_children();
    1.30 +};
    1.31 +
    1.32 +void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
    1.33 +{
    1.34 +  std::string actname=cbt.get_active_text();
    1.35 +  int prev_act=-1;
    1.36 +
    1.37 +  cbt.clear();
    1.38 +  int actptr=0;
    1.39 +
    1.40 +  std::vector< std::string >::iterator emsi=stringlist.begin();
    1.41 +  for(;emsi!=stringlist.end();emsi++)
    1.42 +    {
    1.43 +      if(actname==*emsi)
    1.44 +	{
    1.45 +	  prev_act=actptr;
    1.46 +	}
    1.47 +
    1.48 +      cbt.append_text(*emsi);
    1.49 +      actptr++;
    1.50 +    }
    1.51 +
    1.52 +  if(prev_act!=-1)
    1.53 +    {
    1.54 +      cbt.set_active(prev_act);
    1.55 +    }
    1.56 +  else if(actptr>0) //so there is item in the list
    1.57 +    {
    1.58 +      cbt.set_active(0);
    1.59 +    }
    1.60 +}
    1.61 +
    1.62 +void AlgoBox::update_tablist( std::vector< std::string > tl )
    1.63 +{
    1.64 +  update_cbt(tl, tabcbt);
    1.65 +  emit_tab_change();
    1.66 +}
    1.67 +
    1.68 +void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml )
    1.69 +{
    1.70 +  for(int i=0;i<(int)nodemapcbts.size();i++)
    1.71 +    {
    1.72 +      update_cbt(nml, *(nodemapcbts[i]));
    1.73 +    }
    1.74 +  for(int i=0;i<(int)edgemapcbts.size();i++)
    1.75 +    {
    1.76 +      update_cbt(eml, *(edgemapcbts[i]));
    1.77 +    }
    1.78 +}
    1.79 +
    1.80 +void AlgoBox::run()
    1.81 +{
    1.82 +  std::cout << "Start algorithm." << std::endl;
    1.83 +}
    1.84 +
    1.85 +void AlgoBox::build_box()
    1.86 +{
    1.87 +  pack_start(*(new Gtk::HSeparator()));
    1.88 +
    1.89 +  label=new Gtk::Label("Specific part for each algorithm.");
    1.90 +      
    1.91 +  pack_start(*label);
    1.92 +  pack_start(*(new Gtk::HSeparator()));
    1.93 +
    1.94 +  label=new Gtk::Label("Maps in chosen tab:");
    1.95 +      
    1.96 +  pack_start(*label);
    1.97 +
    1.98 +  nodemapcbts.resize(NODE_INPUT_NUM);
    1.99 +  for(int i=0;i<(int)nodemapcbts.size();i++)
   1.100 +    {
   1.101 +      Gtk::HBox * hbox=new Gtk::HBox();
   1.102 +
   1.103 +      std::ostringstream o;
   1.104 +      o << "NodeInput " << i+1 << ":";
   1.105 +      label=new Gtk::Label(o.str());
   1.106 +
   1.107 +      nodemapcbts[i]=new Gtk::ComboBoxText();
   1.108 +
   1.109 +      hbox->pack_start(*label);
   1.110 +      hbox->pack_start(*(nodemapcbts[i]));
   1.111 +      pack_start(*hbox);
   1.112 +    }
   1.113 +
   1.114 +  pack_start(*(new Gtk::HSeparator()));
   1.115 +
   1.116 +  edgemapcbts.resize(EDGE_INPUT_NUM);
   1.117 +  for(int i=0;i<(int)edgemapcbts.size();i++)
   1.118 +    {
   1.119 +      Gtk::HBox * hbox=new Gtk::HBox();
   1.120 +
   1.121 +      std::ostringstream o;
   1.122 +      o << "EdgeInput " << i+1 << ":";
   1.123 +      label=new Gtk::Label(o.str());
   1.124 +
   1.125 +      edgemapcbts[i]=new Gtk::ComboBoxText();
   1.126 +
   1.127 +      hbox->pack_start(*label);
   1.128 +      hbox->pack_start(*(edgemapcbts[i]));
   1.129 +      pack_start(*hbox);
   1.130 +    }
   1.131 +
   1.132 +  pack_start(*(new Gtk::HSeparator()));
   1.133 +}
   1.134 +
   1.135 +sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
   1.136 +{
   1.137 +  return signal_maplist_need;
   1.138 +}
   1.139 +
   1.140 +void AlgoBox::emit_tab_change()
   1.141 +{
   1.142 +  signal_maplist_need.emit(tabcbt.get_active_text());
   1.143 +}