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