algobox.cc
author hegyi
Fri, 13 Oct 2006 13:53:44 +0000
changeset 163 443bc769b344
parent 116 2bd795bb9984
child 174 95872af46fc4
permissions -rw-r--r--
Dijkstra in GUI - and the body...
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@162
    84
  signal_maplist_updated.emit();
hegyi@106
    85
}
hegyi@106
    86
hegyi@108
    87
void AlgoBox::nodemaplist_changed(std::string newmap)
hegyi@108
    88
{
hegyi@108
    89
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@108
    90
    {
hegyi@108
    91
      (nodemapcbts[i])->append_text(newmap);
hegyi@108
    92
    }
hegyi@108
    93
}
hegyi@108
    94
hegyi@108
    95
void AlgoBox::edgemaplist_changed(std::string newmap)
hegyi@108
    96
{
hegyi@108
    97
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@108
    98
    {
hegyi@108
    99
      (edgemapcbts[i])->append_text(newmap);
hegyi@108
   100
    }
hegyi@108
   101
}
hegyi@108
   102
hegyi@106
   103
void AlgoBox::run()
hegyi@106
   104
{
hegyi@106
   105
  std::cout << "Start algorithm." << std::endl;
hegyi@106
   106
}
hegyi@106
   107
hegyi@106
   108
void AlgoBox::build_box()
hegyi@106
   109
{
hegyi@106
   110
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   111
hegyi@114
   112
  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
   113
      
hegyi@106
   114
  pack_start(*label);
hegyi@106
   115
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   116
hegyi@106
   117
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
   118
      
hegyi@106
   119
  pack_start(*label);
hegyi@106
   120
hegyi@116
   121
  for(int i=0;i<NODE_INPUT_NUM;i++)
hegyi@106
   122
    {
hegyi@106
   123
      std::ostringstream o;
hegyi@106
   124
      o << "NodeInput " << i+1 << ":";
hegyi@106
   125
hegyi@116
   126
      addMapSelector(o.str(), false);
hegyi@106
   127
    }
hegyi@106
   128
hegyi@106
   129
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   130
hegyi@116
   131
  for(int i=0;i<EDGE_INPUT_NUM;i++)
hegyi@106
   132
    {
hegyi@106
   133
hegyi@106
   134
      std::ostringstream o;
hegyi@106
   135
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   136
hegyi@116
   137
      addMapSelector(o.str(), true);
hegyi@106
   138
    }
hegyi@106
   139
hegyi@106
   140
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   141
}
hegyi@106
   142
hegyi@116
   143
void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
hegyi@116
   144
{
hegyi@116
   145
  std::vector<std::string> empty_vector;
hegyi@116
   146
hegyi@116
   147
  MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
hegyi@116
   148
hegyi@116
   149
  if(itisedge)
hegyi@116
   150
    {
hegyi@116
   151
      edgemapcbts.resize(edgemapcbts.size()+1);
hegyi@116
   152
      edgemapcbts[edgemapcbts.size()-1]=msp;
hegyi@116
   153
    }
hegyi@116
   154
  else
hegyi@116
   155
    {
hegyi@116
   156
      nodemapcbts.resize(nodemapcbts.size()+1);
hegyi@116
   157
      nodemapcbts[nodemapcbts.size()-1]=msp;
hegyi@116
   158
    }
hegyi@116
   159
hegyi@116
   160
  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@116
   161
hegyi@116
   162
  pack_start(*msp);
hegyi@116
   163
}
hegyi@116
   164
hegyi@106
   165
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   166
{
hegyi@106
   167
  return signal_maplist_need;
hegyi@106
   168
}
hegyi@106
   169
hegyi@106
   170
void AlgoBox::emit_tab_change()
hegyi@106
   171
{
hegyi@108
   172
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   173
  if(active_tab!="")
hegyi@108
   174
    {
hegyi@108
   175
      signal_maplist_need.emit(active_tab);
hegyi@108
   176
    }
hegyi@108
   177
  else
hegyi@108
   178
    {
hegyi@108
   179
      std::vector<std::string> empty_vector;
hegyi@108
   180
      update_maplist(NULL);
hegyi@108
   181
    }
hegyi@106
   182
}
hegyi@114
   183
hegyi@114
   184
void AlgoBox::emit_new_map_signal(bool itisedge)
hegyi@114
   185
{
hegyi@114
   186
  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
hegyi@114
   187
}