algobox.cc
author hegyi
Mon, 09 Jan 2006 11:55:47 +0000
branchgui
changeset 116 2bd795bb9984
parent 114 0ace7edbb06f
child 162 aaa517c9dc23
permissions -rw-r--r--
Creation of algorithm dialog is even simpler by the usage of the newly created addMapSelector function.
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@108
     6
AlgoBox::AlgoBox(std::vector<std::string> tabnames)
hegyi@106
     7
{
hegyi@108
     8
  init(tabnames);
hegyi@106
     9
}
hegyi@106
    10
hegyi@108
    11
void AlgoBox::init(std::vector<std::string> tabnames)
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
  build_box();
hegyi@106
    22
hegyi@106
    23
  show_all_children();
hegyi@106
    24
};
hegyi@106
    25
hegyi@106
    26
void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
hegyi@106
    27
{
hegyi@106
    28
  std::string actname=cbt.get_active_text();
hegyi@106
    29
  int prev_act=-1;
hegyi@106
    30
hegyi@106
    31
  cbt.clear();
hegyi@106
    32
  int actptr=0;
hegyi@106
    33
hegyi@106
    34
  std::vector< std::string >::iterator emsi=stringlist.begin();
hegyi@106
    35
  for(;emsi!=stringlist.end();emsi++)
hegyi@106
    36
    {
hegyi@106
    37
      if(actname==*emsi)
hegyi@106
    38
	{
hegyi@106
    39
	  prev_act=actptr;
hegyi@106
    40
	}
hegyi@106
    41
hegyi@106
    42
      cbt.append_text(*emsi);
hegyi@106
    43
      actptr++;
hegyi@106
    44
    }
hegyi@106
    45
hegyi@106
    46
  if(prev_act!=-1)
hegyi@106
    47
    {
hegyi@106
    48
      cbt.set_active(prev_act);
hegyi@106
    49
    }
hegyi@106
    50
  else if(actptr>0) //so there is item in the list
hegyi@106
    51
    {
hegyi@108
    52
      //cbt.set_active(0);
hegyi@106
    53
    }
hegyi@106
    54
}
hegyi@106
    55
hegyi@106
    56
void AlgoBox::update_tablist( std::vector< std::string > tl )
hegyi@106
    57
{
hegyi@106
    58
  update_cbt(tl, tabcbt);
hegyi@106
    59
  emit_tab_change();
hegyi@106
    60
}
hegyi@106
    61
hegyi@109
    62
void AlgoBox::update_maplist(MapStorage * ms)
hegyi@106
    63
{
hegyi@109
    64
  mapstorage=ms;
hegyi@108
    65
  std::vector<std::string> nml;
hegyi@108
    66
  std::vector<std::string> eml;
hegyi@108
    67
  if(mapstorage!=NULL)
hegyi@108
    68
    {
hegyi@108
    69
      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
hegyi@108
    70
      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
hegyi@108
    71
      nml=mapstorage->getNodeMapList();
hegyi@109
    72
      eml=mapstorage->getEdgeMapList();
hegyi@108
    73
    }
hegyi@106
    74
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    75
    {
hegyi@114
    76
      (nodemapcbts[i])->update_list(nml);
hegyi@114
    77
      //update_cbt(nml, *(nodemapcbts[i]));
hegyi@106
    78
    }
hegyi@106
    79
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
    80
    {
hegyi@114
    81
      (edgemapcbts[i])->update_list(eml);
hegyi@114
    82
      //update_cbt(eml, *(edgemapcbts[i]));
hegyi@106
    83
    }
hegyi@106
    84
}
hegyi@106
    85
hegyi@108
    86
void AlgoBox::nodemaplist_changed(std::string newmap)
hegyi@108
    87
{
hegyi@108
    88
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@108
    89
    {
hegyi@108
    90
      (nodemapcbts[i])->append_text(newmap);
hegyi@108
    91
    }
hegyi@108
    92
}
hegyi@108
    93
hegyi@108
    94
void AlgoBox::edgemaplist_changed(std::string newmap)
hegyi@108
    95
{
hegyi@108
    96
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@108
    97
    {
hegyi@108
    98
      (edgemapcbts[i])->append_text(newmap);
hegyi@108
    99
    }
hegyi@108
   100
}
hegyi@108
   101
hegyi@106
   102
void AlgoBox::run()
hegyi@106
   103
{
hegyi@106
   104
  std::cout << "Start algorithm." << std::endl;
hegyi@106
   105
}
hegyi@106
   106
hegyi@106
   107
void AlgoBox::build_box()
hegyi@106
   108
{
hegyi@106
   109
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   110
hegyi@114
   111
  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
   112
      
hegyi@106
   113
  pack_start(*label);
hegyi@106
   114
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   115
hegyi@106
   116
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
   117
      
hegyi@106
   118
  pack_start(*label);
hegyi@106
   119
hegyi@116
   120
  for(int i=0;i<NODE_INPUT_NUM;i++)
hegyi@106
   121
    {
hegyi@106
   122
      std::ostringstream o;
hegyi@106
   123
      o << "NodeInput " << i+1 << ":";
hegyi@106
   124
hegyi@116
   125
      addMapSelector(o.str(), false);
hegyi@106
   126
    }
hegyi@106
   127
hegyi@106
   128
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   129
hegyi@116
   130
  for(int i=0;i<EDGE_INPUT_NUM;i++)
hegyi@106
   131
    {
hegyi@106
   132
hegyi@106
   133
      std::ostringstream o;
hegyi@106
   134
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   135
hegyi@116
   136
      addMapSelector(o.str(), true);
hegyi@106
   137
    }
hegyi@106
   138
hegyi@106
   139
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   140
}
hegyi@106
   141
hegyi@116
   142
void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
hegyi@116
   143
{
hegyi@116
   144
  std::vector<std::string> empty_vector;
hegyi@116
   145
hegyi@116
   146
  MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
hegyi@116
   147
hegyi@116
   148
  if(itisedge)
hegyi@116
   149
    {
hegyi@116
   150
      edgemapcbts.resize(edgemapcbts.size()+1);
hegyi@116
   151
      edgemapcbts[edgemapcbts.size()-1]=msp;
hegyi@116
   152
    }
hegyi@116
   153
  else
hegyi@116
   154
    {
hegyi@116
   155
      nodemapcbts.resize(nodemapcbts.size()+1);
hegyi@116
   156
      nodemapcbts[nodemapcbts.size()-1]=msp;
hegyi@116
   157
    }
hegyi@116
   158
hegyi@116
   159
  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@116
   160
hegyi@116
   161
  pack_start(*msp);
hegyi@116
   162
}
hegyi@116
   163
hegyi@106
   164
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   165
{
hegyi@106
   166
  return signal_maplist_need;
hegyi@106
   167
}
hegyi@106
   168
hegyi@106
   169
void AlgoBox::emit_tab_change()
hegyi@106
   170
{
hegyi@108
   171
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   172
  if(active_tab!="")
hegyi@108
   173
    {
hegyi@108
   174
      signal_maplist_need.emit(active_tab);
hegyi@108
   175
    }
hegyi@108
   176
  else
hegyi@108
   177
    {
hegyi@108
   178
      std::vector<std::string> empty_vector;
hegyi@108
   179
      update_maplist(NULL);
hegyi@108
   180
    }
hegyi@106
   181
}
hegyi@114
   182
hegyi@114
   183
void AlgoBox::emit_new_map_signal(bool itisedge)
hegyi@114
   184
{
hegyi@114
   185
  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
hegyi@114
   186
}