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