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