mapselector.h
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mapselector.h	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,178 @@
     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 +#ifndef MAPSELECTOR_H
    1.23 +#define MAPSELECTOR_H
    1.24 +
    1.25 +#include <all_include.h>
    1.26 +#include <libgnomecanvasmm.h>
    1.27 +#include <libgnomecanvasmm/polygon.h>
    1.28 +#include "map_value.h"
    1.29 +
    1.30 +///A widget by which node and arcmaps can be selected, deselected and created.
    1.31 +
    1.32 +///During the usage of \ref glemon we have to select
    1.33 +///maps several times. We also need some aid-function
    1.34 +///like new map creation and deselecting previously
    1.35 +///selected map. Instead of writing a the mapselection
    1.36 +///at all occurences we can use this widget by connecting
    1.37 +///its signals to the correct place.
    1.38 +class MapSelector : public Gtk::HBox
    1.39 +{
    1.40 + protected:
    1.41 +  ///This signal indicates that the selection has been changed by user.
    1.42 +  sigc::signal<void, std::string> signal_cbt;
    1.43 +
    1.44 +  ///Signal that indicates that user wants to create a new map.
    1.45 +  sigc::signal<void, bool> signal_newmapwin;
    1.46 +
    1.47 +  ///If this is true, beyond the mapnames a 'Default' selection is available as well.
    1.48 +
    1.49 +  ///For example \ref MapWin needs 'Default' option as well. In this case no map
    1.50 +  ///will be visualized by the appropriate property.
    1.51 +  ///But \ref AlgoWin do not need 'Default' option, because if no map is selected,
    1.52 +  ///no algorithm can be run.
    1.53 +  ///Its value is got and set in contructor.
    1.54 +  bool def;
    1.55 +
    1.56 +  ///Are the names of arcmaps or nodemaps stored here.
    1.57 +  bool itisarc;
    1.58 +
    1.59 +  ///Shows whether 'Default' option is selected or not.
    1.60 +  bool default_state;
    1.61 +
    1.62 +  ///It is true when the new button had been pressed but the new map has not been registrated yet.
    1.63 +
    1.64 +  ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector
    1.65 +  ///this variable is set to true. When the new map
    1.66 +  ///is done, it will be registrated in all existing \ref MapSelector 
    1.67 +  ///by \ref append_text function. That function checks
    1.68 +  ///whether this variable is true. If it is true that means
    1.69 +  ///that this \ref MapSelector has requested \ref NewMapWin.
    1.70 +  ///Therefore it set itself to the recently created map.
    1.71 +  ///After that \ref set_new_map is set again false, not to
    1.72 +  ///set maps active if \ref MapSelector piece is not the requester.
    1.73 +  bool set_new_map;
    1.74 +
    1.75 +  ///The widget that holds the names of maps.
    1.76 +
    1.77 +  ///It can be rolled down
    1.78 +  ///Names in it are selectable.
    1.79 +  Gtk::ComboBoxText cbt;
    1.80 +
    1.81 +  std::vector<std::string> cbt_content;
    1.82 +
    1.83 +  ///New button.
    1.84 +
    1.85 +  ///By pressing it
    1.86 +  ///\ref NewMapWin wilol pop-up
    1.87 +  Gtk::Button newbut;
    1.88 +
    1.89 +  ///Reset button.
    1.90 +
    1.91 +  ///If pressed \ref cbt will
    1.92 +  ///set to 'Default' option.
    1.93 +  ///
    1.94 +  ///It is visible only if \ref def is true.
    1.95 +  Gtk::Button defbut;
    1.96 +
    1.97 +  ///Shows purpose of \ref MapSelector piece.
    1.98 +  Gtk::Label label;
    1.99 +
   1.100 +  /// Which types of maps (integer, string, ...) to display.
   1.101 +  MapType map_type;
   1.102 +
   1.103 + public:
   1.104 +
   1.105 +  ///Constructor of \ref MapSelector
   1.106 +
   1.107 +  ///Creates the layout and binds signal to the correct place.
   1.108 +  ///\param mapstorage Pointer to the \ref MapStorage to get the map list from.
   1.109 +  ///\param act preselected option
   1.110 +  ///\param purpose text of label indicating purpose of \ref MapStorage
   1.111 +  ///\param itisarc do \ref MapSelector contains arcmap names or nodemapnames.
   1.112 +  ///\param def do we need 'Default' option. See \ref def.
   1.113 +  ///\param type Specifies which types of maps to display.
   1.114 +  MapSelector(std::vector<std::string> n_ml,
   1.115 +      std::vector<std::string> s_ml, std::string act, std::string labeltext,
   1.116 +      bool arc, bool d = true, MapType type = ALL);
   1.117 +
   1.118 +  ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
   1.119 +  sigc::signal<void, std::string> signal_cbt_ch();
   1.120 +
   1.121 +  ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin)
   1.122 +  sigc::signal<void, bool> signal_newmapwin_needed();
   1.123 +
   1.124 +  ///Maintain \ref cbt.
   1.125 +
   1.126 +  ///Fills in \ref cbt with names, taking
   1.127 +  ///into account that the previously selected option
   1.128 +  ///has to be set back after the operation.
   1.129 +  void update_list(std::vector<std::string> n_ml,
   1.130 +      std::vector<std::string> s_ml);
   1.131 +
   1.132 +  ///Handles changement in \ref cbt.
   1.133 +
   1.134 +  ///In default case it emits a signal with the selected option.
   1.135 +  ///But if 'Default' option is selected, it resets the \ref MapSelector
   1.136 +  virtual void comboChanged();
   1.137 +
   1.138 +  ///Requests a \ref NewMapWin
   1.139 +
   1.140 +  ///See \ref set_new_map.
   1.141 +  ///First it sets \ref set_new_map true to be identified
   1.142 +  ///at registration of new map that
   1.143 +  ///it has sent the \ref signal_newmapwin, therefore it
   1.144 +  ///has to set \ref cbt to that option.
   1.145 +  virtual void new_but_pressed();
   1.146 +
   1.147 +  ///If called, 'Default' option is selected, that means unselection of any maps.
   1.148 +
   1.149 +  ///Practically this means that if this is called,
   1.150 +  ///properties of digraph will set to default state.
   1.151 +  ///The function achieves this by emitting appropriately
   1.152 +  ///parametrized signal_cbt.
   1.153 +  virtual void reset();
   1.154 +
   1.155 +  ///Returns the currently selected option.
   1.156 +  Glib::ustring get_active_text();
   1.157 +
   1.158 +  ///Sets the parameter active in \ref cbt.
   1.159 +
   1.160 +  ///\param new_value the
   1.161 +  ///new value to be set in \ref cbt.
   1.162 +  void set_active_text(Glib::ustring new_value);
   1.163 +
   1.164 +  ///Sets the parameter active in \ref cbt.
   1.165 +  ///\param index the
   1.166 +  ///index of row to be set in \ref cbt.
   1.167 +  void set_active(int index){cbt.set_active(index);};
   1.168 +
   1.169 +  ///Clear all options from \ref cbt.
   1.170 +  void clear(){cbt.clear();};
   1.171 +
   1.172 +  ///Appends a new option to the existing ones in \ref cbt.
   1.173 +
   1.174 +  ///If \ref set_new_map is true, the
   1.175 +  ///\ref MapSelector has requested the opened \ref NewMapWin,
   1.176 +  ///from that the option to append is coming. In this case
   1.177 +  ///this function  will set \ref cbt to the new option.
   1.178 +  ///\param new_option new option to append
   1.179 +  void append_text(Glib::ustring new_option, MapValue::Type);
   1.180 +};
   1.181 +#endif //MAPSELECTOR_H