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