[174] | 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 | */ |
---|
[115] | 18 | |
---|
| 19 | #ifndef MAPSELECTOR_H |
---|
| 20 | #define MAPSELECTOR_H |
---|
| 21 | |
---|
| 22 | class MapSelector; |
---|
| 23 | |
---|
| 24 | #include <all_include.h> |
---|
| 25 | #include <map_win.h> |
---|
| 26 | #include <libgnomecanvasmm.h> |
---|
| 27 | #include <libgnomecanvasmm/polygon.h> |
---|
| 28 | |
---|
[122] | 29 | ///A widget by which node and edgemaps can be selected, deselected and created. |
---|
| 30 | |
---|
| 31 | ///During the usage of \ref glemon we have to select |
---|
| 32 | ///maps several times. We also need some aid-function |
---|
| 33 | ///like new map creation and deselecting previously |
---|
| 34 | ///selected map. Instead of writing a the mapselection |
---|
| 35 | ///at all occurences we can use this widget by connecting |
---|
| 36 | ///its signals to the correct place. |
---|
[115] | 37 | class MapSelector : public Gtk::HBox |
---|
| 38 | { |
---|
| 39 | protected: |
---|
[122] | 40 | ///This signal indicates that the selection has been changed by user. |
---|
[115] | 41 | sigc::signal<void, std::string> signal_cbt; |
---|
[122] | 42 | |
---|
| 43 | ///Signal that indicates that user wants to create a new map. |
---|
[115] | 44 | sigc::signal<void, bool> signal_newmapwin; |
---|
| 45 | |
---|
[122] | 46 | ///If this is true, beyond the mapnames a 'Default' selection is available as well. |
---|
| 47 | |
---|
| 48 | ///For example \ref MapWin needs 'Default' option as well. In this case no map |
---|
| 49 | ///will be visualized by the appropriate property. |
---|
| 50 | ///But \ref AlgoWin do not need 'Default' option, because if no map is selected, |
---|
| 51 | ///no algorithm can be run. |
---|
| 52 | ///Its value is got and set in contructor. |
---|
[115] | 53 | bool def; |
---|
| 54 | |
---|
[122] | 55 | ///Are the names of edgemaps or nodemaps stored here. |
---|
[115] | 56 | bool itisedge; |
---|
| 57 | |
---|
[122] | 58 | ///Shows whether 'Default' option is selected or not. |
---|
[115] | 59 | bool default_state; |
---|
| 60 | |
---|
[122] | 61 | ///It is true when the new button had been pressed but the new map has not been registrated yet. |
---|
| 62 | |
---|
| 63 | ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector |
---|
| 64 | ///this variable is set to true. When the new map |
---|
| 65 | ///is done, it will be registrated in all existing \ref MapSelector |
---|
| 66 | ///by \ref append_text function. That function checks |
---|
| 67 | ///whether this variable is true. If it is true that means |
---|
| 68 | ///that this \ref MapSelector has requested \ref NewMapWin. |
---|
| 69 | ///Therefore it set itself to the recently created map. |
---|
| 70 | ///After that \ref set_new_map is set again false, not to |
---|
| 71 | ///set maps active if \ref MapSelector piece is not the requester. |
---|
[115] | 72 | bool set_new_map; |
---|
| 73 | |
---|
[122] | 74 | ///The widget that holds the names of maps. |
---|
| 75 | |
---|
| 76 | ///It can be rolled down |
---|
| 77 | ///Names in it are selectable. |
---|
[115] | 78 | Gtk::ComboBoxText cbt; |
---|
| 79 | |
---|
[172] | 80 | std::vector<std::string> cbt_content; |
---|
| 81 | |
---|
[122] | 82 | ///New button. |
---|
[115] | 83 | |
---|
[122] | 84 | ///By pressing it |
---|
| 85 | ///\ref NewMapWin wilol pop-up |
---|
| 86 | Gtk::Button * newbut; |
---|
| 87 | |
---|
| 88 | ///Reset button. |
---|
| 89 | |
---|
| 90 | ///If pressed \ref cbt will |
---|
| 91 | ///set to 'Default' option. |
---|
| 92 | /// |
---|
| 93 | ///It is visible only if \ref def is true. |
---|
| 94 | Gtk::Button * defbut; |
---|
| 95 | |
---|
| 96 | ///Container in which GUI elements are packed. |
---|
[115] | 97 | Gtk::HBox hbox; |
---|
| 98 | |
---|
[122] | 99 | ///Shows purpose of \ref MapSelector piece. |
---|
[115] | 100 | Gtk::Label * label; |
---|
| 101 | |
---|
| 102 | public: |
---|
| 103 | |
---|
[122] | 104 | ///Constructor of \ref MapSelector |
---|
[115] | 105 | |
---|
[122] | 106 | ///Creates the layout and binds signal to the correct place. |
---|
| 107 | ///\param optionlist list of names to place in \ref cbt |
---|
| 108 | ///\param act preselected option |
---|
| 109 | ///\param purpose text of label indicating purpose of \ref MapStorage |
---|
| 110 | ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames. |
---|
| 111 | ///\param def do we need 'Default' option. See \ref def. |
---|
| 112 | MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true); |
---|
| 113 | |
---|
[123] | 114 | ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt) |
---|
[115] | 115 | sigc::signal<void, std::string> signal_cbt_ch(); |
---|
[122] | 116 | |
---|
[123] | 117 | ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin) |
---|
[115] | 118 | sigc::signal<void, bool> signal_newmapwin_needed(); |
---|
| 119 | |
---|
[122] | 120 | ///Maintain \ref cbt. |
---|
| 121 | |
---|
| 122 | ///Fills in \ref cbt with names, taking |
---|
| 123 | ///into account that the previously selected option |
---|
| 124 | ///has to be set back after the operation. |
---|
[115] | 125 | void update_list( std::vector<std::string> ); |
---|
| 126 | |
---|
[122] | 127 | ///Handles changement in \ref cbt. |
---|
| 128 | |
---|
| 129 | ///In default case it emits a signal with the selected option. |
---|
| 130 | ///But if 'Default' option is selected, it resets the \ref MapSelector |
---|
[115] | 131 | virtual void comboChanged(); |
---|
| 132 | |
---|
[122] | 133 | ///Requests a \ref NewMapWin |
---|
| 134 | |
---|
| 135 | ///See \ref set_new_map. |
---|
| 136 | ///First it sets \ref set_new_map true to be identified |
---|
| 137 | ///at registration of new map that |
---|
| 138 | ///it has sent the \ref signal_newmapwin, therefore it |
---|
| 139 | ///has to set \ref cbt to that option. |
---|
[115] | 140 | virtual void new_but_pressed(); |
---|
| 141 | |
---|
[122] | 142 | ///If called, 'Default' option is selected, that means unselection of any maps. |
---|
| 143 | |
---|
| 144 | ///Practically this means that if this is called, |
---|
| 145 | ///properties of graph will set to default state. |
---|
| 146 | ///The function achieves this by emitting appropriately |
---|
| 147 | ///parametrized signal_cbt. |
---|
[115] | 148 | virtual void reset(); |
---|
| 149 | |
---|
[122] | 150 | ///Returns the currently selected option. |
---|
[115] | 151 | Glib::ustring get_active_text(); |
---|
[122] | 152 | |
---|
| 153 | ///Sets the parameter active in \ref cbt. |
---|
| 154 | |
---|
| 155 | ///\param new_value the |
---|
| 156 | ///new value to be set in \ref cbt. |
---|
| 157 | void set_active_text(Glib::ustring new_value); |
---|
| 158 | |
---|
| 159 | ///Sets the parameter active in \ref cbt. |
---|
| 160 | ///\param index the |
---|
| 161 | ///index of row to be set in \ref cbt. |
---|
[115] | 162 | void set_active(int index){cbt.set_active(index);}; |
---|
[122] | 163 | |
---|
| 164 | ///Clear all options from \ref cbt. |
---|
[115] | 165 | void clear(){cbt.clear();}; |
---|
[122] | 166 | |
---|
| 167 | ///Appends a new option to the existing ones in \ref cbt. |
---|
| 168 | |
---|
| 169 | ///If \ref set_new_map is true, the |
---|
| 170 | ///\ref MapSelector has requested the opened \ref NewMapWin, |
---|
| 171 | ///from that the option to append is coming. In this case |
---|
| 172 | ///this function will set \ref cbt to the new option. |
---|
| 173 | ///\param new_option new option to append |
---|
| 174 | void append_text(Glib::ustring new_option); |
---|
[115] | 175 | }; |
---|
| 176 | #endif //MAPSELECTOR_H |
---|