COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapstorage.h @ 172:fc1e478697d3

Last change on this file since 172:fc1e478697d3 was 172:fc1e478697d3, checked in by Hegyi Péter, 18 years ago

Currently visualized map can be saved and loaded from file.

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