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