algobox.cc
author hegyi
Wed, 04 Jan 2006 18:05:55 +0000
branchgui
changeset 106 853dd852abc7
child 108 bf355fd6563e
permissions -rw-r--r--
Communication with algorithm window is developed.
hegyi@106
     1
#include <algobox.h>
hegyi@106
     2
hegyi@106
     3
enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
hegyi@106
     4
enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
hegyi@106
     5
hegyi@106
     6
AlgoBox::AlgoBox(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
hegyi@106
     7
{
hegyi@106
     8
  init(tabnames, nodemapnames, edgemapnames);
hegyi@106
     9
}
hegyi@106
    10
hegyi@106
    11
void AlgoBox::init(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
hegyi@106
    12
{
hegyi@106
    13
  set_spacing(5);
hegyi@106
    14
hegyi@106
    15
  update_tablist(tabnames);
hegyi@106
    16
hegyi@106
    17
  //if active tab is changed, the map names in cbt/s have to be updated
hegyi@106
    18
  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
hegyi@106
    19
hegyi@106
    20
  pack_start(tabcbt);
hegyi@106
    21
hegyi@106
    22
  build_box();
hegyi@106
    23
hegyi@106
    24
  update_maplist(nodemapnames, edgemapnames);
hegyi@106
    25
hegyi@106
    26
  show_all_children();
hegyi@106
    27
};
hegyi@106
    28
hegyi@106
    29
void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
hegyi@106
    30
{
hegyi@106
    31
  std::string actname=cbt.get_active_text();
hegyi@106
    32
  int prev_act=-1;
hegyi@106
    33
hegyi@106
    34
  cbt.clear();
hegyi@106
    35
  int actptr=0;
hegyi@106
    36
hegyi@106
    37
  std::vector< std::string >::iterator emsi=stringlist.begin();
hegyi@106
    38
  for(;emsi!=stringlist.end();emsi++)
hegyi@106
    39
    {
hegyi@106
    40
      if(actname==*emsi)
hegyi@106
    41
	{
hegyi@106
    42
	  prev_act=actptr;
hegyi@106
    43
	}
hegyi@106
    44
hegyi@106
    45
      cbt.append_text(*emsi);
hegyi@106
    46
      actptr++;
hegyi@106
    47
    }
hegyi@106
    48
hegyi@106
    49
  if(prev_act!=-1)
hegyi@106
    50
    {
hegyi@106
    51
      cbt.set_active(prev_act);
hegyi@106
    52
    }
hegyi@106
    53
  else if(actptr>0) //so there is item in the list
hegyi@106
    54
    {
hegyi@106
    55
      cbt.set_active(0);
hegyi@106
    56
    }
hegyi@106
    57
}
hegyi@106
    58
hegyi@106
    59
void AlgoBox::update_tablist( std::vector< std::string > tl )
hegyi@106
    60
{
hegyi@106
    61
  update_cbt(tl, tabcbt);
hegyi@106
    62
  emit_tab_change();
hegyi@106
    63
}
hegyi@106
    64
hegyi@106
    65
void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml )
hegyi@106
    66
{
hegyi@106
    67
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    68
    {
hegyi@106
    69
      update_cbt(nml, *(nodemapcbts[i]));
hegyi@106
    70
    }
hegyi@106
    71
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
    72
    {
hegyi@106
    73
      update_cbt(eml, *(edgemapcbts[i]));
hegyi@106
    74
    }
hegyi@106
    75
}
hegyi@106
    76
hegyi@106
    77
void AlgoBox::run()
hegyi@106
    78
{
hegyi@106
    79
  std::cout << "Start algorithm." << std::endl;
hegyi@106
    80
}
hegyi@106
    81
hegyi@106
    82
void AlgoBox::build_box()
hegyi@106
    83
{
hegyi@106
    84
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
    85
hegyi@106
    86
  label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
    87
      
hegyi@106
    88
  pack_start(*label);
hegyi@106
    89
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
    90
hegyi@106
    91
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
    92
      
hegyi@106
    93
  pack_start(*label);
hegyi@106
    94
hegyi@106
    95
  nodemapcbts.resize(NODE_INPUT_NUM);
hegyi@106
    96
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    97
    {
hegyi@106
    98
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@106
    99
hegyi@106
   100
      std::ostringstream o;
hegyi@106
   101
      o << "NodeInput " << i+1 << ":";
hegyi@106
   102
      label=new Gtk::Label(o.str());
hegyi@106
   103
hegyi@106
   104
      nodemapcbts[i]=new Gtk::ComboBoxText();
hegyi@106
   105
hegyi@106
   106
      hbox->pack_start(*label);
hegyi@106
   107
      hbox->pack_start(*(nodemapcbts[i]));
hegyi@106
   108
      pack_start(*hbox);
hegyi@106
   109
    }
hegyi@106
   110
hegyi@106
   111
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   112
hegyi@106
   113
  edgemapcbts.resize(EDGE_INPUT_NUM);
hegyi@106
   114
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
   115
    {
hegyi@106
   116
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@106
   117
hegyi@106
   118
      std::ostringstream o;
hegyi@106
   119
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   120
      label=new Gtk::Label(o.str());
hegyi@106
   121
hegyi@106
   122
      edgemapcbts[i]=new Gtk::ComboBoxText();
hegyi@106
   123
hegyi@106
   124
      hbox->pack_start(*label);
hegyi@106
   125
      hbox->pack_start(*(edgemapcbts[i]));
hegyi@106
   126
      pack_start(*hbox);
hegyi@106
   127
    }
hegyi@106
   128
hegyi@106
   129
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   130
}
hegyi@106
   131
hegyi@106
   132
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   133
{
hegyi@106
   134
  return signal_maplist_need;
hegyi@106
   135
}
hegyi@106
   136
hegyi@106
   137
void AlgoBox::emit_tab_change()
hegyi@106
   138
{
hegyi@106
   139
  signal_maplist_need.emit(tabcbt.get_active_text());
hegyi@106
   140
}