design_win.cc
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Mon, 07 Jul 2008 15:20:43 +0100
changeset 3 2cc5ed6e6255
permissions -rw-r--r--
Use hg changeset hash instead of svn revision.
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 <design_win.h>
hegyi@1
    20
hegyi@1
    21
bool DesignWin::closeIfEscapeIsPressed(GdkEventKey* e)
hegyi@1
    22
{
hegyi@1
    23
  if(e->keyval==GDK_Escape)
hegyi@1
    24
  {
hegyi@1
    25
    on_hide();
hegyi@1
    26
  }
hegyi@1
    27
  return true;
hegyi@1
    28
}
hegyi@1
    29
hegyi@1
    30
DesignWin::DesignWin(const std::string& title, double attraction_v, double propulsation_v, int iterations_v)
hegyi@1
    31
{
hegyi@1
    32
  set_title(title);
hegyi@1
    33
hegyi@1
    34
  //mytab.signal_title_ch().connect(sigc::mem_fun(*this, &DesignWin::set_title));
hegyi@1
    35
hegyi@1
    36
  signal_key_press_event().connect(sigc::mem_fun(*this, &DesignWin::closeIfEscapeIsPressed));
hegyi@1
    37
hegyi@1
    38
  Gtk::VBox * vbox=new Gtk::VBox();
hegyi@1
    39
  vbox->set_spacing(5);
hegyi@1
    40
hegyi@1
    41
  Gtk::Label * attraction_label=new Gtk::Label("Arc elasticity: ");
hegyi@1
    42
  Gtk::Label * propulsation_label=new Gtk::Label("Node propulsation: ");
hegyi@1
    43
  Gtk::Label * iteration_label=new Gtk::Label("Iteration number: ");
hegyi@1
    44
hegyi@1
    45
  Gtk::Adjustment * attraction_adjustment=new Gtk::Adjustment(attraction_v, 0,1,0.01,0.1);
hegyi@1
    46
  Gtk::Adjustment * propulsation_adjustment=new Gtk::Adjustment(propulsation_v,0,1000000,1000,10000);
hegyi@1
    47
  Gtk::Adjustment * iteration_adjustment=new Gtk::Adjustment(iterations_v,1,20000,5,10);
hegyi@1
    48
hegyi@1
    49
  attraction = new Gtk::SpinButton(*attraction_adjustment,5,3);
hegyi@1
    50
  propulsation = new Gtk::SpinButton(*propulsation_adjustment,5,0);
hegyi@1
    51
  iteration = new Gtk::SpinButton(*iteration_adjustment,5,0);
hegyi@1
    52
hegyi@1
    53
  close_button=new Gtk::Button("Redesign");
hegyi@1
    54
hegyi@1
    55
  attraction->signal_value_changed().connect(sigc::mem_fun(*this, &DesignWin::emit_attraction));
hegyi@1
    56
  propulsation->signal_value_changed().connect(sigc::mem_fun(*this, &DesignWin::emit_propulsation));
hegyi@1
    57
  iteration->signal_value_changed().connect(sigc::mem_fun(*this, &DesignWin::emit_iteration));
hegyi@1
    58
  close_button->signal_pressed().connect(sigc::mem_fun(*this, &DesignWin::emit_closerun));
hegyi@1
    59
hegyi@1
    60
  table.attach(*attraction_label,0,1,0,1);
hegyi@1
    61
  table.attach(*propulsation_label,0,1,1,2);
hegyi@1
    62
  table.attach(*iteration_label,0,1,2,3);
hegyi@1
    63
  table.attach(*attraction,1,2,0,1);
hegyi@1
    64
  table.attach(*propulsation,1,2,1,2);
hegyi@1
    65
  table.attach(*iteration,1,2,2,3);
hegyi@1
    66
  table.attach(*close_button,0,2,3,4);
hegyi@1
    67
hegyi@1
    68
  add(table);
hegyi@1
    69
hegyi@1
    70
  show_all_children();
hegyi@1
    71
};
hegyi@1
    72
hegyi@1
    73
void DesignWin::emit_attraction()
hegyi@1
    74
{
hegyi@1
    75
  signal_attraction_ch.emit(attraction->get_value());
hegyi@1
    76
}
hegyi@1
    77
hegyi@1
    78
void DesignWin::emit_propulsation()
hegyi@1
    79
{
hegyi@1
    80
  signal_propulsation_ch.emit(propulsation->get_value());
hegyi@1
    81
}
hegyi@1
    82
hegyi@1
    83
void DesignWin::emit_iteration()
hegyi@1
    84
{
hegyi@1
    85
  signal_iteration_ch.emit((int)iteration->get_value());
hegyi@1
    86
}
hegyi@1
    87
hegyi@1
    88
void DesignWin::set_title(std::string tabname)
hegyi@1
    89
{
hegyi@1
    90
  Gtk::Window::set_title("Design Setup - "+tabname);
hegyi@1
    91
}
hegyi@1
    92
hegyi@1
    93
void DesignWin::set_data(double attr, double propuls, int it)
hegyi@1
    94
{
hegyi@1
    95
  attraction->set_value(attr);
hegyi@1
    96
  propulsation->set_value(propuls);
hegyi@1
    97
  iteration->set_value(it);
hegyi@1
    98
}