ladanyi@6: // -*- C++ -*- // ladanyi@6: ladanyi@6: #ifndef MAPSTORAGE_H ladanyi@6: #define MAPSTORAGE_H ladanyi@6: hegyi@94: class Mapstorage; hegyi@94: ladanyi@53: #include "all_include.h" ladanyi@53: #include "xymap.h" hegyi@94: #include ladanyi@6: hegyi@118: ///class MapStorage handles NodeMaps and EdgeMaps. hegyi@118: ladanyi@6: ///Class MapStorage is responsible for storing ladanyi@6: ///NodeMaps and EdgeMaps that can be shown later ladanyi@6: ///on GUI. Therefore maps can be added to it, ladanyi@6: ///and datas over the added maps can be queried. ladanyi@6: ///The maps will be stored in an std::map, ladanyi@6: ///referenced with their names. Unfortunately at ladanyi@6: ///the moment it works only with double type maps ladanyi@6: /// ladanyi@6: ///\todo too many things are public!! ladanyi@6: class MapStorage ladanyi@6: { ladanyi@6: public: ladanyi@6: hegyi@118: ///The graph for which the datas are stored. ladanyi@53: Graph graph; ladanyi@98: /// the coordinates of the nodes ladanyi@53: XYMap > coords; ladanyi@98: /// the coordinates of the arrows on the edges ladanyi@98: XYMap > arrow_pos; ladanyi@53: hegyi@118: ///The content of the object has changed, update is needed. ladanyi@53: bool modified; hegyi@118: hegyi@118: ///Name of file loaded in object. ladanyi@53: std::string file_name; ladanyi@6: ladanyi@6: ///Stores double type NodeMaps ladanyi@6: std::map< std::string,Graph::NodeMap * > nodemap_storage; ladanyi@6: ladanyi@6: ///Stores double type EdgeMaps ladanyi@6: std::map< std::string,Graph::EdgeMap * > edgemap_storage; ladanyi@6: hegyi@118: ///Stores the default values for the different visualization node attributes ladanyi@6: std::vector > default_nodemaps; ladanyi@6: hegyi@118: ///Stores the default values for the different visualization edge attributes ladanyi@6: std::vector > default_edgemaps; ladanyi@6: hegyi@118: ///Stores the active maps for the different visualization node attributes hegyi@94: std::vector< std::string > active_nodemaps; hegyi@94: hegyi@118: /// Stores the active maps for the different visualization edge attributes hegyi@94: std::vector< std::string > active_edgemaps; hegyi@94: hegyi@118: /// Default values for the maps ladanyi@63: std::map< std::string, double > nodemap_default; ladanyi@63: hegyi@118: /// Default values for the maps ladanyi@63: std::map< std::string, double > edgemap_default; ladanyi@63: ladanyi@98: bool arrow_pos_read_ok; ladanyi@98: hegyi@94: protected: hegyi@118: /// type of the signal emitted if the visualization of the maps might have to be updated. hegyi@118: hegyi@118: /// bool shows us whether the changed map is edge or nodemap. hegyi@118: /// int tells us the refreshed property hegyi@94: typedef sigc::signal Signal_Prop; hegyi@118: hegyi@118: /// Signal emitted on any change made on map values hegyi@94: Signal_Prop signal_prop; hegyi@118: hegyi@118: /// Signal emitted in the case of nodemap addition hegyi@118: hegyi@118: /// std::string is the hegyi@118: ///name of the new map hegyi@108: sigc::signal signal_node_map; hegyi@118: hegyi@118: /// Signal emitted in the case of edgemap addition hegyi@118: hegyi@118: /// std::string is the hegyi@118: ///name of the new map hegyi@108: sigc::signal signal_edge_map; hegyi@94: ladanyi@6: public: hegyi@118: ///Constructor of MapStorage. hegyi@118: ladanyi@6: ///Its all activity is initializing default values hegyi@118: ///for different visualization attributes. ladanyi@53: MapStorage(); ladanyi@53: hegyi@118: ///Destructor of MapStorage hegyi@118: hegyi@118: ///Maps stored here are created with new. Destructor hegyi@118: ///deletes them to free up the reserved memory. ladanyi@53: ~MapStorage(); ladanyi@6: hegyi@118: /// Registrates if the shown map by any attribute has changed to another. hegyi@94: hegyi@118: ///It handles the \ref active_edgemaps and hegyi@118: ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let hegyi@118: ///know the interested objects that the visible map of a certain hegyi@118: ///attribute has changed. hegyi@118: ///\param itisedge edgemap or nodemap has changed hegyi@118: ///\param prop the property of which the map is changed hegyi@118: ///\param mapname the visible map hegyi@118: void changeActiveMap(bool itisedge , int prop , std::string mapname); hegyi@94: hegyi@118: /// Returns the active edgemap shown by a visualization property. hegyi@118: hegyi@118: /// \param prop is the property hegyi@118: ///that shows the requested map. hegyi@118: std::string getActiveEdgeMap(int prop); hegyi@118: hegyi@118: /// Returns the active nodemap shown by a visualization property. hegyi@118: hegyi@118: /// \param prop is the property hegyi@118: ///that shows the requested map. hegyi@118: std::string getActiveNodeMap(int prop); hegyi@118: hegyi@118: /// Returns the names of the edgemaps stored here. hegyi@94: std::vector getEdgeMapList(); hegyi@118: hegyi@118: /// Returns the names of the nodemaps stored here. hegyi@94: std::vector getNodeMapList(); hegyi@94: hegyi@118: ///returns \ref signal_prop to be able to connect functions to it hegyi@94: Signal_Prop signal_prop_ch(); hegyi@94: hegyi@118: ///returns \ref signal_node_map to be able to connect functions to it hegyi@108: sigc::signal signal_node_map_ch(){return signal_node_map;}; hegyi@118: hegyi@118: ///returns \ref signal_edge_map to be able to connect functions to it hegyi@108: sigc::signal signal_edge_map_ch(){return signal_edge_map;}; hegyi@108: hegyi@118: ///Adds given map to storage. hegyi@118: hegyi@118: ///A name and the map itself has to be provided. hegyi@118: ///\param mapname is the name of map hegyi@118: ///\param nodemap is the pointer of the given nodemap hegyi@118: ///\param def the default value of the map. If not given, it will be 0. hegyi@118: ///If new edge is added to graph the value of it in the map will be this. ladanyi@6: ///\todo map should be given by reference! hegyi@118: ///\todo why is default value stored? hegyi@118: int addNodeMap(const std::string & mapname,Graph::NodeMap * nodemap, double def=0.0); ladanyi@6: ladanyi@6: ///Adds given map to storage. A name and the map itself has to be provided. hegyi@118: hegyi@118: ///A name and the map itself has to be provided. hegyi@118: ///\param mapname is the name of map hegyi@118: ///\param edgemap is the pointer of the given edgemap hegyi@118: ///\param def the default value of the map. If not given, it will be 0. hegyi@118: ///If new edge is added to graph the value of it in the map will be this. ladanyi@6: ///\todo map should be given by reference! hegyi@118: int addEdgeMap(const std::string & mapname,Graph::EdgeMap * edgemap, double def=0.0); ladanyi@6: ladanyi@6: ///Returns how much nodemaps is stored in \ref MapStorage ladanyi@6: int numOfNodeMaps() {return nodemap_storage.size();}; ladanyi@6: ladanyi@6: ///Returns how much edgemaps is stored in \ref MapStorage ladanyi@6: int numOfEdgeMaps() {return edgemap_storage.size();}; ladanyi@6: hegyi@118: ///Returns the maximum value of the given NodeMap. ladanyi@6: hegyi@118: ///NodeMap has to be given by its name. hegyi@118: ///\param name the name of map of which maximum is searched hegyi@118: double maxOfNodeMap(const std::string & name); ladanyi@6: hegyi@118: ///Returns the maximum value of the given EdgeMap. ladanyi@6: hegyi@118: ///EdgeMap has to be given by its name. hegyi@118: ///\param name the name of map of which maximum is searched hegyi@118: double maxOfEdgeMap(const std::string & name); ladanyi@6: hegyi@118: ///Returns the minimum value of the given NodeMap. hegyi@118: hegyi@118: ///NodeMap has to be given by its name. hegyi@118: ///\param name the name of map of which minimum is searched hegyi@118: double minOfNodeMap(const std::string & name); hegyi@118: hegyi@118: ///Returns the minimum value of the given EdgeMap. hegyi@118: hegyi@118: ///EdgeMap has to be given by its name. hegyi@118: ///\param name the name of map of which minimum is searched hegyi@118: double minOfEdgeMap(const std::string & name); hegyi@118: hegyi@118: ///Returns iterator pointing to the first NodeMap in storage. hegyi@118: hegyi@118: ///To be able to iterate through each maps this function hegyi@118: ///returns an iterator pointing to the first nodemap in hegyi@118: ///the storage. ladanyi@6: std::map< std::string,Graph::NodeMap * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; ladanyi@6: hegyi@118: ///Returns iterator pointing to the first EdgeMap in storage. hegyi@118: hegyi@118: ///To be able to iterate through each maps this function hegyi@118: ///returns an iterator pointing to the first edgemap in hegyi@118: ///the storage. ladanyi@6: std::map< std::string,Graph::EdgeMap * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; hegyi@26: hegyi@118: ///Returns iterator pointing after the last NodeMap in storage. hegyi@118: hegyi@118: ///To be able to iterate through each maps this function hegyi@118: ///returns an iterator pointing to the last nodemap in the storage. hegyi@31: std::map< std::string,Graph::NodeMap * >::iterator endOfNodeMaps(){return nodemap_storage.end();}; hegyi@31: hegyi@118: ///Returns iterator pointing after the last EdgeMap in storage. hegyi@118: hegyi@118: ///To be able to iterate through each maps this function hegyi@118: ///returns an iterator pointing to the last edgemap in the storage. hegyi@31: std::map< std::string,Graph::EdgeMap * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; hegyi@31: hegyi@118: ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. hegyi@111: hegyi@118: ///If values in a map have changed, this function checks, whether it is displayed. hegyi@118: ///This check means searching the given mapname between active maps hegyi@118: ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property, hegyi@118: ///it emits a signal with the property, where the gotten mapname was found. One signal hegyi@118: ///is emitted for each property displaying the given map. hegyi@118: ///\param itisedge whether the map an edgemap or nodemap hegyi@118: ///\param mapname name of map to visualize hegyi@118: void mapChanged(bool itisedge, std::string mapname); hegyi@118: hegyi@118: ///Read datas from the given filename. ladanyi@63: int readFromFile(const std::string &); hegyi@118: hegyi@118: ///Save datas to the given filename. ladanyi@53: void writeToFile(const std::string &); ladanyi@53: hegyi@118: ///Deletes all datastructures stored here. ladanyi@53: void clear(); ladanyi@98: ladanyi@98: void ArrowPosReadOK(); ladanyi@6: }; ladanyi@6: ladanyi@6: #endif //MAPSTORAGE_H