gui/algobox.cc
author hegyi
Fri, 06 Jan 2006 14:36:46 +0000
changeset 1882 2c3f6c7e01b4
parent 1878 409a31271efd
child 1884 9c061834b33b
permissions -rw-r--r--
MapSelector has become a standalone class.
hegyi@1876
     1
#include <algobox.h>
hegyi@1876
     2
hegyi@1876
     3
enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
hegyi@1876
     4
enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
hegyi@1876
     5
hegyi@1878
     6
AlgoBox::AlgoBox(std::vector<std::string> tabnames)
hegyi@1876
     7
{
hegyi@1878
     8
  init(tabnames);
hegyi@1876
     9
}
hegyi@1876
    10
hegyi@1878
    11
void AlgoBox::init(std::vector<std::string> tabnames)
hegyi@1876
    12
{
hegyi@1876
    13
  set_spacing(5);
hegyi@1876
    14
hegyi@1876
    15
  update_tablist(tabnames);
hegyi@1876
    16
hegyi@1876
    17
  //if active tab is changed, the map names in cbt/s have to be updated
hegyi@1876
    18
  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
hegyi@1876
    19
hegyi@1876
    20
  pack_start(tabcbt);
hegyi@1876
    21
  build_box();
hegyi@1876
    22
hegyi@1876
    23
  show_all_children();
hegyi@1876
    24
};
hegyi@1876
    25
hegyi@1876
    26
void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
hegyi@1876
    27
{
hegyi@1876
    28
  std::string actname=cbt.get_active_text();
hegyi@1876
    29
  int prev_act=-1;
hegyi@1876
    30
hegyi@1876
    31
  cbt.clear();
hegyi@1876
    32
  int actptr=0;
hegyi@1876
    33
hegyi@1876
    34
  std::vector< std::string >::iterator emsi=stringlist.begin();
hegyi@1876
    35
  for(;emsi!=stringlist.end();emsi++)
hegyi@1876
    36
    {
hegyi@1876
    37
      if(actname==*emsi)
hegyi@1876
    38
	{
hegyi@1876
    39
	  prev_act=actptr;
hegyi@1876
    40
	}
hegyi@1876
    41
hegyi@1876
    42
      cbt.append_text(*emsi);
hegyi@1876
    43
      actptr++;
hegyi@1876
    44
    }
hegyi@1876
    45
hegyi@1876
    46
  if(prev_act!=-1)
hegyi@1876
    47
    {
hegyi@1876
    48
      cbt.set_active(prev_act);
hegyi@1876
    49
    }
hegyi@1876
    50
  else if(actptr>0) //so there is item in the list
hegyi@1876
    51
    {
hegyi@1878
    52
      //cbt.set_active(0);
hegyi@1876
    53
    }
hegyi@1876
    54
}
hegyi@1876
    55
hegyi@1876
    56
void AlgoBox::update_tablist( std::vector< std::string > tl )
hegyi@1876
    57
{
hegyi@1876
    58
  update_cbt(tl, tabcbt);
hegyi@1876
    59
  emit_tab_change();
hegyi@1876
    60
}
hegyi@1876
    61
hegyi@1879
    62
void AlgoBox::update_maplist(MapStorage * ms)
hegyi@1876
    63
{
hegyi@1879
    64
  mapstorage=ms;
hegyi@1878
    65
  std::vector<std::string> nml;
hegyi@1878
    66
  std::vector<std::string> eml;
hegyi@1878
    67
  if(mapstorage!=NULL)
hegyi@1878
    68
    {
hegyi@1878
    69
      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
hegyi@1878
    70
      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
hegyi@1878
    71
      nml=mapstorage->getNodeMapList();
hegyi@1879
    72
      eml=mapstorage->getEdgeMapList();
hegyi@1878
    73
    }
hegyi@1876
    74
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@1876
    75
    {
hegyi@1876
    76
      update_cbt(nml, *(nodemapcbts[i]));
hegyi@1876
    77
    }
hegyi@1876
    78
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@1876
    79
    {
hegyi@1876
    80
      update_cbt(eml, *(edgemapcbts[i]));
hegyi@1876
    81
    }
hegyi@1876
    82
}
hegyi@1876
    83
hegyi@1878
    84
