map_win.cc
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/map_win.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,204 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <map_win.h>
    1.23 +#include <nbtab.h>
    1.24 +#include <mapselector.h>
    1.25 +#include <set>
    1.26 +
    1.27 +bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e)
    1.28 +{
    1.29 +  if(e->keyval==GDK_Escape)
    1.30 +  {
    1.31 +    mytab.closeMapWin();
    1.32 +    //    hide();
    1.33 +  }
    1.34 +  return true;
    1.35 +}
    1.36 +
    1.37 +MapWin::MapWin(const std::string& title,
    1.38 +    std::vector<std::string> n_eml,
    1.39 +    std::vector<std::string> s_eml,
    1.40 +    std::vector<std::string> n_nml,
    1.41 +    std::vector<std::string> s_nml,
    1.42 +    NoteBookTab & mw):mytab(mw)
    1.43 +{
    1.44 +  set_title(title);
    1.45 +  set_default_size(200, 50);
    1.46 +
    1.47 +  set_resizable(false);
    1.48 +
    1.49 +  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
    1.50 +
    1.51 +  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &MapWin::set_title));
    1.52 +
    1.53 +  e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM];
    1.54 +
    1.55 +  table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false);
    1.56 +
    1.57 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    1.58 +  {
    1.59 +    switch (i)
    1.60 +    {
    1.61 +      case E_WIDTH:
    1.62 +        e_combo_array[i]=new MapSelector(n_eml, s_eml,
    1.63 +            mytab.getActiveArcMap(i), arc_property_strings[i],
    1.64 +            true, true, NUM);
    1.65 +        break;
    1.66 +      case E_COLOR:
    1.67 +        e_combo_array[i]=new MapSelector(n_eml, s_eml,
    1.68 +            mytab.getActiveArcMap(i), arc_property_strings[i],
    1.69 +            true, true, NUM);
    1.70 +        break;
    1.71 +      case E_TEXT:
    1.72 +        e_combo_array[i]=new MapSelector(n_eml, s_eml,
    1.73 +            mytab.getActiveArcMap(i), arc_property_strings[i],
    1.74 +            true, true, ALL);
    1.75 +        break;
    1.76 +    }
    1.77 +
    1.78 +    (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.79 +
    1.80 +    e_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::arcMapChanged), i));
    1.81 +    e_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded));
    1.82 +  }
    1.83 +
    1.84 +  vbox.pack_start(*(new Gtk::Label("Arc properties")));
    1.85 +
    1.86 +  vbox.pack_start(*table);
    1.87 +
    1.88 +  vbox.pack_start(*(new Gtk::HSeparator));
    1.89 +
    1.90 +  n_combo_array=new MapSelector * [NODE_PROPERTY_NUM];
    1.91 +
    1.92 +  table=new Gtk::Table(NODE_PROPERTY_NUM, 1, false);
    1.93 +
    1.94 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    1.95 +  {
    1.96 +    switch (i)
    1.97 +    {
    1.98 +      case N_RADIUS:
    1.99 +        n_combo_array[i]=new MapSelector(n_nml, s_nml,
   1.100 +            mytab.getActiveNodeMap(i), node_property_strings[i],
   1.101 +            false, true, NUM);
   1.102 +        break;
   1.103 +      case N_COLOR:
   1.104 +        n_combo_array[i]=new MapSelector(n_nml, s_nml,
   1.105 +            mytab.getActiveNodeMap(i), node_property_strings[i],
   1.106 +            false, true, NUM);
   1.107 +        break;
   1.108 +      case N_TEXT:
   1.109 +        n_combo_array[i]=new MapSelector(n_nml, s_nml,
   1.110 +            mytab.getActiveNodeMap(i), node_property_strings[i],
   1.111 +            false, true, ALL);
   1.112 +        break;
   1.113 +    }
   1.114 +
   1.115 +    (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
   1.116 +
   1.117 +    n_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::nodeMapChanged), i));
   1.118 +    n_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded));
   1.119 +  }
   1.120 +
   1.121 +  add(vbox);
   1.122 +
   1.123 +  vbox.pack_start(*(new Gtk::Label("Node properties")));
   1.124 +
   1.125 +  vbox.pack_start(*table);
   1.126 +
   1.127 +  update(n_eml, s_eml, n_nml, s_nml);
   1.128 +
   1.129 +  show_all_children();
   1.130 +
   1.131 +}
   1.132 +
   1.133 +void MapWin::nodeMapChanged(std::string mapname, int prop)
   1.134 +{
   1.135 +  mytab.propertyChange(false, prop, mapname);
   1.136 +}
   1.137 +
   1.138 +void MapWin::arcMapChanged(std::string mapname, int prop)
   1.139 +{
   1.140 +  mytab.propertyChange(true, prop, mapname);
   1.141 +}
   1.142 +
   1.143 +void MapWin::newMapWinNeeded(bool itisarc)
   1.144 +{
   1.145 +  mytab.popupNewMapWin(itisarc);
   1.146 +}
   1.147 +
   1.148 +void MapWin::update(
   1.149 +    std::vector<std::string> n_eml,
   1.150 +    std::vector<std::string> s_eml,
   1.151 +    std::vector<std::string> n_nml,
   1.152 +    std::vector<std::string> s_nml)
   1.153 +{
   1.154 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.155 +  {
   1.156 +    e_combo_array[i]->update_list(n_eml, s_eml);
   1.157 +  }
   1.158 +
   1.159 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.160 +  {
   1.161 +    n_combo_array[i]->update_list(n_nml, s_nml);
   1.162 +  }
   1.163 +
   1.164 +  mytab.active_maps_needed();
   1.165 +}
   1.166 +
   1.167 +void MapWin::registerNewArcMap(std::string newmapname, MapValue::Type type)
   1.168 +{
   1.169 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   1.170 +  {
   1.171 +    //filling in combo box with choices
   1.172 +    e_combo_array[i]->append_text((Glib::ustring)newmapname, type);
   1.173 +  }
   1.174 +}
   1.175 +
   1.176 +void MapWin::registerNewNodeMap(std::string newmapname, MapValue::Type type)
   1.177 +{
   1.178 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
   1.179 +  {
   1.180 +    //filling in combo box with choices
   1.181 +    n_combo_array[i]->append_text((Glib::ustring)newmapname, type);
   1.182 +  }
   1.183 +}
   1.184 +
   1.185 +bool MapWin::on_delete_event(GdkEventAny * event)
   1.186 +{
   1.187 +  event=event;
   1.188 +  mytab.closeMapWin();
   1.189 +  return true;
   1.190 +}
   1.191 +
   1.192 +void MapWin::changeEntry(bool isitarc, int prop, std::string mapname)
   1.193 +{
   1.194 +  if(isitarc)
   1.195 +    {
   1.196 +      e_combo_array[prop]->set_active_text(mapname);
   1.197 +    }
   1.198 +  else
   1.199 +    {
   1.200 +      n_combo_array[prop]->set_active_text(mapname);
   1.201 +    }
   1.202 +}
   1.203 +
   1.204 +void MapWin::set_title(std::string tabname)
   1.205 +{
   1.206 +  Gtk::Window::set_title("Map Setup - "+tabname);
   1.207 +}