mapstorage.h
author hegyi
Wed, 25 Oct 2006 13:21:24 +0000
changeset 172 fc1e478697d3
parent 118 cfd49e5c8723
child 173 8339178ae43d
permissions -rw-r--r--
Currently visualized map can be saved and loaded from file.
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
hegyi@172
    88
  /// Signal emitted, when entry in \ref MapWin should be changed.
hegyi@172
    89
  sigc::signal<void, bool, int, std::string> signal_map_win;
hegyi@172
    90
ladanyi@6
    91
public:
hegyi@118
    92
  ///Constructor of MapStorage.
hegyi@118
    93
ladanyi@6
    94
  ///Its all activity is initializing default values
hegyi@118
    95
  ///for different visualization attributes.
ladanyi@53
    96
  MapStorage();
ladanyi@53
    97
hegyi@118
    98
  ///Destructor of MapStorage
hegyi@118
    99
hegyi@118
   100
  ///Maps stored here are created with new. Destructor
hegyi@118
   101
  ///deletes them to free up the reserved memory.
ladanyi@53
   102
  ~MapStorage();
ladanyi@6
   103
hegyi@118
   104
  /// Registrates if the shown map by any attribute has changed to another.
hegyi@94
   105
hegyi@118
   106
  ///It handles the \ref active_edgemaps and
hegyi@118
   107
  ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
hegyi@118
   108
  ///know the interested objects that the visible map of a certain
hegyi@118
   109
  ///attribute has changed.
hegyi@118
   110
  ///\param itisedge edgemap or nodemap has changed
hegyi@118
   111
  ///\param prop the property of which the map is changed
hegyi@118
   112
  ///\param mapname the visible map
hegyi@118
   113
  void changeActiveMap(bool itisedge , int prop , std::string mapname);
hegyi@94
   114
hegyi@172
   115
  ///Emits signals that let change the active maps in \ref MapWin.
hegyi@172
   116
  void broadcastActiveMaps();
hegyi@172
   117
hegyi@118
   118
  /// Returns the active edgemap 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 getActiveEdgeMap(int prop);
hegyi@118
   123
hegyi@118
   124
  /// Returns the active nodemap shown by a visualization property.
hegyi@118
   125
hegyi@118
   126
  /// \param prop is the property
hegyi@118
   127
  ///that shows the requested map.
hegyi@118
   128
  std::string getActiveNodeMap(int prop);
hegyi@118
   129
hegyi@118
   130
  /// Returns the names of the edgemaps stored here.
hegyi@94
   131
  std::vector<std::string> getEdgeMapList();
hegyi@118
   132
hegyi@118
   133
  /// Returns the names of the nodemaps stored here.
hegyi@94
   134
  std::vector<std::string> getNodeMapList();
hegyi@94
   135
hegyi@118
   136
  ///returns \ref signal_prop to be able to connect functions to it
hegyi@94
   137
  Signal_Prop signal_prop_ch();
hegyi@94
   138
hegyi@118
   139
  ///returns \ref signal_node_map to be able to connect functions to it
hegyi@108
   140
  sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
hegyi@118
   141
hegyi@118
   142
  ///returns \ref signal_edge_map to be able to connect functions to it
hegyi@108
   143
  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
hegyi@108
   144
hegyi@172
   145
  ///returns \ref signal_map_win to be able to connect functions to it
hegyi@172
   146
  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
hegyi@172
   147
hegyi@118
   148
  ///Adds given map to storage.
hegyi@118
   149
hegyi@118
   150
  ///A name and the map itself has to be provided.
hegyi@118
   151
  ///\param mapname is the name of map
hegyi@118
   152
  ///\param nodemap is the pointer of the given nodemap
hegyi@118
   153
  ///\param def the default value of the map. If not given, it will be 0.
hegyi@118
   154
  ///If new edge is added to graph the value of it in the map will be this.
ladanyi@6
   155
  ///\todo map should be given by reference!
hegyi@118
   156
  ///\todo why is default value stored?
hegyi@118
   157
  int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
ladanyi@6
   158
ladanyi@6
   159
  ///Adds given map to storage. A name and the map itself has to be provided.
hegyi@118
   160
hegyi@118
   161
  ///A name and the map itself has to be provided.
hegyi@118
   162
  ///\param mapname is the name of map
hegyi@118
   163
  ///\param edgemap is the pointer of the given edgemap
hegyi@118
   164
  ///\param def the default value of the map. If not given, it will be 0.
hegyi@118
   165
  ///If new edge is added to graph the value of it in the map will be this.
ladanyi@6
   166
  ///\todo map should be given by reference!
