mapstorage.h
author hegyi
Thu, 01 Mar 2007 16:28:13 +0000
changeset 198 d6cc0579b94b
parent 195 125c56c1efda
child 201 879e47e5b731
permissions -rw-r--r--
Shape feature of EPS can be used.
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@194
    22
#include <all_include.h>
hegyi@194
    23
#include <xymap.h>
hegyi@94
    24
#include <libgnomecanvasmm.h>
ladanyi@6
    25
hegyi@118
    26
///class MapStorage handles NodeMaps and EdgeMaps.
hegyi@118
    27
ladanyi@6
    28
///Class MapStorage is responsible for storing
ladanyi@6
    29
///NodeMaps and EdgeMaps that can be shown later
ladanyi@6
    30
///on GUI. Therefore maps can be added to it,
ladanyi@6
    31
///and datas over the added maps can be queried.
ladanyi@6
    32
///The maps will be stored in an std::map,
ladanyi@6
    33
///referenced with their names. Unfortunately at
ladanyi@6
    34
///the moment it works only with double type maps
ladanyi@6
    35
///
ladanyi@6
    36
///\todo too many things are public!!
ladanyi@6
    37
class MapStorage
ladanyi@6
    38
{
ladanyi@184
    39
private:
ladanyi@184
    40
  std::string background_file_name;
ladanyi@184
    41
  bool background_set;
ladanyi@184
    42
  double background_scaling;
ladanyi@6
    43
public:
ladanyi@184
    44
  void setBackground(const std::string& file_name);
ladanyi@184
    45
  const std::string& getBackgroundFilename();
ladanyi@184
    46
  bool isBackgroundSet();
ladanyi@184
    47
  double getBackgroundScaling();
ladanyi@184
    48
  void setBackgroundScaling(double scaling);
hegyi@118
    49
  ///The graph for which the datas are stored.
ladanyi@53
    50
  Graph graph;
ladanyi@98
    51
  /// the coordinates of the nodes
ladanyi@53
    52
  XYMap<Graph::NodeMap<double> > coords;
ladanyi@98
    53
  /// the coordinates of the arrows on the edges
ladanyi@98
    54
  XYMap<Graph::EdgeMap<double> > arrow_pos;
ladanyi@53
    55
hegyi@118
    56
  ///The content of the object has changed, update is needed.
ladanyi@53
    57
  bool modified;
hegyi@118
    58
hegyi@118
    59
  ///Name of file loaded in object.
ladanyi@53
    60
  std::string file_name;
ladanyi@6
    61
ladanyi@6
    62
  ///Stores double type NodeMaps
ladanyi@6
    63
  std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
ladanyi@6
    64
ladanyi@6
    65
  ///Stores double type EdgeMaps
ladanyi@6
    66
  std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
ladanyi@6
    67
hegyi@118
    68
  ///Stores the default values for the different visualization node attributes
ladanyi@6
    69
  std::vector<Graph::NodeMap<double> > default_nodemaps;
ladanyi@6
    70
hegyi@118
    71
  ///Stores the default values for the different visualization edge attributes
ladanyi@6
    72
  std::vector<Graph::EdgeMap<double> > default_edgemaps;
ladanyi@6
    73
hegyi@118
    74
  ///Stores the active maps for the different visualization node attributes
hegyi@94
    75
  std::vector< std::string > active_nodemaps;
hegyi@94
    76
hegyi@118
    77
  /// Stores the active maps for the different visualization edge attributes
hegyi@94
    78
  std::vector< std::string > active_edgemaps;
hegyi@94
    79
hegyi@118
    80
  /// Default values for the maps
ladanyi@63
    81
  std::map< std::string, double > nodemap_default;
ladanyi@63
    82
hegyi@118
    83
  /// Default values for the maps
ladanyi@63
    84
  std::map< std::string, double > edgemap_default;
ladanyi@63
    85
ladanyi@98
    86
  bool arrow_pos_read_ok;
ladanyi@98
    87
hegyi@94
    88
protected:
hegyi@118
    89
hegyi@177
    90
  /// Signal emitted on any change made on map values
hegyi@177
    91
hegyi@177
    92
  /// Signal emitted if the visualization of the maps might have to be updated.
hegyi@118
    93
  /// bool shows us whether the changed map is edge or nodemap.
hegyi@118
    94
  /// int tells us the refreshed property
hegyi@177
    95
  sigc::signal<void, bool, int> signal_prop;
hegyi@118
    96
hegyi@118
    97
  /// Signal emitted in the case of nodemap addition
hegyi@118
    98
hegyi@118
    99
  /// std::string is the
hegyi@118
   100
  ///name of the new map
hegyi@108
   101
  sigc::signal<void, std::string> signal_node_map;
hegyi@118
   102
hegyi@118
   103
  /// Signal emitted in the case of edgemap addition
hegyi@118
   104
hegyi@118
   105
  /// std::string is the
hegyi@118
   106
  ///name of the new map
hegyi@108
   107
  sigc::signal<void, std::string> signal_edge_map;
hegyi@94
   108
hegyi@172
   109
  /// Signal emitted, when entry in \ref MapWin should be changed.
hegyi@172
   110
  sigc::signal<void, bool, int, std::string> signal_map_win;
hegyi@172
   111
hegyi@177
   112
  /// Signal emitted, when entry in \ref DesignWin should be changed.
hegyi@177
   113
  sigc::signal<void, double, double, int> signal_design_win;
hegyi@177
   114
hegyi@195
   115
  ///Signal emitted when background should be set by \ref NoteBookTab
hegyi@195
   116
  sigc::signal<void> signal_background;
hegyi@195
   117
hegyi@177
   118
  ///Iteration number during graph design
hegyi@177
   119
  int iterations;
hegyi@177
   120
hegyi@177
   121
  ///Attraction factor during graph design
hegyi@177
   122
  double attraction;
hegyi@177
   123
hegyi@177
   124
  ///Propulsation factor during graph design
hegyi@177
   125
  double propulsation;
hegyi@177
   126
ladanyi@6
   127
public:
hegyi@118
   128
  ///Constructor of MapStorage.
hegyi@118
   129
ladanyi@6
   130
  ///Its all activity is initializing default values
hegyi@118
   131
  ///for different visualization attributes.
hegyi@195
   132
  MapStorage();
ladanyi@53
   133
hegyi@118
   134
  ///Destructor of MapStorage
hegyi@118
   135
hegyi@118
   136
  ///Maps stored here are created with new. Destructor
hegyi@118
   137
  ///deletes them to free up the reserved memory.
ladanyi@53
   138
  ~MapStorage();
ladanyi@6
   139
hegyi@118
   140
  /// Registrates if the shown map by any attribute has changed to another.
hegyi@94
   141
hegyi@118
   142
  ///It handles the \ref active_edgemaps and
hegyi@118
   143
  ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
hegyi@118
   144
  ///know the interested objects that the visible map of a certain
hegyi@118
   145
  ///attribute has changed.
hegyi@118
   146
  ///\param itisedge edgemap or nodemap has changed
hegyi@118
   147
  ///\param prop the property of which the map is changed
hegyi@118
   148
  ///\param mapname the visible map
hegyi@118
   149
  void changeActiveMap(bool itisedge , int prop , std::string mapname);
hegyi@94
   150
hegyi@172
   151
  ///Emits signals that let change the active maps in \ref MapWin.
hegyi@172
   152
  void broadcastActiveMaps();
hegyi@172
   153
hegyi@118
   154
  /// Returns the active edgemap shown by a visualization property.
hegyi@118
   155
hegyi@118
   156
  /// \param prop is the property
hegyi@118
   157
  ///that shows the requested map.
hegyi@118
   158
  std::string getActiveEdgeMap(int prop);
hegyi@118
   159
hegyi@118
   160
  /// Returns the active nodemap shown by a visualization property.
hegyi@118
   161
hegyi@118
   162
  /// \param prop is the property
hegyi@118
   163
  ///that shows the requested map.
hegyi@118
   164
  std::string getActiveNodeMap(int prop);
hegyi@118
   165
hegyi@118
   166
  /// Returns the names of the edgemaps stored here.
hegyi@94
   167
  std::vector<std::string> getEdgeMapList();
hegyi@118
   168
hegyi@118
   169
  /// Returns the names of the nodemaps stored here.
hegyi@94
   170
  std::vector<std::string> getNodeMapList();
hegyi@94
   171
hegyi@118
   172
  ///returns \ref signal_prop to be able to connect functions to it
hegyi@177
   173
  sigc::signal<void, bool, int> signal_prop_ch();
hegyi@94
   174
hegyi@118
   175
  ///returns \ref signal_node_map to be able to connect functions to it
hegyi@108
   176
  sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
hegyi@118
   177
hegyi@118
   178
  ///returns \ref signal_edge_map to be able to connect functions to it
hegyi@108
   179
  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
hegyi@108
   180
hegyi@172
   181
  ///returns \ref signal_map_win to be able to connect functions to it
hegyi@172
   182
  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
hegyi@172
   183
hegyi@177
   184
  ///returns \ref signal_design_win to be able to connect functions to it
hegyi@177
   185
  sigc::signal<void, double, double, int> signal_design_win_ch(){return signal_design_win;};
hegyi@177
   186
hegyi@195
   187
  ///returns \ref signal_background to be able to connect functions to it
hegyi@195
   188
  sigc::signal<void> signal_background_ch(){return signal_background;};
hegyi@195
   189
hegyi@195
   190
hegyi@118
   191
  ///Adds given map to storage.
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 nodemap is the pointer of the given nodemap
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
  ///\todo why is default value stored?
hegyi@118
   200
  int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
ladanyi@6
   201
ladanyi@6
   202
  ///Adds given map to storage. A name and the map itself has to be provided.
hegyi@118
   203
hegyi@118
   204
  ///A name and the map itself has to be provided.
hegyi@118
   205
  ///\param mapname is the name of map
hegyi@118
   206
  ///\param edgemap is the pointer of the given edgemap
hegyi@118
   207
  ///\param def the default value of the map. If not given, it will be 0.
hegyi@118
   208
  ///If new edge is added to graph the value of it in the map will be this.
ladanyi@6
   209
  ///\todo map should be given by reference!
hegyi@118
   210
  int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
ladanyi@6
   211
ladanyi@6
   212
  ///Returns how much nodemaps is stored in \ref MapStorage
ladanyi@6
   213
  int numOfNodeMaps() {return nodemap_storage.size();};
ladanyi@6
   214
ladanyi@6
   215
  ///Returns how much edgemaps is stored in \ref MapStorage
ladanyi@6
   216
  int numOfEdgeMaps() {return edgemap_storage.size();};
ladanyi@6
   217
hegyi@118
   218
  ///Returns the maximum value of the given NodeMap.
ladanyi@6
   219
hegyi@118
   220
  ///NodeMap has to be given by its name.
hegyi@118
   221
  ///\param name the name of map of which maximum is searched
hegyi@118
   222
  double maxOfNodeMap(const std::string & name);
ladanyi@6
   223
hegyi@118
   224
  ///Returns the maximum value of the given EdgeMap.
ladanyi@6
   225
hegyi@118
   226
  ///EdgeMap has to be given by its name.
hegyi@118
   227
  ///\param name the name of map of which maximum is searched
hegyi@118
   228
  double maxOfEdgeMap(const std::string & name);
ladanyi@6
   229
hegyi@118
   230
  ///Returns the minimum value of the given NodeMap.
hegyi@118
   231
hegyi@118
   232
  ///NodeMap has to be given by its name.
hegyi@118
   233
  ///\param name the name of map of which minimum is searched
hegyi@118
   234
  double minOfNodeMap(const std::string & name);
hegyi@118
   235
hegyi@118
   236
  ///Returns the minimum value of the given EdgeMap.
hegyi@118
   237
hegyi@118
   238
  ///EdgeMap has to be given by its name.
hegyi@118
   239
  ///\param name the name of map of which minimum is searched
hegyi@118
   240
  double minOfEdgeMap(const std::string & name);
hegyi@118
   241
hegyi@118
   242
  ///Returns iterator pointing to the first NodeMap in storage.
hegyi@118
   243
hegyi@118
   244
  ///To be able to iterate through each maps this function
hegyi@118
   245
  ///returns an iterator pointing to the first nodemap in
hegyi@118
   246
  ///the storage.
ladanyi@6
   247
  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
ladanyi@6
   248
hegyi@118
   249
  ///Returns iterator pointing to the first EdgeMap in storage.
hegyi@118
   250
hegyi@118
   251
  ///To be able to iterate through each maps this function
hegyi@118
   252
  ///returns an iterator pointing to the first edgemap in
hegyi@118
   253
  ///the storage.
ladanyi@6
   254
  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
hegyi@26
   255
hegyi@118
   256
  ///Returns iterator pointing after the last NodeMap in storage.
hegyi@118
   257
hegyi@118
   258
  ///To be able to iterate through each maps this function
hegyi@118
   259
  ///returns an iterator pointing to the last nodemap in the storage.
hegyi@31
   260
  std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
hegyi@31
   261
hegyi@118
   262
  ///Returns iterator pointing after the last EdgeMap in storage.
hegyi@118
   263
hegyi@118
   264
  ///To be able to iterate through each maps this function
hegyi@118
   265
  ///returns an iterator pointing to the last edgemap in the storage.
hegyi@31
   266
  std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
hegyi@31
   267
hegyi@118
   268
  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
hegyi@111
   269
hegyi@118
   270
  ///If values in a map have changed, this function checks, whether it is displayed.
hegyi@118
   271
  ///This check means searching the given mapname between active maps
hegyi@118
   272
  ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
hegyi@118
   273
  ///it emits a signal with the property, where the gotten mapname was found. One signal
hegyi@118
   274
  ///is emitted for each property displaying the given map.
hegyi@118
   275
  ///\param itisedge whether the map an edgemap or nodemap
hegyi@118
   276
  ///\param mapname name of map to visualize
hegyi@118
   277
  void mapChanged(bool itisedge, std::string mapname);
hegyi@118
   278
hegyi@118
   279
  ///Read datas from the given filename.
ladanyi@63
   280
  int readFromFile(const std::string &);
hegyi@118
   281
hegyi@118
   282
  ///Save datas to the given filename.
ladanyi@53
   283
  void writeToFile(const std::string &);
ladanyi@53
   284
hegyi@118
   285
  ///Deletes all datastructures stored here.
ladanyi@53
   286
  void clear();
ladanyi@98
   287
ladanyi@98
   288
  void ArrowPosReadOK();
hegyi@177
   289
hegyi@177
   290
  void get_design_data(double &, double &, int &);
hegyi@177
   291
  void set_attraction(double);
hegyi@177
   292
  void set_propulsation(double);
hegyi@177
   293
  void set_iteration(int);
hegyi@177
   294
hegyi@177
   295
  void redesign_data_changed();
hegyi@191
   296
hegyi@198
   297
  void exportGraphToEPS(std::vector<bool>, std::string, std::string);
ladanyi@6
   298
};
ladanyi@6
   299
ladanyi@6
   300
#endif //MAPSTORAGE_H