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