alpar@174: /* -*- C++ -*- alpar@174: * alpar@174: * This file is a part of LEMON, a generic C++ optimization library alpar@174: * alpar@174: * Copyright (C) 2003-2006 alpar@174: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@174: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@174: * alpar@174: * Permission to use, modify and distribute this software is granted alpar@174: * provided that this copyright notice appears in all copies. For alpar@174: * precise terms see the accompanying LICENSE file. alpar@174: * alpar@174: * This software is provided "AS IS" with no warranty of any kind, alpar@174: * express or implied, and with no claim as to its suitability for any alpar@174: * purpose. alpar@174: * alpar@174: */ hegyi@115: hegyi@115: #ifndef MAPSELECTOR_H hegyi@115: #define MAPSELECTOR_H hegyi@115: hegyi@115: #include hegyi@115: #include hegyi@115: #include ladanyi@201: #include "map_value.h" hegyi@115: hegyi@122: ///A widget by which node and edgemaps can be selected, deselected and created. hegyi@122: hegyi@122: ///During the usage of \ref glemon we have to select hegyi@122: ///maps several times. We also need some aid-function hegyi@122: ///like new map creation and deselecting previously hegyi@122: ///selected map. Instead of writing a the mapselection hegyi@122: ///at all occurences we can use this widget by connecting hegyi@122: ///its signals to the correct place. hegyi@115: class MapSelector : public Gtk::HBox hegyi@115: { hegyi@115: protected: hegyi@122: ///This signal indicates that the selection has been changed by user. hegyi@115: sigc::signal signal_cbt; hegyi@122: hegyi@122: ///Signal that indicates that user wants to create a new map. hegyi@115: sigc::signal signal_newmapwin; hegyi@115: hegyi@122: ///If this is true, beyond the mapnames a 'Default' selection is available as well. hegyi@122: hegyi@122: ///For example \ref MapWin needs 'Default' option as well. In this case no map hegyi@122: ///will be visualized by the appropriate property. hegyi@122: ///But \ref AlgoWin do not need 'Default' option, because if no map is selected, hegyi@122: ///no algorithm can be run. hegyi@122: ///Its value is got and set in contructor. hegyi@115: bool def; hegyi@115: hegyi@122: ///Are the names of edgemaps or nodemaps stored here. hegyi@115: bool itisedge; hegyi@115: hegyi@122: ///Shows whether 'Default' option is selected or not. hegyi@115: bool default_state; hegyi@115: hegyi@122: ///It is true when the new button had been pressed but the new map has not been registrated yet. hegyi@122: hegyi@122: ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector hegyi@122: ///this variable is set to true. When the new map hegyi@122: ///is done, it will be registrated in all existing \ref MapSelector hegyi@122: ///by \ref append_text function. That function checks hegyi@122: ///whether this variable is true. If it is true that means hegyi@122: ///that this \ref MapSelector has requested \ref NewMapWin. hegyi@122: ///Therefore it set itself to the recently created map. hegyi@122: ///After that \ref set_new_map is set again false, not to hegyi@122: ///set maps active if \ref MapSelector piece is not the requester. hegyi@115: bool set_new_map; hegyi@115: hegyi@122: ///The widget that holds the names of maps. hegyi@122: hegyi@122: ///It can be rolled down hegyi@122: ///Names in it are selectable. hegyi@115: Gtk::ComboBoxText cbt; hegyi@115: hegyi@172: std::vector cbt_content; hegyi@172: hegyi@122: ///New button. hegyi@115: hegyi@122: ///By pressing it hegyi@122: ///\ref NewMapWin wilol pop-up ladanyi@201: Gtk::Button newbut; hegyi@122: hegyi@122: ///Reset button. hegyi@122: hegyi@122: ///If pressed \ref cbt will hegyi@122: ///set to 'Default' option. hegyi@122: /// hegyi@122: ///It is visible only if \ref def is true. ladanyi@201: Gtk::Button defbut; hegyi@115: hegyi@122: ///Shows purpose of \ref MapSelector piece. ladanyi@201: Gtk::Label label; ladanyi@201: ladanyi@201: /// Which types of maps (integer, string, ...) to display. ladanyi@201: MapType map_type; hegyi@115: hegyi@115: public: hegyi@115: hegyi@122: ///Constructor of \ref MapSelector hegyi@115: hegyi@122: ///Creates the layout and binds signal to the correct place. ladanyi@201: ///\param mapstorage Pointer to the \ref MapStorage to get the map list from. hegyi@122: ///\param act preselected option hegyi@122: ///\param purpose text of label indicating purpose of \ref MapStorage hegyi@122: ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames. hegyi@122: ///\param def do we need 'Default' option. See \ref def. ladanyi@201: ///\param type Specifies which types of maps to display. ladanyi@201: MapSelector(std::vector n_ml, ladanyi@201: std::vector s_ml, std::string act, std::string labeltext, ladanyi@201: bool edge, bool d = true, MapType type = ALL); hegyi@122: hegyi@123: ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt) hegyi@115: sigc::signal signal_cbt_ch(); hegyi@122: hegyi@123: ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin) hegyi@115: sigc::signal signal_newmapwin_needed(); hegyi@115: hegyi@122: ///Maintain \ref cbt. hegyi@122: hegyi@122: ///Fills in \ref cbt with names, taking hegyi@122: ///into account that the previously selected option hegyi@122: ///has to be set back after the operation. ladanyi@201: void update_list(std::vector n_ml, ladanyi@201: std::vector s_ml); hegyi@115: hegyi@122: ///Handles changement in \ref cbt. hegyi@122: hegyi@122: ///In default case it emits a signal with the selected option. hegyi@122: ///But if 'Default' option is selected, it resets the \ref MapSelector hegyi@115: virtual void comboChanged(); hegyi@115: hegyi@122: ///Requests a \ref NewMapWin hegyi@122: hegyi@122: ///See \ref set_new_map. hegyi@122: ///First it sets \ref set_new_map true to be identified hegyi@122: ///at registration of new map that hegyi@122: ///it has sent the \ref signal_newmapwin, therefore it hegyi@122: ///has to set \ref cbt to that option. hegyi@115: virtual void new_but_pressed(); hegyi@115: hegyi@122: ///If called, 'Default' option is selected, that means unselection of any maps. hegyi@122: hegyi@122: ///Practically this means that if this is called, hegyi@122: ///properties of graph will set to default state. hegyi@122: ///The function achieves this by emitting appropriately hegyi@122: ///parametrized signal_cbt. hegyi@115: virtual void reset(); hegyi@115: hegyi@122: ///Returns the currently selected option. hegyi@115: Glib::ustring get_active_text(); hegyi@122: hegyi@122: ///Sets the parameter active in \ref cbt. hegyi@122: hegyi@122: ///\param new_value the hegyi@122: ///new value to be set in \ref cbt. hegyi@122: void set_active_text(Glib::ustring new_value); hegyi@122: hegyi@122: ///Sets the parameter active in \ref cbt. hegyi@122: ///\param index the hegyi@122: ///index of row to be set in \ref cbt. hegyi@115: void set_active(int index){cbt.set_active(index);}; hegyi@122: hegyi@122: ///Clear all options from \ref cbt. hegyi@115: void clear(){cbt.clear();}; hegyi@122: hegyi@122: ///Appends a new option to the existing ones in \ref cbt. hegyi@122: hegyi@122: ///If \ref set_new_map is true, the hegyi@122: ///\ref MapSelector has requested the opened \ref NewMapWin, hegyi@122: ///from that the option to append is coming. In this case hegyi@122: ///this function will set \ref cbt to the new option. hegyi@122: ///\param new_option new option to append ladanyi@201: void append_text(Glib::ustring new_option, MapValue::Type); hegyi@115: }; hegyi@115: #endif //MAPSELECTOR_H