COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapstorage.h @ 194:6b2b718420eb

Last change on this file since 194:6b2b718420eb was 194:6b2b718420eb, checked in by Hegyi Péter, 17 years ago

Header reorganising

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