algobox.cc
author hegyi
Fri, 06 Jan 2006 16:07:08 +0000
branchgui
changeset 114 0ace7edbb06f
parent 109 9f8dc346ac6e
child 116 2bd795bb9984
permissions -rw-r--r--
In algorithm window maps can be selected and reated through MapSelector widget.
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@106
   120
  nodemapcbts.resize(NODE_INPUT_NUM);
hegyi@106
   121
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
   122
    {
hegyi@114
   123
      std::vector<std::string> empty_vector;
hegyi@106
   124
hegyi@106
   125
      std::ostringstream o;
hegyi@106
   126
      o << "NodeInput " << i+1 << ":";
hegyi@106
   127
hegyi@114
   128
      nodemapcbts[i]=new MapSelector(empty_vector,"",o.str(),false, false);
hegyi@114
   129
      nodemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@106
   130
hegyi@114
   131
      pack_start(*(nodemapcbts[i]));
hegyi@106
   132
    }
hegyi@106
   133
hegyi@106
   134
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   135
hegyi@106
   136
  edgemapcbts.resize(EDGE_INPUT_NUM);
hegyi@106
   137
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
   138
    {
hegyi@114
   139
      std::vector<std::string> empty_vector;
hegyi@106
   140
hegyi@106
   141
      std::ostringstream o;
hegyi@106
   142
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   143
hegyi@114
   144
      edgemapcbts[i]=new MapSelector(empty_vector,"",o.str(),true, false);
hegyi@114
   145
      edgemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@106
   146
hegyi@114
   147
      pack_start(*(edgemapcbts[i]));
hegyi@106
   148
    }
hegyi@106
   149
hegyi@106
   150
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   151
}
hegyi@106
   152
hegyi@106
   153
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   154
{
hegyi@106
   155
  return signal_maplist_need;
hegyi@106
   156
}
hegyi@106
   157
hegyi@106
   158
void AlgoBox::emit_tab_change()
hegyi@106
   159
{
hegyi@108
   160
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   161
  if(active_tab!="")
hegyi@108
   162
    {
hegyi@108
   163
      signal_maplist_need.emit(active_tab);
hegyi@108
   164
    }
hegyi@108
   165
  else
hegyi@108
   166
    {
hegyi@108
   167
      std::vector<std::string> empty_vector;
hegyi@108
   168
      update_maplist(NULL);
hegyi@108
   169
    }
hegyi@106
   170
}
hegyi@114
   171
hegyi@114
   172
void AlgoBox::emit_new_map_signal(bool itisedge)
hegyi@114
   173
{
hegyi@114
   174
  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
hegyi@114
   175
}