algobox.cc
author hegyi
Thu, 05 Jan 2006 12:30:09 +0000
branchgui
changeset 108 bf355fd6563e
parent 106 853dd852abc7
child 109 9f8dc346ac6e
permissions -rw-r--r--
Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
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@108
    62
void AlgoBox::update_maplist( void * ms)
hegyi@106
    63
{
hegyi@108
    64
  mapstorage=(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@108
    72
      eml=mapstorage->getNodeMapList();
hegyi@108
    73
    }
hegyi@106
    74
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    75
    {
hegyi@106
    76
      update_cbt(nml, *(nodemapcbts[i]));
hegyi@106
    77
    }
hegyi@106
    78
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
    79
    {
hegyi@106
    80
      update_cbt(eml, *(edgemapcbts[i]));
hegyi@106
    81
    }
hegyi@106
    82
}
hegyi@106
    83
hegyi@108
    84
void AlgoBox::nodemaplist_changed(std::string newmap)
hegyi@108
    85
{
hegyi@108
    86
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@108
    87
    {
hegyi@108
    88
      (nodemapcbts[i])->append_text(newmap);
hegyi@108
    89
    }
hegyi@108
    90
}
hegyi@108
    91
hegyi@108
    92
void AlgoBox::edgemaplist_changed(std::string newmap)
hegyi@108
    93
{
hegyi@108
    94
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@108
    95
    {
hegyi@108
    96
      (edgemapcbts[i])->append_text(newmap);
hegyi@108
    97
    }
hegyi@108
    98
}
hegyi@108
    99
hegyi@106
   100
void AlgoBox::run()
hegyi@106
   101
{
hegyi@106
   102
  std::cout << "Start algorithm." << std::endl;
hegyi@106
   103
}
hegyi@106
   104
hegyi@106
   105
void AlgoBox::build_box()
hegyi@106
   106
{
hegyi@106
   107
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   108
hegyi@106
   109
  label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
   110
      
hegyi@106
   111
  pack_start(*label);
hegyi@106
   112
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   113
hegyi@106
   114
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
   115
      
hegyi@106
   116
  pack_start(*label);
hegyi@106
   117
hegyi@106
   118
  nodemapcbts.resize(NODE_INPUT_NUM);
hegyi@106
   119
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
   120
    {
hegyi@106
   121
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@106
   122
hegyi@106
   123
      std::ostringstream o;
hegyi@106
   124
      o << "NodeInput " << i+1 << ":";
hegyi@106
   125
      label=new Gtk::Label(o.str());
hegyi@106
   126
hegyi@106
   127
      nodemapcbts[i]=new Gtk::ComboBoxText();
hegyi@106
   128
hegyi@106
   129
      hbox->pack_start(*label);
hegyi@106
   130
      hbox->pack_start(*(nodemapcbts[i]));
hegyi@106
   131
      pack_start(*hbox);
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@106
   139
      Gtk::HBox * hbox=new Gtk::HBox();
hegyi@106
   140
hegyi@106
   141
      std::ostringstream o;
hegyi@106
   142
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   143
      label=new Gtk::Label(o.str());
hegyi@106
   144
hegyi@106
   145
      edgemapcbts[i]=new Gtk::ComboBoxText();
hegyi@106
   146
hegyi@106
   147
      hbox->pack_start(*label);
hegyi@106
   148
      hbox->pack_start(*(edgemapcbts[i]));
hegyi@106
   149
      pack_start(*hbox);
hegyi@106
   150
    }
hegyi@106
   151
hegyi@106
   152
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   153
}
hegyi@106
   154
hegyi@106
   155
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   156
{
hegyi@106
   157
  return signal_maplist_need;
hegyi@106
   158
}
hegyi@106
   159
hegyi@106
   160
void AlgoBox::emit_tab_change()
hegyi@106
   161
{
hegyi@108
   162
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   163
  if(active_tab!="")
hegyi@108
   164
    {
hegyi@108
   165
      signal_maplist_need.emit(active_tab);
hegyi@108
   166
    }
hegyi@108
   167
  else
hegyi@108
   168
    {
hegyi@108
   169
      std::vector<std::string> empty_vector;
hegyi@108
   170
      update_maplist(NULL);
hegyi@108
   171
    }
hegyi@106
   172
}