mapstorage.h
author alpar
Tue, 07 Nov 2006 21:27:28 +0000
changeset 180 911c6ba0e3c8
parent 174 95872af46fc4
child 184 4e8704aae278
permissions -rw-r--r--
Bugfix + polishing
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
hegyi@177
    86
  /// Signal emitted on any change made on map values
hegyi@177
    87
hegyi@177
    88
  /// Signal emitted if the visualization of the maps might have to be updated.
hegyi@118
    89
  /// bool shows us whether the changed map is edge or nodemap.
hegyi@118
    90
  /// int tells us the refreshed property
hegyi@177
    91
  sigc::signal<void, bool, int> signal_prop;
hegyi@118
    92
hegyi@118
    93
  /// Signal emitted in the case of nodemap addition
hegyi@118
    94
hegyi@118
    95
  /// std::string is the
hegyi@118
    96
  ///name of the new map
hegyi@108
    97
  sigc::signal<void, std::string> signal_node_map;
hegyi@118
    98
hegyi@118
    99
  /// Signal emitted in the case of edgemap addition
hegyi@118
   100
hegyi@118
   101
  /// std::string is the
hegyi@118
   102
  ///name of the new map
hegyi@108
   103
  sigc::signal<void, std::string> signal_edge_map;
hegyi@94
   104
hegyi@172
   105
  /// Signal emitted, when entry in \ref MapWin should be changed.
hegyi@172
   106
  sigc::signal<void, bool, int, std::string> signal_map_win;
hegyi@172
   107
hegyi@177
   108
  /// Signal emitted, when entry in \ref DesignWin should be changed.
hegyi@177
   109
  sigc::signal<void, double, double, int> signal_design_win;
hegyi@177
   110
hegyi@177
   111
  ///Iteration number during graph design
hegyi@177
   112
  int iterations;
hegyi@177
   113
hegyi@177
   114
  ///Attraction factor during graph design
hegyi@177
   115
  double attraction;
hegyi@177
   116
hegyi@177
   117
  ///Propulsation factor during graph design
hegyi@177
   118
  double propulsation;
hegyi@177
   119
ladanyi@6
   120
public:
hegyi@118
   121
  ///Constructor of MapStorage.
hegyi@118
   122
ladanyi@6
   123
  ///Its all activity is initializing default values
hegyi@118
   124
  ///for different visualization attributes.
ladanyi@53
   125
  MapStorage();
ladanyi@53
   126
hegyi@118
   127
  ///Destructor of MapStorage
hegyi@118
   128
hegyi@118
   129
  ///Maps stored here are created with new. Destructor
hegyi@118
   130
  ///deletes them to free up the reserved memory.
ladanyi@53
   131
  ~MapStorage();
ladanyi@6
   132
hegyi@118
   133
  /// Registrates if the shown map by any attribute has changed to another.
hegyi@94
   134
hegyi@118
   135
  ///It handles the \ref active_edgemaps and
hegyi@118
   136
  ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
hegyi@118
   137
  ///know the interested objects that the visible map of a certain
hegyi@118
   138
  ///attribute has changed.
hegyi@118
   139
  ///\param itisedge edgemap or nodemap has changed
hegyi@118
   140
  ///\param prop the property of which the map is changed
hegyi@118
   141
  ///\param mapname the visible map
hegyi@118
   142
  void changeActiveMap(bool itisedge , int prop , std::string mapname);
hegyi@94
   143
hegyi@172
   144
  ///Emits signals that let change the active maps in \ref MapWin.
hegyi@172
   145
  void broadcastActiveMaps();
hegyi@172
   146
hegyi@118
   147
  /// Returns the active edgemap shown by a visualization property.
hegyi@118
   148
hegyi@118
   149
  /// \param prop is the property
hegyi@118
   150
  ///that shows the requested map.
hegyi@118
   151
  std::string getActiveEdgeMap(int prop);
hegyi@118
   152
hegyi@118
   153
  /// Returns the active nodemap shown by a visualization property.
hegyi@118
   154
hegyi@118
   155
  /// \param prop is the property
hegyi@118
   156
  ///that shows the requested map.
hegyi@118
   157
  std::string getActiveNodeMap(int prop);
hegyi@118
   158
hegyi@118
   159
  /// Returns the names of the edgemaps stored here.
hegyi@94
   160
  std::vector<std::string> getEdgeMapList();
hegyi@118
   161
hegyi@118
   162
  /// Returns the names of the nodemaps stored here.
hegyi@94
   163
  std::vector<std::string> getNodeMapList();
hegyi@94
   164
hegyi@118
   165
  ///returns \ref signal_prop to be able to connect functions to it
hegyi@177
   166
  sigc::signal<void, bool, int> signal_prop_ch();
hegyi@94
   167
hegyi@118
   168
  ///returns \ref signal_node_map to be able to connect functions to it
hegyi@108
   169
  sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
hegyi@118
   170
hegyi@118
   171
  ///returns \ref signal_edge_map to be able to connect functions to it
hegyi@108
   172
  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
hegyi@108
   173
hegyi@172
   174
  ///returns \ref signal_map_win to be able to connect functions to it
hegyi@172
   175
  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
hegyi@172
   176
hegyi@177
   177
  ///returns \ref signal_design_win to be able to connect functions to it
hegyi@177
   178
  sigc::signal<void, double, double, int> signal_design_win_ch(){return signal_design_win;};
hegyi@177
   179
hegyi@118
   180
  ///Adds given map to storage.
hegyi@118
   181
hegyi@118
   182
  ///A name and the map itself has to be provided.
hegyi@118
   183
  ///\param mapname is the name of map
hegyi@118
   184
  ///\param nodemap is the pointer of the given nodemap
