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