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