mapselector.cc
author hegyi
Tue, 27 Feb 2007 17:18:19 +0000
changeset 191 af2ed974ab68
parent 172 fc1e478697d3
child 194 6b2b718420eb
permissions -rw-r--r--
GUI can now export graph to EPS.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #include "mapselector.h"
    20 
    21 MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
    22 {
    23   update_list(ml);
    24 
    25   if(act=="")
    26     {
    27       cbt.set_active(0);
    28       default_state=true;
    29     }
    30   else
    31     {
    32       cbt.set_active_text((Glib::ustring)act);
    33       default_state=false;
    34     }
    35 
    36   //binding signal to the actual entry
    37   cbt.signal_changed().connect
    38     (
    39      sigc::mem_fun((*this), &MapSelector::comboChanged),
    40      false
    41      );
    42   
    43   label=new Gtk::Label(labeltext);
    44 
    45   label->set_width_chars(longest_property_string_length);
    46 
    47   defbut=NULL;
    48   if(def)
    49     {
    50       defbut=new Gtk::Button();
    51       defbut->set_label("Reset");
    52       
    53       defbut->signal_pressed().connect
    54 	(
    55 	 sigc::mem_fun(*this, &MapSelector::reset)
    56 	 );
    57     }
    58 
    59   newbut=new Gtk::Button(Gtk::Stock::NEW);
    60 
    61   newbut->signal_pressed().connect
    62     (
    63      sigc::mem_fun(*this, &MapSelector::new_but_pressed)
    64      );
    65 
    66   add(*label);
    67 
    68   add(cbt);
    69 
    70   if(def)
    71     {
    72       add(*defbut);
    73     }
    74 
    75   add(*newbut);
    76 }
    77 
    78 void MapSelector::new_but_pressed()
    79 {
    80   set_new_map=true;
    81   signal_newmapwin.emit(itisedge);
    82 }
    83 
    84 void MapSelector::update_list( std::vector< std::string > ml )
    85 {
    86   int prev_act=cbt.get_active_row_number();
    87   cbt.clear();
    88   cbt_content.clear();
    89   std::vector< std::string >::iterator emsi=ml.begin();
    90   for(;emsi!=ml.end();emsi++)
    91     {
    92       cbt.append_text(*emsi);
    93       cbt_content.push_back(*emsi);
    94     }
    95   if(def)
    96     {
    97       cbt.prepend_text("Default values");
    98       cbt_content.push_back("Default values");
    99     }
   100   if(prev_act!=-1)
   101     {
   102       cbt.set_active(prev_act);
   103     }
   104 }
   105 
   106 void MapSelector::comboChanged()
   107 {
   108   if(cbt.get_active_row_number()!=0 || !def)
   109     {
   110       default_state=false;
   111       Glib::ustring mapname = cbt.get_active_text();
   112       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
   113 	{
   114 	  signal_cbt.emit(mapname);
   115 	}
   116     }
   117   else if((!default_state)&&(cbt.get_active_row_number()==0))
   118     {
   119       reset();
   120     }
   121 }
   122 
   123 void MapSelector::reset()
   124 {
   125   default_state=true;
   126 
   127   cbt.set_active(0);
   128 
   129   signal_cbt.emit("");
   130 }
   131 
   132 
   133 Glib::ustring MapSelector::get_active_text()
   134 {
   135   return cbt.get_active_text();
   136 }
   137 
   138 void MapSelector::set_active_text(Glib::ustring text)
   139 {
   140   if(text.compare(""))
   141     {
   142       cbt.set_active_text(text);
   143     }
   144   else
   145     { 
   146       cbt.set_active_text("Default values");
   147     }
   148 }
   149 
   150 void MapSelector::append_text(Glib::ustring text)
   151 {
   152   cbt.append_text(text);
   153   cbt_content.push_back(text);
   154 
   155   if(set_new_map)
   156     {
   157       set_active_text(text);
   158       set_new_map=false;
   159     }
   160 }
   161 
   162 sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
   163 {
   164   return signal_cbt;
   165 }
   166 
   167 sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
   168 {
   169   return signal_newmapwin;
   170 }