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