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