map_win.cc
author Peter Hegyi <hegyi@tmit.bme.hu>
Wed, 13 Aug 2008 17:24:25 +0100
changeset 6 3a44a2bb6da8
permissions -rw-r--r--
Remove lemon/graph_utils.h include.
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 <map_win.h>
hegyi@1
    20
#include <nbtab.h>
hegyi@1
    21
#include <mapselector.h>
hegyi@1
    22
#include <set>
hegyi@1
    23
hegyi@1
    24
bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e)
hegyi@1
    25
{
hegyi@1
    26
  if(e->keyval==GDK_Escape)
hegyi@1
    27
  {
hegyi@1
    28
    mytab.closeMapWin();
hegyi@1
    29
    //    hide();
hegyi@1
    30
  }
hegyi@1
    31
  return true;
hegyi@1
    32
}
hegyi@1
    33
hegyi@1
    34
MapWin::MapWin(const std::string& title,
hegyi@1
    35
    std::vector<std::string> n_eml,
hegyi@1
    36
    std::vector<std::string> s_eml,
hegyi@1
    37
    std::vector<std::string> n_nml,
hegyi@1
    38
    std::vector<std::string> s_nml,
hegyi@1
    39
    NoteBookTab & mw):mytab(mw)
hegyi@1
    40
{
hegyi@1
    41
  set_title(title);
hegyi@1
    42
  set_default_size(200, 50);
hegyi@1
    43
hegyi@1
    44
  set_resizable(false);
hegyi@1
    45
hegyi@1
    46
  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
hegyi@1
    47
hegyi@1
    48
  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &MapWin::set_title));
hegyi@1
    49
hegyi@1
    50
  e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM];
hegyi@1
    51
hegyi@1
    52
  table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false);
hegyi@1
    53
hegyi@1
    54
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1
    55
  {
hegyi@1
    56
    switch (i)
hegyi@1
    57
    {
hegyi@1
    58
      case E_WIDTH:
hegyi@1
    59
        e_combo_array[i]=new MapSelector(n_eml, s_eml,
hegyi@1
    60
            mytab.getActiveArcMap(i), arc_property_strings[i],
hegyi@1
    61
            true, true, NUM);
hegyi@1
    62
        break;
hegyi@1
    63
      case E_COLOR:
hegyi@1
    64
        e_combo_array[i]=new MapSelector(n_eml, s_eml,
hegyi@1
    65
            mytab.getActiveArcMap(i), arc_property_strings[i],
hegyi@1
    66
            true, true, NUM);
hegyi@1
    67
        break;
hegyi@1
    68
      case E_TEXT:
hegyi@1
    69
        e_combo_array[i]=new MapSelector(n_eml, s_eml,
hegyi@1
    70
            mytab.getActiveArcMap(i), arc_property_strings[i],
hegyi@1
    71
            true, true, ALL);
hegyi@1
    72
        break;
hegyi@1
    73
    }
hegyi@1
    74
hegyi@1
    75
    (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1
    76
hegyi@1
    77
    e_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::arcMapChanged), i));
hegyi@1
    78
    e_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded));
hegyi@1
    79
  }
hegyi@1
    80
hegyi@1
    81
  vbox.pack_start(*(new Gtk::Label("Arc properties")));
hegyi@1
    82
hegyi@1
    83
  vbox.pack_start(*table);
hegyi@1
    84
hegyi@1
    85
  vbox.pack_start(*(new Gtk::HSeparator));
hegyi@1
    86
hegyi@1
    87
  n_combo_array=new MapSelector * [NODE_PROPERTY_NUM];
hegyi@1
    88
hegyi@1
    89
  table=new Gtk::Table(NODE_PROPERTY_NUM, 1, false);
hegyi@1
    90
hegyi@1
    91
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1
    92
  {
hegyi@1
    93
    switch (i)
hegyi@1
    94
    {
hegyi@1
    95
      case N_RADIUS:
hegyi@1
    96
        n_combo_array[i]=new MapSelector(n_nml, s_nml,
hegyi@1
    97
            mytab.getActiveNodeMap(i), node_property_strings[i],
hegyi@1
    98
            false, true, NUM);
hegyi@1
    99
        break;
hegyi@1
   100
      case N_COLOR:
hegyi@1
   101
        n_combo_array[i]=new MapSelector(n_nml, s_nml,
hegyi@1
   102
            mytab.getActiveNodeMap(i), node_property_strings[i],
hegyi@1
   103
            false, true, NUM);
hegyi@1
   104
        break;
hegyi@1
   105
      case N_TEXT:
hegyi@1
   106
        n_combo_array[i]=new MapSelector(n_nml, s_nml,
hegyi@1
   107
            mytab.getActiveNodeMap(i), node_property_strings[i],
hegyi@1
   108
            false, true, ALL);
hegyi@1
   109
        break;
hegyi@1
   110
    }
hegyi@1
   111
hegyi@1
   112
    (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1
   113
hegyi@1
   114
    n_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::nodeMapChanged), i));
