gui/mapstorage.h
changeset 1951 cb7a6e0573bc
parent 1881 f40cdc2057c2
equal deleted inserted replaced
12:9300c4203cb4 13:bf307055cf1c
     6 class Mapstorage;
     6 class Mapstorage;
     7 
     7 
     8 #include "all_include.h"
     8 #include "all_include.h"
     9 #include "xymap.h"
     9 #include "xymap.h"
    10 #include <libgnomecanvasmm.h>
    10 #include <libgnomecanvasmm.h>
       
    11 
       
    12 ///class MapStorage handles NodeMaps and EdgeMaps.
    11 
    13 
    12 ///Class MapStorage is responsible for storing
    14 ///Class MapStorage is responsible for storing
    13 ///NodeMaps and EdgeMaps that can be shown later
    15 ///NodeMaps and EdgeMaps that can be shown later
    14 ///on GUI. Therefore maps can be added to it,
    16 ///on GUI. Therefore maps can be added to it,
    15 ///and datas over the added maps can be queried.
    17 ///and datas over the added maps can be queried.
    20 ///\todo too many things are public!!
    22 ///\todo too many things are public!!
    21 class MapStorage
    23 class MapStorage
    22 {
    24 {
    23 public:
    25 public:
    24 
    26 
       
    27   ///The graph for which the datas are stored.
    25   Graph graph;
    28   Graph graph;
    26   /// the coordinates of the nodes
    29   /// the coordinates of the nodes
    27   XYMap<Graph::NodeMap<double> > coords;
    30   XYMap<Graph::NodeMap<double> > coords;
    28   /// the coordinates of the arrows on the edges
    31   /// the coordinates of the arrows on the edges
    29   XYMap<Graph::EdgeMap<double> > arrow_pos;
    32   XYMap<Graph::EdgeMap<double> > arrow_pos;
    30 
    33 
       
    34   ///The content of the object has changed, update is needed.
    31   bool modified;
    35   bool modified;
       
    36 
       
    37   ///Name of file loaded in object.
    32   std::string file_name;
    38   std::string file_name;
    33 
    39 
    34   ///Stores double type NodeMaps
    40   ///Stores double type NodeMaps
    35   std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
    41   std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
    36 
    42 
    37   ///Stores double type EdgeMaps
    43   ///Stores double type EdgeMaps
    38   std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
    44   std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
    39 
    45 
    40   //Stores the default values for the different visualization node attributes
    46   ///Stores the default values for the different visualization node attributes
    41   std::vector<Graph::NodeMap<double> > default_nodemaps;
    47   std::vector<Graph::NodeMap<double> > default_nodemaps;
    42 
    48 
    43   //Stores the default values for the different visualization edge attributes
    49   ///Stores the default values for the different visualization edge attributes
    44   std::vector<Graph::EdgeMap<double> > default_edgemaps;
    50   std::vector<Graph::EdgeMap<double> > default_edgemaps;
    45 
    51 
    46   //Stores the active maps for the different visualization node attributes
    52   ///Stores the active maps for the different visualization node attributes
    47   std::vector< std::string > active_nodemaps;
    53   std::vector< std::string > active_nodemaps;
    48 
    54 
    49   //Stores the active maps for the different visualization edge attributes
    55   /// Stores the active maps for the different visualization edge attributes
    50   std::vector< std::string > active_edgemaps;
    56   std::vector< std::string > active_edgemaps;
    51 
    57 
    52   // Default values for the maps
    58   /// Default values for the maps
    53   std::map< std::string, double > nodemap_default;
    59   std::map< std::string, double > nodemap_default;
    54 
    60 
    55   // Default values for the maps
    61   /// Default values for the maps
    56   std::map< std::string, double > edgemap_default;
    62   std::map< std::string, double > edgemap_default;
    57 
    63 
    58   bool arrow_pos_read_ok;
    64   bool arrow_pos_read_ok;
    59 
    65 
    60 protected:
    66 protected:
       
    67   /// type of the signal emitted if the visualization of the maps might have to be updated.
       
    68 
       
    69   /// bool shows us whether the changed map is edge or nodemap.
       
    70   /// int tells us the refreshed property
    61   typedef sigc::signal<void, bool, int> Signal_Prop;
    71   typedef sigc::signal<void, bool, int> Signal_Prop;
       
    72 
       
    73   /// Signal emitted on any change made on map values
    62   Signal_Prop signal_prop;
    74   Signal_Prop signal_prop;
       
    75 
       
    76   /// Signal emitted in the case of nodemap addition
       
    77 
       
    78   /// std::string is the
       
    79   ///name of the new map
    63   sigc::signal<void, std::string> signal_node_map;
    80   sigc::signal<void, std::string> signal_node_map;
       
    81 
       
    82   /// Signal emitted in the case of edgemap addition
       
    83 
       
    84   /// std::string is the
       
    85   ///name of the new map
    64   sigc::signal<void, std::string> signal_edge_map;
    86   sigc::signal<void, std::string> signal_edge_map;
    65 
    87 
    66 public:
    88 public:
    67   ///Constructor of MapStorage. Expects the Graph of
    89   ///Constructor of MapStorage.
    68   ///which maps will be stored in it.
    90 
    69   ///Its all activity is initializing default values
    91   ///Its all activity is initializing default values
    70   ///for different visualization attributes
    92   ///for different visualization attributes.
    71   ///
       
    72   ///\param graph is the graph for which the maps are stored in this object.
       
    73   MapStorage();
    93   MapStorage();
    74 
    94 
       
    95   ///Destructor of MapStorage
       
    96 
       
    97   ///Maps stored here are created with new. Destructor
       
    98   ///deletes them to free up the reserved memory.
    75   ~MapStorage();
    99   ~MapStorage();
    76 
   100 
    77   void changeActiveMap(bool, int, std::string);
   101   /// Registrates if the shown map by any attribute has changed to another.
    78 
   102 
    79   std::string getActiveEdgeMap(int);
   103   ///It handles the \ref active_edgemaps and
    80   std::string getActiveNodeMap(int);
   104   ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
    81 
   105   ///know the interested objects that the visible map of a certain
       
   106   ///attribute has changed.
       
   107   ///\param itisedge edgemap or nodemap has changed
       
   108   ///\param prop the property of which the map is changed
       
   109   ///\param mapname the visible map
       
   110   void changeActiveMap(bool itisedge , int prop , std::string mapname);
       
   111 
       
   112   /// Returns the active edgemap shown by a visualization property.
       
   113 
       
   114   /// \param prop is the property
       
   115   ///that shows the requested map.
       
   116   std::string getActiveEdgeMap(int prop);
       
   117 
       
   118   /// Returns the active nodemap shown by a visualization property.
       
   119 
       
   120   /// \param prop is the property
       
   121   ///that shows the requested map.
       
   122   std::string getActiveNodeMap(int prop);
       
   123 
       
   124   /// Returns the names of the edgemaps stored here.
    82   std::vector<std::string> getEdgeMapList();
   125   std::vector<std::string> getEdgeMapList();
       
   126 
       
   127   /// Returns the names of the nodemaps stored here.
    83   std::vector<std::string> getNodeMapList();
   128   std::vector<std::string> getNodeMapList();
    84 
   129 
       
   130   ///returns \ref signal_prop to be able to connect functions to it
    85   Signal_Prop signal_prop_ch();
   131   Signal_Prop signal_prop_ch();
    86 
   132 
       
   133   ///returns \ref signal_node_map to be able to connect functions to it
    87   sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
   134   sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
       
   135 
       
   136   ///returns \ref signal_edge_map to be able to connect functions to it
    88   sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
   137   sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
    89 
   138 
       
   139   ///Adds given map to storage.
       
   140 
       
   141   ///A name and the map itself has to be provided.
       
   142   ///\param mapname is the name of map
       
   143   ///\param nodemap is the pointer of the given nodemap
       
   144   ///\param def the default value of the map. If not given, it will be 0.
       
   145   ///If new edge is added to graph the value of it in the map will be this.
       
   146   ///\todo map should be given by reference!
       
   147   ///\todo why is default value stored?
       
   148   int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
       
   149 
    90   ///Adds given map to storage. A name and the map itself has to be provided.
   150   ///Adds given map to storage. A name and the map itself has to be provided.
    91   ///\param name is the name of map
   151 
    92   ///\nodemap is the pointer of the given nodemap
   152   ///A name and the map itself has to be provided.
       
   153   ///\param mapname is the name of map
       
   154   ///\param edgemap is the pointer of the given edgemap
       
   155   ///\param def the default value of the map. If not given, it will be 0.
       
   156   ///If new edge is added to graph the value of it in the map will be this.
    93   ///\todo map should be given by reference!
   157   ///\todo map should be given by reference!
    94   int addNodeMap(const std::string &,Graph::NodeMap<double> *, double);
   158   int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
    95 
       
    96   ///Adds given map to storage. A name and the map itself has to be provided.
       
    97   ///\param name is the name of map
       
    98   ///\edgemap is the pointer of the given edgemap
       
    99   ///\todo map should be given by reference!
       
   100   int addEdgeMap(const std::string &,Graph::EdgeMap<double> *, double);
       
   101 
   159 
   102   ///Returns how much nodemaps is stored in \ref MapStorage
   160   ///Returns how much nodemaps is stored in \ref MapStorage
   103   int numOfNodeMaps() {return nodemap_storage.size();};
   161   int numOfNodeMaps() {return nodemap_storage.size();};
   104 
   162 
   105   ///Returns how much edgemaps is stored in \ref MapStorage
   163   ///Returns how much edgemaps is stored in \ref MapStorage
   106   int numOfEdgeMaps() {return edgemap_storage.size();};
   164   int numOfEdgeMaps() {return edgemap_storage.size();};
   107 
   165 
   108   ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
   166   ///Returns the maximum value of the given NodeMap.
   109   ///\param name is the name of map of which maximum is searched
   167 
   110   double maxOfNodeMap(const std::string &);
   168   ///NodeMap has to be given by its name.
   111 
   169   ///\param name the name of map of which maximum is searched
   112   ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
   170   double maxOfNodeMap(const std::string & name);
   113   ///\param name is the name of map of which maximum is searched
   171 
   114   double maxOfEdgeMap(const std::string &);
   172   ///Returns the maximum value of the given EdgeMap.
   115 
   173 
   116   ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
   174   ///EdgeMap has to be given by its name.
   117   ///\param name is the name of map of which minimum is searched
   175   ///\param name the name of map of which maximum is searched
   118   double minOfNodeMap(const std::string &);
   176   double maxOfEdgeMap(const std::string & name);
   119 
   177 
   120   ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
   178   ///Returns the minimum value of the given NodeMap.
   121   ///\param name is the name of map of which minimum is searched
   179 
   122   double minOfEdgeMap(const std::string &);
   180   ///NodeMap has to be given by its name.
   123 
   181   ///\param name the name of map of which minimum is searched
   124   ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
   182   double minOfNodeMap(const std::string & name);
       
   183 
       
   184   ///Returns the minimum value of the given EdgeMap.
       
   185 
       
   186   ///EdgeMap has to be given by its name.
       
   187   ///\param name the name of map of which minimum is searched
       
   188   double minOfEdgeMap(const std::string & name);
       
   189 
       
   190   ///Returns iterator pointing to the first NodeMap in storage.
       
   191 
       
   192   ///To be able to iterate through each maps this function
       
   193   ///returns an iterator pointing to the first nodemap in
       
   194   ///the storage.
   125   std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
   195   std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
   126 
   196 
   127   ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
   197   ///Returns iterator pointing to the first EdgeMap in storage.
       
   198 
       
   199   ///To be able to iterate through each maps this function
       
   200   ///returns an iterator pointing to the first edgemap in
       
   201   ///the storage.
   128   std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
   202   std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
   129 
   203 
   130   ///To be able to iterate through each maps this function returns an iterator pointing to the last nodemap in the storage.
   204   ///Returns iterator pointing after the last NodeMap in storage.
       
   205 
       
   206   ///To be able to iterate through each maps this function
       
   207   ///returns an iterator pointing to the last nodemap in the storage.
   131   std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
   208   std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
   132 
   209 
   133   ///To be able to iterate through each maps this function returns an iterator pointing to the last edgemap in the storage.
   210   ///Returns iterator pointing after the last EdgeMap in storage.
       
   211 
       
   212   ///To be able to iterate through each maps this function
       
   213   ///returns an iterator pointing to the last edgemap in the storage.
   134   std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
   214   std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
   135 
   215 
   136   void mapChanged(bool, std::string);
   216   ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
   137 
   217 
       
   218   ///If values in a map have changed, this function checks, whether it is displayed.
       
   219   ///This check means searching the given mapname between active maps
       
   220   ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
       
   221   ///it emits a signal with the property, where the gotten mapname was found. One signal
       
   222   ///is emitted for each property displaying the given map.
       
   223   ///\param itisedge whether the map an edgemap or nodemap
       
   224   ///\param mapname name of map to visualize
       
   225   void mapChanged(bool itisedge, std::string mapname);
       
   226 
       
   227   ///Read datas from the given filename.
   138   int readFromFile(const std::string &);
   228   int readFromFile(const std::string &);
       
   229 
       
   230   ///Save datas to the given filename.
   139   void writeToFile(const std::string &);
   231   void writeToFile(const std::string &);
   140 
   232 
       
   233   ///Deletes all datastructures stored here.
   141   void clear();
   234   void clear();
   142 
   235 
   143   void ArrowPosReadOK();
   236   void ArrowPosReadOK();
   144 };
   237 };
   145 
   238