COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapstorage.h @ 173:8339178ae43d

Last change on this file since 173:8339178ae43d was 173:8339178ae43d, checked in by Akos Ladanyi, 14 years ago

Added two new classes.

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