hegyi@1
   115
    n_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded));
hegyi@1
   116
  }
hegyi@1
   117
hegyi@1
   118
  add(vbox);
hegyi@1
   119
hegyi@1
   120
  vbox.pack_start(*(new Gtk::Label("Node properties")));
hegyi@1
   121
hegyi@1
   122
  vbox.pack_start(*table);
hegyi@1
   123
hegyi@1
   124
  update(n_eml, s_eml, n_nml, s_nml);
hegyi@1
   125
hegyi@1
   126
  show_all_children();
hegyi@1
   127
hegyi@1
   128
}
hegyi@1
   129
hegyi@1
   130
void MapWin::nodeMapChanged(std::string mapname, int prop)
hegyi@1
   131
{
hegyi@1
   132
  mytab.propertyChange(false, prop, mapname);
hegyi@1
   133
}
hegyi@1
   134
hegyi@1
   135
void MapWin::arcMapChanged(std::string mapname, int prop)
hegyi@1
   136
{
hegyi@1
   137
  mytab.propertyChange(true, prop, mapname);
hegyi@1
   138
}
hegyi@1
   139
hegyi@1
   140
void MapWin::newMapWinNeeded(bool itisarc)
hegyi@1
   141
{
hegyi@1
   142
  mytab.popupNewMapWin(itisarc);
hegyi@1
   143
}
hegyi@1
   144
hegyi@1
   145
void MapWin::update(
hegyi@1
   146
    std::vector<std::string> n_eml,
hegyi@1
   147
    std::vector<std::string> s_eml,
hegyi@1
   148
    std::vector<std::string> n_nml,
hegyi@1
   149
    std::vector<std::string> s_nml)
hegyi@1
   150
{
hegyi@1
   151
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1
   152
  {
hegyi@1
   153
    e_combo_array[i]->update_list(n_eml, s_eml);
hegyi@1
   154
  }
hegyi@1
   155
hegyi@1
   156
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1
   157
  {
hegyi@1
   158
    n_combo_array[i]->update_list(n_nml, s_nml);
hegyi@1
   159
  }
hegyi@1
   160
hegyi@1
   161
  mytab.active_maps_needed();
hegyi@1
   162
}
hegyi@1
   163
hegyi@1
   164
void MapWin::registerNewArcMap(std::string newmapname, MapValue::Type type)
hegyi@1
   165
{
hegyi@1
   166
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1
   167
  {
hegyi@1
   168
    //filling in combo box with choices
hegyi@1
   169
    e_combo_array[i]->append_text((Glib::ustring)newmapname, type);
hegyi@1
   170
  }
hegyi@1
   171
}
hegyi@1
   172
hegyi@1
   173
void MapWin::registerNewNodeMap(std::string newmapname, MapValue::Type type)
hegyi@1
   174
{
hegyi@1
   175
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1
   176
  {
hegyi@1
   177
    //filling in combo box with choices
hegyi@1
   178
    n_combo_array[i]->append_text((Glib::ustring)newmapname, type);
hegyi@1
   179
  }
hegyi@1
   180
}
hegyi@1
   181
hegyi@1
   182
bool MapWin::on_delete_event(GdkEventAny * event)
hegyi@1
   183
{
hegyi@1
   184
  event=event;
hegyi@1
   185
  mytab.closeMapWin();
hegyi@1
   186
  return true;
hegyi@1
   187
}
hegyi@1
   188
hegyi@1
   189
void MapWin::changeEntry(bool isitarc, int prop, std::string mapname)
hegyi@1
   190
{
hegyi@1
   191
  if(isitarc)
hegyi@1
   192
    {
hegyi@1
   193
      e_combo_array[prop]->set_active_text(mapname);
hegyi@1
   194
    }
hegyi@1
   195
  else
hegyi@1
   196
    {
hegyi@1
   197
      n_combo_array[prop]->set_active_text(mapname);
hegyi@1
   198
    }
hegyi@1
   199
}
hegyi@1
   200
hegyi@1
   201
void MapWin::set_title(std::string tabname)
hegyi@1
   202
{
hegyi@1
   203
  Gtk::Window::set_title("Map Setup - "+tabname);
hegyi@1
   204
}