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