algobox.cc
author ladanyi
Wed, 02 Jan 2008 21:03:09 +0000
changeset 201 879e47e5b731
parent 194 6b2b718420eb
permissions -rw-r--r--
Merge branches/akos to trunk.
alpar@174
     1
/* -*- C++ -*-
alpar@174
     2
 *
alpar@174
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@174
     4
 *
alpar@174
     5
 * Copyright (C) 2003-2006
alpar@174
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@174
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@174
     8
 *
alpar@174
     9
 * Permission to use, modify and distribute this software is granted
alpar@174
    10
 * provided that this copyright notice appears in all copies. For
alpar@174
    11
 * precise terms see the accompanying LICENSE file.
alpar@174
    12
 *
alpar@174
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@174
    14
 * express or implied, and with no claim as to its suitability for any
alpar@174
    15
 * purpose.
alpar@174
    16
 *
alpar@174
    17
 */
alpar@174
    18
hegyi@106
    19
#include <algobox.h>
hegyi@194
    20
#include <mapstorage.h>
hegyi@194
    21
#include <mapselector.h>
hegyi@106
    22
hegyi@106
    23
enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
hegyi@106
    24
enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
hegyi@106
    25
hegyi@108
    26
AlgoBox::AlgoBox(std::vector<std::string> tabnames)
hegyi@106
    27
{
hegyi@108
    28
  init(tabnames);
hegyi@106
    29
}
hegyi@106
    30
hegyi@108
    31
void AlgoBox::init(std::vector<std::string> tabnames)
hegyi@106
    32
{
hegyi@106
    33
  set_spacing(5);
hegyi@106
    34
hegyi@106
    35
  update_tablist(tabnames);
hegyi@106
    36
hegyi@106
    37
  //if active tab is changed, the map names in cbt/s have to be updated
hegyi@106
    38
  tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
hegyi@106
    39
hegyi@106
    40
  pack_start(tabcbt);
hegyi@106
    41
  build_box();
hegyi@106
    42
hegyi@106
    43
  show_all_children();
hegyi@106
    44
};
hegyi@106
    45
hegyi@106
    46
void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
hegyi@106
    47
{
hegyi@106
    48
  std::string actname=cbt.get_active_text();
hegyi@106
    49
  int prev_act=-1;
hegyi@106
    50
hegyi@106
    51
  cbt.clear();
hegyi@106
    52
  int actptr=0;
hegyi@106
    53
hegyi@106
    54
  std::vector< std::string >::iterator emsi=stringlist.begin();
hegyi@106
    55
  for(;emsi!=stringlist.end();emsi++)
hegyi@106
    56
    {
hegyi@106
    57
      if(actname==*emsi)
hegyi@106
    58
	{
hegyi@106
    59
	  prev_act=actptr;
hegyi@106
    60
	}
hegyi@106
    61
hegyi@106
    62
      cbt.append_text(*emsi);
hegyi@106
    63
      actptr++;
hegyi@106
    64
    }
hegyi@106
    65
hegyi@106
    66
  if(prev_act!=-1)
hegyi@106
    67
    {
hegyi@106
    68
      cbt.set_active(prev_act);
hegyi@106
    69
    }
hegyi@106
    70
  else if(actptr>0) //so there is item in the list
hegyi@106
    71
    {
hegyi@108
    72
      //cbt.set_active(0);
hegyi@106
    73
    }
hegyi@106
    74
}
hegyi@106
    75
hegyi@106
    76
void AlgoBox::update_tablist( std::vector< std::string > tl )
hegyi@106
    77
{
hegyi@106
    78
  update_cbt(tl, tabcbt);
hegyi@106
    79
  emit_tab_change();
hegyi@106
    80
}
hegyi@106
    81
hegyi@109
    82
void AlgoBox::update_maplist(MapStorage * ms)
hegyi@106
    83
{
hegyi@109
    84
  mapstorage=ms;
ladanyi@201
    85
  std::vector<std::string> n_nml;
ladanyi@201
    86
  std::vector<std::string> s_nml;
ladanyi@201
    87
  std::vector<std::string> n_eml;
ladanyi@201
    88
  std::vector<std::string> s_eml;
hegyi@108
    89
  if(mapstorage!=NULL)
hegyi@108
    90
    {
hegyi@108
    91
      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
hegyi@108
    92
      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
ladanyi@201
    93
      n_nml=mapstorage->getNodeMapList(NUM);
ladanyi@201
    94
      s_nml=mapstorage->getNodeMapList(STR);
ladanyi@201
    95
      n_eml=mapstorage->getEdgeMapList(NUM);
ladanyi@201
    96
      s_eml=mapstorage->getEdgeMapList(STR);
hegyi@108
    97
    }
hegyi@106
    98
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    99
    {
ladanyi@201
   100
      (nodemapcbts[i])->update_list(n_nml, s_nml);
hegyi@114
   101
      //update_cbt(nml, *(nodemapcbts[i]));
hegyi@106
   102
    }
hegyi@106
   103
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
   104
    {
ladanyi@201
   105
      (edgemapcbts[i])->update_list(n_eml, s_eml);
hegyi@114
   106
      //update_cbt(eml, *(edgemapcbts[i]));
hegyi@106
   107
    }
hegyi@162
   108
  signal_maplist_updated.emit();
hegyi@106
   109
}
hegyi@106
   110