void AlgoBox::nodemaplist_changed(std::string newmap)
hegyi@1878
    85
{
hegyi@1878
    86
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@1878
    87
    {
hegyi@1878
    88
      (nodemapcbts[i])->append_text(newmap);
hegyi@1878
    89
    }
hegyi@1878
    90
}
hegyi@1878
    91
hegyi@1878
    92
void AlgoBox::edgemaplist_changed(std::string newmap)
hegyi@1878
    93
{
hegyi@1878
    94
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@1878
    95
    {
hegyi@1878
    96
      (edgemapcbts[i])->append_text(newmap);
hegyi@1878
    97
    }
hegyi@1878
    98
}
hegyi@1878
    99
hegyi@1876
   100
void AlgoBox::run()
hegyi@1876
   101
{
hegyi@1876
   102
  std::cout << "Start algorithm." << std::endl;
hegyi@1876
   103
}
hegyi@1876
   104
hegyi@1876
   105
void AlgoBox::build_box()
hegyi@1876
   106
{
hegyi@1876
   107
  pack_start(*(new Gtk::HSeparator()));
hegyi@1876
   108
hegyi@1876
   109
  label=new Gtk::Label("Specific part for each algorithm.");
hegyi@1876
   110
      
hegyi@1876
   111
  pack_start(*label);
hegyi@1876
   112
  pack_start(*(new Gtk::HSeparator()));
hegyi@1876
   113
hegyi@1876
   114
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@1876
   115
      
hegyi@1876
   116
  pack_start(*label);
hegyi@1876
   117
hegyi@1876
   118
  nodemapcbts.resize(NODE_INPUT_NUM);
hegyi@1876
   119
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@1876
   120
    {
hegyi@1876
   121
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@1876
   122
hegyi@1876
   123
      std::ostringstream o;
hegyi@1876
   124
      o << "NodeInput " << i+1 << ":";
hegyi@1876
   125
      label=new Gtk::Label(o.str());
hegyi@1876
   126
hegyi@1876
   127
      nodemapcbts[i]=new Gtk::ComboBoxText();
hegyi@1876
   128
hegyi@1876
   129
      hbox->pack_start(*label);
hegyi@1876
   130
      hbox->pack_start(*(nodemapcbts[i]));
hegyi@1876
   131
      pack_start(*hbox);
hegyi@1876
   132
    }
hegyi@1876
   133
hegyi@1876
   134
  pack_start(*(new Gtk::HSeparator()));
hegyi@1876
   135
hegyi@1876
   136
  edgemapcbts.resize(EDGE_INPUT_NUM);
hegyi@1876
   137
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@1876
   138
    {
hegyi@1876
   139
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@1876
   140
hegyi@1876
   141
      std::ostringstream o;
hegyi@1876
   142
      o << "EdgeInput " << i+1 << ":";
hegyi@1876
   143
      label=new Gtk::Label(o.str());
hegyi@1876
   144
hegyi@1876
   145
      edgemapcbts[i]=new Gtk::ComboBoxText();
hegyi@1876
   146
hegyi@1876
   147
      hbox->pack_start(*label);
hegyi@1876
   148
      hbox->pack_start(*(edgemapcbts[i]));
hegyi@1876
   149
      pack_start(*hbox);
hegyi@1876
   150
    }
hegyi@1876
   151
hegyi@1876
   152
  pack_start(*(new Gtk::HSeparator()));
hegyi@1876
   153
}
hegyi@1876
   154
hegyi@1876
   155
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@1876
   156
{
hegyi@1876
   157
  return signal_maplist_need;
hegyi@1876
   158
}
hegyi@1876
   159
hegyi@1876
   160
void AlgoBox::emit_tab_change()
hegyi@1876
   161
{
hegyi@1878
   162
  std::string active_tab=tabcbt.get_active_text();
hegyi@1878
   163
  if(active_tab!="")
hegyi@1878
   164
    {
hegyi@1878
   165
      signal_maplist_need.emit(active_tab);
hegyi@1878
   166
    }
hegyi@1878
   167
  else
hegyi@1878
   168
    {
hegyi@1878
   169
      std::vector<std::string> empty_vector;
hegyi@1878
   170
      update_maplist(NULL);
hegyi@1878
   171
    }
hegyi@1876
   172
}