hegyi@118
   167
  int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
ladanyi@6
   168
ladanyi@6
   169
  ///Returns how much nodemaps is stored in \ref MapStorage
ladanyi@6
   170
  int numOfNodeMaps() {return nodemap_storage.size();};
ladanyi@6
   171
ladanyi@6
   172
  ///Returns how much edgemaps is stored in \ref MapStorage
ladanyi@6
   173
  int numOfEdgeMaps() {return edgemap_storage.size();};
ladanyi@6
   174
hegyi@118
   175
  ///Returns the maximum value of the given NodeMap.
ladanyi@6
   176
hegyi@118
   177
  ///NodeMap has to be given by its name.
hegyi@118
   178
  ///\param name the name of map of which maximum is searched
hegyi@118
   179
  double maxOfNodeMap(const std::string & name);
ladanyi@6
   180
hegyi@118
   181
  ///Returns the maximum value of the given EdgeMap.
ladanyi@6
   182
hegyi@118
   183
  ///EdgeMap has to be given by its name.
hegyi@118
   184
  ///\param name the name of map of which maximum is searched
hegyi@118
   185
  double maxOfEdgeMap(const std::string & name);
ladanyi@6
   186
hegyi@118
   187
  ///Returns the minimum value of the given NodeMap.
hegyi@118
   188
hegyi@118
   189
  ///NodeMap has to be given by its name.
hegyi@118
   190
  ///\param name the name of map of which minimum is searched
hegyi@118
   191
  double minOfNodeMap(const std::string & name);
hegyi@118
   192
hegyi@118
   193
  ///Returns the minimum value of the given EdgeMap.
hegyi@118
   194
hegyi@118
   195
  ///EdgeMap has to be given by its name.
hegyi@118
   196
  ///\param name the name of map of which minimum is searched
hegyi@118
   197
  double minOfEdgeMap(const std::string & name);
hegyi@118
   198
hegyi@118
   199
  ///Returns iterator pointing to the first NodeMap in storage.
hegyi@118
   200
hegyi@118
   201
  ///To be able to iterate through each maps this function
hegyi@118
   202
  ///returns an iterator pointing to the first nodemap in
hegyi@118
   203
  ///the storage.
ladanyi@6
   204
  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
ladanyi@6
   205
hegyi@118
   206
  ///Returns iterator pointing to the first EdgeMap in storage.
hegyi@118
   207
hegyi@118
   208
  ///To be able to iterate through each maps this function
hegyi@118
   209
  ///returns an iterator pointing to the first edgemap in
hegyi@118
   210
  ///the storage.
ladanyi@6
   211
  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
hegyi@26
   212
hegyi@118
   213
  ///Returns iterator pointing after the last NodeMap in storage.
hegyi@118
   214
hegyi@118
   215
  ///To be able to iterate through each maps this function
hegyi@118
   216
  ///returns an iterator pointing to the last nodemap in the storage.
hegyi@31
   217
  std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
hegyi@31
   218
hegyi@118
   219
  ///Returns iterator pointing after the last EdgeMap in storage.
hegyi@118
   220
hegyi@118
   221
  ///To be able to iterate through each maps this function
hegyi@118
   222
  ///returns an iterator pointing to the last edgemap in the storage.
hegyi@31
   223
  std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
hegyi@31
   224
hegyi@118
   225
  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
hegyi@111
   226
hegyi@118
   227
  ///If values in a map have changed, this function checks, whether it is displayed.
hegyi@118
   228
  ///This check means searching the given mapname between active maps
hegyi@118
   229
  ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
hegyi@118
   230
  ///it emits a signal with the property, where the gotten mapname was found. One signal
hegyi@118
   231
  ///is emitted for each property displaying the given map.
hegyi@118
   232
  ///\param itisedge whether the map an edgemap or nodemap
hegyi@118
   233
  ///\param mapname name of map to visualize
hegyi@118
   234
  void mapChanged(bool itisedge, std::string mapname);
hegyi@118
   235
hegyi@118
   236
  ///Read datas from the given filename.
ladanyi@63
   237
  int readFromFile(const std::string &);
hegyi@118
   238
hegyi@118
   239
  ///Save datas to the given filename.
ladanyi@53
   240
  void writeToFile(const std::string &);
ladanyi@53
   241
hegyi@118
   242
  ///Deletes all datastructures stored here.
ladanyi@53
   243
  void clear();
ladanyi@98
   244
ladanyi@98
   245
  void ArrowPosReadOK();
ladanyi@6
   246
};
ladanyi@6
   247
ladanyi@6
   248
#endif //MAPSTORAGE_H