hegyi@118
   185
  ///\param def the default value of the map. If not given, it will be 0.
hegyi@118
   186
  ///If new edge is added to graph the value of it in the map will be this.
ladanyi@6
   187
  ///\todo map should be given by reference!
hegyi@118
   188
  ///\todo why is default value stored?
hegyi@118
   189
  int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
ladanyi@6
   190
ladanyi@6
   191
  ///Adds given map to storage. A name and the map itself has to be provided.
hegyi@118
   192
hegyi@118
   193
  ///A name and the map itself has to be provided.
hegyi@118
   194
  ///\param mapname is the name of map
hegyi@118
   195
  ///\param edgemap is the pointer of the given edgemap
hegyi@118
   196
  ///\param def the default value of the map. If not given, it will be 0.
hegyi@118
   197
  ///If new edge is added to graph the value of it in the map will be this.
ladanyi@6
   198
  ///\todo map should be given by reference!
hegyi@118
   199
  int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
ladanyi@6
   200
ladanyi@6
   201
  ///Returns how much nodemaps is stored in \ref MapStorage
ladanyi@6
   202
  int numOfNodeMaps() {return nodemap_storage.size();};
ladanyi@6
   203
ladanyi@6
   204
  ///Returns how much edgemaps is stored in \ref MapStorage
ladanyi@6
   205
  int numOfEdgeMaps() {return edgemap_storage.size();};
ladanyi@6
   206
hegyi@118
   207
  ///Returns the maximum value of the given NodeMap.
ladanyi@6
   208
hegyi@118
   209
  ///NodeMap has to be given by its name.
hegyi@118
   210
  ///\param name the name of map of which maximum is searched
hegyi@118
   211
  double maxOfNodeMap(const std::string & name);
ladanyi@6
   212
hegyi@118
   213
  ///Returns the maximum value of the given EdgeMap.
ladanyi@6
   214
hegyi@118
   215
  ///EdgeMap has to be given by its name.
hegyi@118
   216
  ///\param name the name of map of which maximum is searched
hegyi@118
   217
  double maxOfEdgeMap(const std::string & name);
ladanyi@6
   218
hegyi@118
   219
  ///Returns the minimum value of the given NodeMap.
hegyi@118
   220
hegyi@118
   221
  ///NodeMap has to be given by its name.
hegyi@118
   222
  ///\param name the name of map of which minimum is searched
hegyi@118
   223
  double minOfNodeMap(const std::string & name);
hegyi@118
   224
hegyi@118
   225
  ///Returns the minimum value of the given EdgeMap.
hegyi@118
   226
hegyi@118
   227
  ///EdgeMap has to be given by its name.
hegyi@118
   228
  ///\param name the name of map of which minimum is searched
hegyi@118
   229
  double minOfEdgeMap(const std::string & name);
hegyi@118
   230
hegyi@118
   231
  ///Returns iterator pointing to the first 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 first nodemap in
hegyi@118
   235
  ///the storage.
ladanyi@6
   236
  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
ladanyi@6
   237
hegyi@118
   238
  ///Returns iterator pointing to the first EdgeMap in storage.
hegyi@118
   239
hegyi@118
   240
  ///To be able to iterate through each maps this function
hegyi@118
   241
  ///returns an iterator pointing to the first edgemap in
hegyi@118
   242
  ///the storage.
ladanyi@6
   243
  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
hegyi@26
   244
hegyi@118
   245
  ///Returns iterator pointing after the last NodeMap in storage.
hegyi@118
   246
hegyi@118
   247
  ///To be able to iterate through each maps this function
hegyi@118
   248
  ///returns an iterator pointing to the last nodemap in the storage.
hegyi@31
   249
  std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
hegyi@31
   250
hegyi@118
   251
  ///Returns iterator pointing after the last EdgeMap in storage.
hegyi@118
   252
hegyi@118
   253
  ///To be able to iterate through each maps this function
hegyi@118
   254
  ///returns an iterator pointing to the last edgemap in the storage.
hegyi@31
   255
  std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
hegyi@31
   256
hegyi@118
   257
  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
hegyi@111
   258
hegyi@118
   259
  ///If values in a map have changed, this function checks, whether it is displayed.
hegyi@118
   260
  ///This check means searching the given mapname between active maps
hegyi@118
   261
  ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
hegyi@118
   262
  ///it emits a signal with the property, where the gotten mapname was found. One signal
hegyi@118
   263
  ///is emitted for each property displaying the given map.
hegyi@118
   264
  ///\param itisedge whether the map an edgemap or nodemap
hegyi@118
   265
  ///\param mapname name of map to visualize
hegyi@118
   266
  void mapChanged(bool itisedge, std::string mapname);
hegyi@118
   267
hegyi@118
   268
  ///Read datas from the given filename.
ladanyi@63
   269
  int readFromFile(const std::string &);
hegyi@118
   270
hegyi@118
   271
  ///Save datas to the given filename.
ladanyi@53
   272
  void writeToFile(const std::string &);
ladanyi@53
   273
hegyi@118
   274
  ///Deletes all datastructures stored here.
ladanyi@53
   275
  void clear();
ladanyi@98
   276
ladanyi@98
   277
  void ArrowPosReadOK();
hegyi@177
   278
hegyi@177
   279
  void get_design_data(double &, double &, int &);
hegyi@177
   280
  void set_attraction(double);
hegyi@177
   281
  void set_propulsation(double);
hegyi@177
   282
  void set_iteration(int);
hegyi@177
   283
hegyi@177
   284
  void redesign_data_changed();
ladanyi@6
   285
};
ladanyi@6
   286
ladanyi@6
   287
#endif //MAPSTORAGE_H