algobox.cc
author hegyi
Thu, 01 Mar 2007 13:33:46 +0000
changeset 196 c220f9de6545
parent 174 95872af46fc4
child 201 879e47e5b731
permissions -rw-r--r--
EpsWin and DesignWin does not need to know NoteBookTab.
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;
hegyi@108
    85
  std::vector<std::string> nml;
hegyi@108
    86
  std::vector<std::string> eml;
hegyi@108
    87
  if(mapstorage!=NULL)
hegyi@108
    88
    {
hegyi@108
    89
      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
hegyi@108
    90
      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
hegyi@108
    91
      nml=mapstorage->getNodeMapList();
hegyi@109
    92
      eml=mapstorage->getEdgeMapList();
hegyi@108
    93
    }
hegyi@106
    94
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@106
    95
    {
hegyi@114
    96
      (nodemapcbts[i])->update_list(nml);
hegyi@114
    97
      //update_cbt(nml, *(nodemapcbts[i]));
hegyi@106
    98
    }
hegyi@106
    99
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@106
   100
    {
hegyi@114
   101
      (edgemapcbts[i])->update_list(eml);
hegyi@114
   102
      //update_cbt(eml, *(edgemapcbts[i]));
hegyi@106
   103
    }
hegyi@162
   104
  signal_maplist_updated.emit();
hegyi@106
   105
}
hegyi@106
   106
hegyi@108
   107
void AlgoBox::nodemaplist_changed(std::string newmap)
hegyi@108
   108
{
hegyi@108
   109
  for(int i=0;i<(int)nodemapcbts.size();i++)
hegyi@108
   110
    {
hegyi@108
   111
      (nodemapcbts[i])->append_text(newmap);
hegyi@108
   112
    }
hegyi@108
   113
}
hegyi@108
   114
hegyi@108
   115
void AlgoBox::edgemaplist_changed(std::string newmap)
hegyi@108
   116
{
hegyi@108
   117
  for(int i=0;i<(int)edgemapcbts.size();i++)
hegyi@108
   118
    {
hegyi@108
   119
      (edgemapcbts[i])->append_text(newmap);
hegyi@108
   120
    }
hegyi@108
   121
}
hegyi@108
   122
hegyi@106
   123
void AlgoBox::run()
hegyi@106
   124
{
hegyi@106
   125
  std::cout << "Start algorithm." << std::endl;
hegyi@106
   126
}
hegyi@106
   127
hegyi@106
   128
void AlgoBox::build_box()
hegyi@106
   129
{
hegyi@106
   130
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   131
hegyi@114
   132
  Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
hegyi@106
   133
      
hegyi@106
   134
  pack_start(*label);
hegyi@106
   135
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   136
hegyi@106
   137
  label=new Gtk::Label("Maps in chosen tab:");
hegyi@106
   138
      
hegyi@106
   139
  pack_start(*label);
hegyi@106
   140
hegyi@116
   141
  for(int i=0;i<NODE_INPUT_NUM;i++)
hegyi@106
   142
    {
hegyi@106
   143
      std::ostringstream o;
hegyi@106
   144
      o << "NodeInput " << i+1 << ":";
hegyi@106
   145
hegyi@116
   146
      addMapSelector(o.str(), false);
hegyi@106
   147
    }
hegyi@106
   148
hegyi@106
   149
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   150
hegyi@116
   151
  for(int i=0;i<EDGE_INPUT_NUM;i++)
hegyi@106
   152
    {
hegyi@106
   153
hegyi@106
   154
      std::ostringstream o;
hegyi@106
   155
      o << "EdgeInput " << i+1 << ":";
hegyi@106
   156
hegyi@116
   157
      addMapSelector(o.str(), true);
hegyi@106
   158
    }
hegyi@106
   159
hegyi@106
   160
  pack_start(*(new Gtk::HSeparator()));
hegyi@106
   161
}
hegyi@106
   162
hegyi@116
   163
void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
hegyi@116
   164
{
hegyi@116
   165
  std::vector<std::string> empty_vector;
hegyi@116
   166
hegyi@116
   167
  MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
hegyi@116
   168
hegyi@116
   169
  if(itisedge)
hegyi@116
   170
    {
hegyi@116
   171
      edgemapcbts.resize(edgemapcbts.size()+1);
hegyi@116
   172
      edgemapcbts[edgemapcbts.size()-1]=msp;
hegyi@116
   173
    }
hegyi@116
   174
  else
hegyi@116
   175
    {
hegyi@116
   176
      nodemapcbts.resize(nodemapcbts.size()+1);
hegyi@116
   177
      nodemapcbts[nodemapcbts.size()-1]=msp;
hegyi@116
   178
    }
hegyi@116
   179
hegyi@116
   180
  msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
hegyi@116
   181
hegyi@116
   182
  pack_start(*msp);
hegyi@116
   183
}
hegyi@116
   184
hegyi@106
   185
sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
hegyi@106
   186
{
hegyi@106
   187
  return signal_maplist_need;
hegyi@106
   188
}
hegyi@106
   189
hegyi@106
   190
void AlgoBox::emit_tab_change()
hegyi@106
   191
{
hegyi@108
   192
  std::string active_tab=tabcbt.get_active_text();
hegyi@108
   193
  if(active_tab!="")
hegyi@108
   194
    {
hegyi@108
   195
      signal_maplist_need.emit(active_tab);
hegyi@108
   196
    }
hegyi@108
   197
  else
hegyi@108
   198
    {
hegyi@108
   199
      std::vector<std::string> empty_vector;
hegyi@108
   200
      update_maplist(NULL);
hegyi@108
   201
    }
hegyi@106
   202
}
hegyi@114
   203
hegyi@114
   204
void AlgoBox::emit_new_map_signal(bool itisedge)
hegyi@114
   205
{
hegyi@114
   206
  signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
hegyi@114
   207
}