/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2006 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ #ifndef MAPSTORAGE_H #define MAPSTORAGE_H #include #include #include class NoteBookTab; ///class MapStorage handles NodeMaps and EdgeMaps. ///Class MapStorage is responsible for storing ///NodeMaps and EdgeMaps that can be shown later ///on GUI. Therefore maps can be added to it, ///and datas over the added maps can be queried. ///The maps will be stored in an std::map, ///referenced with their names. Unfortunately at ///the moment it works only with double type maps /// ///\todo too many things are public!! class MapStorage { private: std::string background_file_name; bool background_set; double background_scaling; NoteBookTab& mytab; public: void setBackground(const std::string& file_name); const std::string& getBackgroundFilename(); bool isBackgroundSet(); double getBackgroundScaling(); void setBackgroundScaling(double scaling); ///The graph for which the datas are stored. Graph graph; /// the coordinates of the nodes XYMap > coords; /// the coordinates of the arrows on the edges XYMap > arrow_pos; ///The content of the object has changed, update is needed. bool modified; ///Name of file loaded in object. std::string file_name; ///Stores double type NodeMaps std::map< std::string,Graph::NodeMap * > nodemap_storage; ///Stores double type EdgeMaps std::map< std::string,Graph::EdgeMap * > edgemap_storage; ///Stores the default values for the different visualization node attributes std::vector > default_nodemaps; ///Stores the default values for the different visualization edge attributes std::vector > default_edgemaps; ///Stores the active maps for the different visualization node attributes std::vector< std::string > active_nodemaps; /// Stores the active maps for the different visualization edge attributes std::vector< std::string > active_edgemaps; /// Default values for the maps std::map< std::string, double > nodemap_default; /// Default values for the maps std::map< std::string, double > edgemap_default; bool arrow_pos_read_ok; protected: /// Signal emitted on any change made on map values /// Signal emitted if the visualization of the maps might have to be updated. /// bool shows us whether the changed map is edge or nodemap. /// int tells us the refreshed property sigc::signal signal_prop; /// Signal emitted in the case of nodemap addition /// std::string is the ///name of the new map sigc::signal signal_node_map; /// Signal emitted in the case of edgemap addition /// std::string is the ///name of the new map sigc::signal signal_edge_map; /// Signal emitted, when entry in \ref MapWin should be changed. sigc::signal signal_map_win; /// Signal emitted, when entry in \ref DesignWin should be changed. sigc::signal signal_design_win; ///Iteration number during graph design int iterations; ///Attraction factor during graph design double attraction; ///Propulsation factor during graph design double propulsation; public: ///Constructor of MapStorage. ///Its all activity is initializing default values ///for different visualization attributes. MapStorage(NoteBookTab& tab); ///Destructor of MapStorage ///Maps stored here are created with new. Destructor ///deletes them to free up the reserved memory. ~MapStorage(); /// Registrates if the shown map by any attribute has changed to another. ///It handles the \ref active_edgemaps and ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let ///know the interested objects that the visible map of a certain ///attribute has changed. ///\param itisedge edgemap or nodemap has changed ///\param prop the property of which the map is changed ///\param mapname the visible map void changeActiveMap(bool itisedge , int prop , std::string mapname); ///Emits signals that let change the active maps in \ref MapWin. void broadcastActiveMaps(); /// Returns the active edgemap shown by a visualization property. /// \param prop is the property ///that shows the requested map. std::string getActiveEdgeMap(int prop); /// Returns the active nodemap shown by a visualization property. /// \param prop is the property ///that shows the requested map. std::string getActiveNodeMap(int prop); /// Returns the names of the edgemaps stored here. std::vector getEdgeMapList(); /// Returns the names of the nodemaps stored here. std::vector getNodeMapList(); ///returns \ref signal_prop to be able to connect functions to it sigc::signal signal_prop_ch(); ///returns \ref signal_node_map to be able to connect functions to it sigc::signal signal_node_map_ch(){return signal_node_map;}; ///returns \ref signal_edge_map to be able to connect functions to it sigc::signal signal_edge_map_ch(){return signal_edge_map;}; ///returns \ref signal_map_win to be able to connect functions to it sigc::signal signal_map_win_ch(){return signal_map_win;}; ///returns \ref signal_design_win to be able to connect functions to it sigc::signal signal_design_win_ch(){return signal_design_win;}; ///Adds given map to storage. ///A name and the map itself has to be provided. ///\param mapname is the name of map ///\param nodemap is the pointer of the given nodemap ///\param def the default value of the map. If not given, it will be 0. ///If new edge is added to graph the value of it in the map will be this. ///\todo map should be given by reference! ///\todo why is default value stored? int addNodeMap(const std::string & mapname,Graph::NodeMap * nodemap, double def=0.0); ///Adds given map to storage. A name and the map itself has to be provided. ///A name and the map itself has to be provided. ///\param mapname is the name of map ///\param edgemap is the pointer of the given edgemap ///\param def the default value of the map. If not given, it will be 0. ///If new edge is added to graph the value of it in the map will be this. ///\todo map should be given by reference! int addEdgeMap(const std::string & mapname,Graph::EdgeMap * edgemap, double def=0.0); ///Returns how much nodemaps is stored in \ref MapStorage int numOfNodeMaps() {return nodemap_storage.size();}; ///Returns how much edgemaps is stored in \ref MapStorage int numOfEdgeMaps() {return edgemap_storage.size();}; ///Returns the maximum value of the given NodeMap. ///NodeMap has to be given by its name. ///\param name the name of map of which maximum is searched double maxOfNodeMap(const std::string & name); ///Returns the maximum value of the given EdgeMap. ///EdgeMap has to be given by its name. ///\param name the name of map of which maximum is searched double maxOfEdgeMap(const std::string & name); ///Returns the minimum value of the given NodeMap. ///NodeMap has to be given by its name. ///\param name the name of map of which minimum is searched double minOfNodeMap(const std::string & name); ///Returns the minimum value of the given EdgeMap. ///EdgeMap has to be given by its name. ///\param name the name of map of which minimum is searched double minOfEdgeMap(const std::string & name); ///Returns iterator pointing to the first NodeMap in storage. ///To be able to iterate through each maps this function ///returns an iterator pointing to the first nodemap in ///the storage. std::map< std::string,Graph::NodeMap * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; ///Returns iterator pointing to the first EdgeMap in storage. ///To be able to iterate through each maps this function ///returns an iterator pointing to the first edgemap in ///the storage. std::map< std::string,Graph::EdgeMap * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; ///Returns iterator pointing after the last NodeMap in storage. ///To be able to iterate through each maps this function ///returns an iterator pointing to the last nodemap in the storage. std::map< std::string,Graph::NodeMap * >::iterator endOfNodeMaps(){return nodemap_storage.end();}; ///Returns iterator pointing after the last EdgeMap in storage. ///To be able to iterate through each maps this function ///returns an iterator pointing to the last edgemap in the storage. std::map< std::string,Graph::EdgeMap * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. ///If values in a map have changed, this function checks, whether it is displayed. ///This check means searching the given mapname between active maps ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property, ///it emits a signal with the property, where the gotten mapname was found. One signal ///is emitted for each property displaying the given map. ///\param itisedge whether the map an edgemap or nodemap ///\param mapname name of map to visualize void mapChanged(bool itisedge, std::string mapname); ///Read datas from the given filename. int readFromFile(const std::string &); ///Save datas to the given filename. void writeToFile(const std::string &); ///Deletes all datastructures stored here. void clear(); void ArrowPosReadOK(); void get_design_data(double &, double &, int &); void set_attraction(double); void set_propulsation(double); void set_iteration(int); void redesign_data_changed(); void exportGraphToEPS(std::vector, std::string); }; #endif //MAPSTORAGE_H