ladanyi@201
   111
void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type)
hegyi@108
   112
{
hegyi@108
   113
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@108
   114
    {
ladanyi@201
   115
      (nodemapcbts[i])->append_text(newmap, type);
hegyi@108
   116
    }
hegyi@108
   117
}
hegyi@108
   118
ladanyi@201
   119
void AlgoBox::edgemaplist_changed(std::string newmap, MapValue::Type type)
hegyi@108
   120
{
hegyi@108
   121
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@108
   122
    {
ladanyi@201
   123
      (edgemapcbts[i])->append_text(newmap, type);
hegyi@108
   124
    }
hegyi@108
   125
}
hegyi@108
   126
hegyi@106
   127
void AlgoBox::run()
hegyi@106
   128
{
hegyi@106
   129
  std::cout << "Start algorithm." << std::endl;
hegyi@106
   130
}
hegyi@106
   131
hegyi@106
   132
void AlgoBox::build_box()
hegyi@106
   133
{
hegyi@106
   134
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   135
hegyi@114
   136
  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
   137
      
hegyi@106
   138
  pack_start(*label);
hegyi@106
   139
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   140
hegyi@106
   141
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
   142
      
hegyi@106
   143
  pack_start(*label);
hegyi@106
   144
hegyi@116
   145
  for(int i=0;i<NODE_INPUT_NUM;i++)
hegyi@106
   146
    {
hegyi@106
   147
      std::ostringstream o;
hegyi@106
   148
      o << "NodeInput " << i+1 << ":";
hegyi@106
   149
hegyi@116
   150
      addMapSelector(o.str(), false);
hegyi@106
   151
    }
hegyi@106
   152
hegyi@106
   153
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   154
hegyi@116
   155
  for(int i=0;i<EDGE_INPUT_NUM;i++)
hegyi@106
   156
    {
hegyi@106
   157
hegyi@106
   158
      std::ostringstream o;
hegyi@106
   159
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   160
hegyi@116
   161
      addMapSelector(o.str(), true);
hegyi@106
   162
    }
hegyi@106
   163
hegyi@106
   164
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   165
}
hegyi@106
   166
ladanyi@201
   167
void AlgoBox::addMapSelector(std::string inputname, bool itisedge, MapType type)
hegyi@116
   168
{
hegyi@116
   169
  std::vector<std::string> empty_vector;
hegyi@116
   170
ladanyi@201
   171
  MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisedge, false, type);
hegyi@116
   172
hegyi@116
   173
  if(itisedge)
hegyi@116
   174
    {
hegyi@116
   175
      edgemapcbts.resize(edgemapcbts.size()+1);
hegyi@116
   176
      edgemapcbts[edgemapcbts.size()-1]=msp;
hegyi@116
   177
    }
hegyi@116
   178
  else
hegyi@116
   179
    {
hegyi@116
   180
      nodemapcbts.resize(nodemapcbts.size()+1);
hegyi@116
   181
      nodemapcbts[nodemapcbts.size()-1]=msp;
hegyi@116
   182
    }
hegyi@116
   183
hegyi@116
   184
  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@116
   185
hegyi@116
   186
  pack_start(*msp);
hegyi@116
   187
}
hegyi@116
   188
hegyi@106
   189
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   190
{
hegyi@106
   191
  return signal_maplist_need;
hegyi@106
   192
}
hegyi@106
   193
hegyi@106
   194
void AlgoBox::emit_tab_change()
hegyi@106
   195
{
hegyi@108
   196
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   197
  if(active_tab!="")
hegyi@108
   198
    {
hegyi@108
   199
      signal_maplist_need.emit(active_tab);
hegyi@108
   200
    }
hegyi@108
   201
  else
hegyi@108
   202
    {
hegyi@108
   203
      std::vector<std::string> empty_vector;
hegyi@108
   204
      update_maplist(NULL);
hegyi@108
   205
    }
hegyi@106
   206
}
hegyi@114
   207
hegyi@114
   208
void AlgoBox::emit_new_map_signal(bool itisedge)
hegyi@114
   209
{
hegyi@114
   210
  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
hegyi@114
   211
}