algowin.cc
author ladanyi
Wed, 02 Jan 2008 21:03:09 +0000
changeset 201 879e47e5b731
parent 174 95872af46fc4
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 <algowin.h>
hegyi@194
    20
#include <algobox.h>
hegyi@106
    21
#include <kruskalbox.h>
hegyi@162
    22
#include <dijkstrabox.h>
hegyi@106
    23
hegyi@106
    24
sigc::signal<void, AlgoWin *> AlgoWin::signal_closing()
hegyi@106
    25
{
hegyi@106
    26
  return signal_closed;
hegyi@106
    27
}
hegyi@106
    28
hegyi@106
    29
sigc::signal<void, AlgoWin *, std::string> AlgoWin::signal_maplist_needed()
hegyi@106
    30
{
hegyi@106
    31
  return signal_maplist_need;
hegyi@106
    32
}
hegyi@106
    33
hegyi@106
    34
bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e)
hegyi@106
    35
{
hegyi@106
    36
  if(e->keyval==GDK_Escape)
hegyi@106
    37
  {
hegyi@106
    38
    on_hide();
hegyi@106
    39
  }
hegyi@106
    40
  return true;
hegyi@106
    41
}
hegyi@106
    42
hegyi@108
    43
AlgoWin::AlgoWin(int algoid, std::vector<std::string> tabnames)
hegyi@106
    44
{
hegyi@106
    45
  signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed));
hegyi@106
    46
hegyi@106
    47
  Gtk::VBox * vbox=new Gtk::VBox();
hegyi@106
    48
  vbox->set_spacing(5);
hegyi@106
    49
hegyi@106
    50
  Gtk::Label * label=new Gtk::Label("Select graph:");
hegyi@106
    51
hegyi@106
    52
  switch(algoid)
hegyi@106
    53
    {
hegyi@106
    54
    case 0:
hegyi@108
    55
      ab=new AlgoBox(tabnames);
hegyi@106
    56
      set_title("Algo Win Demo");
hegyi@106
    57
      break;
hegyi@106
    58
    case 1:
hegyi@108
    59
      ab=new KruskalBox(tabnames);
hegyi@106
    60
      set_title("Kruskal Algorithm");
hegyi@106
    61
      break;
hegyi@162
    62
    case 2:
hegyi@162
    63
      ab=new DijkstraBox(tabnames);
hegyi@162
    64
      set_title("Dijkstra Algorithm");
hegyi@162
    65
      break;
hegyi@165
    66
    case 3:
hegyi@165
    67
      ab=new SuurballeBox(tabnames);
hegyi@165
    68
      set_title("Suurballe Algorithm");
hegyi@165
    69
      break;
hegyi@106
    70
    default:
hegyi@106
    71
      break;
hegyi@106
    72
    }
hegyi@106
    73
  ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change));
hegyi@114
    74
  ab->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_new_map_signal));
hegyi@106
    75
hegyi@106
    76
  runbutton=new Gtk::Button("Run");
hegyi@106
    77
  runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run));
hegyi@106
    78
  runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run));
hegyi@106
    79
hegyi@106
    80
  closebutton=new Gtk::Button("Close");
hegyi@106
    81
  closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
hegyi@106
    82
  closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
hegyi@106
    83
      
hegyi@106
    84
  Gtk::HBox * hbox=new Gtk::HBox();
hegyi@106
    85
hegyi@106
    86
  hbox->pack_start(*runbutton);
hegyi@106
    87
  hbox->pack_start(*closebutton);
hegyi@106
    88
hegyi@106
    89
  vbox->pack_start(*label);
hegyi@106
    90
  vbox->pack_start(*ab);
hegyi@106
    91
  vbox->pack_start(*hbox);
hegyi@106
    92
      
hegyi@106
    93
  add(*vbox);
hegyi@106
    94
hegyi@106
    95
  show_all_children();
hegyi@106
    96
};
hegyi@106
    97
hegyi@106
    98
void AlgoWin::update_tablist(std::vector<std::string> tabnames)
hegyi@106
    99
{
hegyi@106
   100
  ab->update_tablist(tabnames);
hegyi@106
   101
}
hegyi@106
   102
hegyi@109
   103
void AlgoWin::update_maplist(MapStorage * mapstorage)
hegyi@106
   104
{
hegyi@108
   105
  ab->update_maplist(mapstorage);
hegyi@106
   106
}
hegyi@106
   107
hegyi@106
   108
void AlgoWin::on_hide()
hegyi@106
   109
{
hegyi@106
   110
  signal_closed.emit(this);
hegyi@106
   111
  Gtk::Window::on_hide();
hegyi@106
   112
}
hegyi@106
   113
hegyi@106
   114
void AlgoWin::emit_tab_change(std::string newtab)
hegyi@106
   115
{
hegyi@106
   116
  signal_maplist_need.emit(this, newtab);
hegyi@106
   117
}