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