Changeset 201:879e47e5b731 in glemon-0.x for mapstorage.h
- Timestamp:
- 01/02/08 22:03:09 (16 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mapstorage.h
r198 r201 20 20 #define MAPSTORAGE_H 21 21 22 #include <all_include.h> 23 #include <xymap.h> 22 class Mapstorage; 23 24 #include <vector> 25 #include <map> 26 #include <string> 27 #include "all_include.h" 28 #include "xymap.h" 24 29 #include <libgnomecanvasmm.h> 30 #include "map_value.h" 31 #include "map_value_map.h" 25 32 26 33 ///class MapStorage handles NodeMaps and EdgeMaps. … … 42 49 double background_scaling; 43 50 public: 51 class Error : public std::exception 52 { 53 private: 54 std::string message; 55 public: 56 Error(const std::string& msg) : message(msg) {} 57 virtual const char* what() const throw() 58 { 59 return message.c_str(); 60 } 61 ~Error() throw() {} 62 }; 63 44 64 void setBackground(const std::string& file_name); 45 65 const std::string& getBackgroundFilename(); … … 47 67 double getBackgroundScaling(); 48 68 void setBackgroundScaling(double scaling); 69 70 enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE }; 71 enum GuiSectSaveDest { LGF_FILE, CONF_FILE }; 72 struct SpecMapSaveOpts 73 { 74 enum Dest { GUI_SECT, NESET_SECT }; 75 enum MapNum { ONE_MAP, TWO_MAPS }; 76 }; 77 78 typedef Graph::NodeMap<double> NumericNodeMap; 79 typedef Graph::NodeMap<std::string> StringNodeMap; 80 typedef Graph::EdgeMap<double> NumericEdgeMap; 81 typedef Graph::EdgeMap<std::string> StringEdgeMap; 82 typedef Graph::NodeMap<int> NodeLabelMap; 83 typedef Graph::EdgeMap<int> EdgeLabelMap; 84 typedef XYMap<Graph::NodeMap<double> > NodeCoordMap; 85 typedef XYMap<Graph::EdgeMap<double> > ArrowCoordMap; 86 87 struct EdgeMapData 88 { 89 /// where to save the map 90 MapSaveDest save_dest; 91 /// read-only or read-write 92 bool writeable; 93 /// default value 94 MapValue default_value; 95 virtual MapValue::Type type() = 0; 96 virtual MapValue get(Edge e) = 0; 97 virtual void set(Edge e, MapValue v) = 0; 98 EdgeMapData(MapValue def_val) : 99 save_dest(GUI_SECT), 100 writeable(true), 101 default_value(def_val) 102 {} 103 }; 104 105 struct NumericEdgeMapData : public EdgeMapData 106 { 107 NumericEdgeMap map; 108 MapValue::Type type() { return MapValue::NUMERIC; } 109 MapValue get(Edge e) { return MapValue(map[e]); } 110 void set(Edge e, MapValue v) { map.set(e, static_cast<double>(v)); } 111 NumericEdgeMapData(Graph& g, double def_val) : 112 EdgeMapData(MapValue(def_val)), 113 map(g, def_val) 114 {} 115 }; 116 117 struct StringEdgeMapData : public EdgeMapData 118 { 119 StringEdgeMap map; 120 MapValue::Type type() { return MapValue::STRING; } 121 MapValue get(Edge e) { return MapValue(map[e]); } 122 void set(Edge e, MapValue v) { map.set(e, static_cast<std::string>(v)); } 123 StringEdgeMapData(Graph& g, std::string def_val) : 124 EdgeMapData(MapValue(def_val)), 125 map(g, def_val) 126 {} 127 }; 128 129 struct NodeMapData 130 { 131 /// where to save the map 132 MapSaveDest save_dest; 133 /// read-only or read-write 134 bool writeable; 135 /// default value 136 MapValue default_value; 137 virtual MapValue::Type type() = 0; 138 virtual MapValue get(Node e) = 0; 139 virtual void set(Node e, MapValue v) = 0; 140 NodeMapData(MapValue def_val) : 141 save_dest(GUI_SECT), 142 writeable(true), 143 default_value(def_val) 144 {} 145 }; 146 147 struct NumericNodeMapData : public NodeMapData 148 { 149 NumericNodeMap map; 150 MapValue::Type type() { return MapValue::NUMERIC; } 151 MapValue get(Node e) { return MapValue(map[e]); } 152 void set(Node e, MapValue v) { map.set(e, static_cast<double>(v)); } 153 NumericNodeMapData(Graph& g, double def_val) : 154 NodeMapData(MapValue(def_val)), 155 map(g, def_val) 156 {} 157 }; 158 159 struct StringNodeMapData : public NodeMapData 160 { 161 StringNodeMap map; 162 MapValue::Type type() { return MapValue::STRING; } 163 MapValue get(Node e) { return MapValue(map[e]); } 164 void set(Node e, MapValue v) { map.set(e, static_cast<std::string>(v)); } 165 StringNodeMapData(Graph& g, std::string def_val) : 166 NodeMapData(MapValue(def_val)), 167 map(g, def_val) 168 {} 169 }; 170 171 typedef std::map<std::string, NodeMapData*> NodeMapStore; 172 typedef std::map<std::string, EdgeMapData*> EdgeMapStore; 173 174 struct GUISectData 175 { 176 std::vector<std::string> main_node_map_names; 177 std::vector<std::string> main_edge_map_names; 178 179 std::vector<std::string> gui_node_map_names; 180 std::vector<std::string> gui_edge_map_names; 181 182 std::map<std::string, MapValue::Type> node_map_types; 183 std::map<std::string, MapValue::Type> edge_map_types; 184 185 std::map<std::string, std::map<int, double>* > numeric_node_maps; 186 std::map<std::string, std::map<int, std::string>* > string_node_maps; 187 188 std::map<std::string, std::map<int, double>* > numeric_edge_maps; 189 std::map<std::string, std::map<int, std::string>* > string_edge_maps; 190 191 std::map<int, XY> node_coord_map; 192 std::map<int, XY> arrow_coord_map; 193 194 SpecMapSaveOpts::Dest node_coords_save_dest; 195 SpecMapSaveOpts::MapNum node_coords_save_map_num; 196 std::string node_coords_one_map_name; 197 std::string node_coords_two_maps_1_name; 198 std::string node_coords_two_maps_2_name; 199 200 SpecMapSaveOpts::Dest arrow_coords_save_dest; 201 SpecMapSaveOpts::MapNum arrow_coords_save_map_num; 202 std::string arrow_coords_one_map_name; 203 std::string arrow_coords_two_maps_1_name; 204 std::string arrow_coords_two_maps_2_name; 205 206 ~GUISectData() 207 { 208 using std::map; 209 using std::vector; 210 using std::pair; 211 using std::string; 212 213 for (map<string, map<int, double>* >::iterator it = 214 numeric_node_maps.begin(); it != numeric_node_maps.end(); ++it) 215 { 216 delete it->second; 217 } 218 for (map<string, map<int, string>* >::iterator it = 219 string_node_maps.begin(); it != string_node_maps.end(); ++it) 220 { 221 delete it->second; 222 } 223 for (map<string, map<int, double>* >::iterator it = 224 numeric_edge_maps.begin(); it != numeric_edge_maps.end(); ++it) 225 { 226 delete it->second; 227 } 228 for (map<string, map<int, string>* >::iterator it = 229 string_edge_maps.begin(); it != string_edge_maps.end(); ++it) 230 { 231 delete it->second; 232 } 233 } 234 }; 235 public: 49 236 ///The graph for which the datas are stored. 50 237 Graph graph; 238 const Graph& getGraph(); 239 240 private: 241 GuiSectSaveDest gui_sect_save_dest; 242 243 SpecMapSaveOpts::Dest node_coords_save_dest; 244 SpecMapSaveOpts::MapNum node_coords_save_map_num; 245 SpecMapSaveOpts::Dest arrow_coords_save_dest; 246 SpecMapSaveOpts::MapNum arrow_coords_save_map_num; 247 248 NodeMapStore nodemaps; 249 EdgeMapStore edgemaps; 250 251 NodeLabelMap node_label; 252 EdgeLabelMap edge_label; 253 51 254 /// the coordinates of the nodes 52 XYMap<Graph::NodeMap<double> > coords; 255 NodeCoordMap node_coords; 256 Graph::NodeMap<double> node_coords_x; 257 Graph::NodeMap<double> node_coords_y; 258 53 259 /// the coordinates of the arrows on the edges 54 XYMap<Graph::EdgeMap<double> > arrow_pos; 260 ArrowCoordMap arrow_coords; 261 Graph::EdgeMap<double> arrow_coords_x; 262 Graph::EdgeMap<double> arrow_coords_y; 55 263 56 264 ///The content of the object has changed, update is needed. … … 60 268 std::string file_name; 61 269 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 270 // the largest node label 271 int max_node_label; 272 273 // the largest edge label 274 int max_edge_label; 275 276 std::string node_coords_one_map_name; 277 std::string node_coords_two_maps_1_name; 278 std::string node_coords_two_maps_2_name; 279 280 std::string arrow_coords_one_map_name; 281 std::string arrow_coords_two_maps_1_name; 282 std::string arrow_coords_two_maps_2_name; 283 284 public: 68 285 ///Stores the default values for the different visualization node attributes 69 286 std::vector<Graph::NodeMap<double> > default_nodemaps; … … 77 294 /// Stores the active maps for the different visualization edge attributes 78 295 std::vector< std::string > active_edgemaps; 79 80 /// Default values for the maps81 std::map< std::string, double > nodemap_default;82 83 /// Default values for the maps84 std::map< std::string, double > edgemap_default;85 86 bool arrow_pos_read_ok;87 296 88 297 protected: … … 99 308 /// std::string is the 100 309 ///name of the new map 101 sigc::signal<void, std::string > signal_node_map;310 sigc::signal<void, std::string, MapValue::Type> signal_node_map; 102 311 103 312 /// Signal emitted in the case of edgemap addition … … 105 314 /// std::string is the 106 315 ///name of the new map 107 sigc::signal<void, std::string > signal_edge_map;316 sigc::signal<void, std::string, MapValue::Type> signal_edge_map; 108 317 109 318 /// Signal emitted, when entry in \ref MapWin should be changed. … … 165 374 166 375 /// Returns the names of the edgemaps stored here. 167 std::vector<std::string> getEdgeMapList( );376 std::vector<std::string> getEdgeMapList(MapType type = ALL); 168 377 169 378 /// Returns the names of the nodemaps stored here. 170 std::vector<std::string> getNodeMapList( );379 std::vector<std::string> getNodeMapList(MapType type = ALL); 171 380 172 381 ///returns \ref signal_prop to be able to connect functions to it … … 174 383 175 384 ///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;};385 sigc::signal<void, std::string, MapValue::Type> signal_node_map_ch(){return signal_node_map;}; 177 386 178 387 ///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;};388 sigc::signal<void, std::string, MapValue::Type> signal_edge_map_ch(){return signal_edge_map;}; 180 389 181 390 ///returns \ref signal_map_win to be able to connect functions to it … … 185 394 sigc::signal<void, double, double, int> signal_design_win_ch(){return signal_design_win;}; 186 395 396 void createNodeMap(const std::string& name, MapValue::Type type, 397 MapValue def_val); 398 void createEdgeMap(const std::string& name, MapValue::Type type, 399 MapValue def_val); 400 187 401 ///returns \ref signal_background to be able to connect functions to it 188 402 sigc::signal<void> signal_background_ch(){return signal_background;}; … … 190 404 191 405 ///Adds given map to storage. 192 193 ///A name and the map itself has to be provided.194 ///\param mapname is the name of map195 ///\param nodemap is the pointer of the given nodemap196 ///\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.198 ///\todo map should be given by reference!199 ///\todo why is default value stored?200 int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);201 202 ///Adds given map to storage. A name and the map itself has to be provided.203 204 ///A name and the map itself has to be provided.205 ///\param mapname is the name of map206 ///\param edgemap is the pointer of the given edgemap207 ///\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.209 ///\todo map should be given by reference!210 int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);211 212 ///Returns how much nodemaps is stored in \ref MapStorage213 int numOfNodeMaps() {return nodemap_storage.size();};214 215 ///Returns how much edgemaps is stored in \ref MapStorage216 int numOfEdgeMaps() {return edgemap_storage.size();};217 218 ///Returns the maximum value of the given NodeMap.219 220 ///NodeMap has to be given by its name.221 ///\param name the name of map of which maximum is searched222 double maxOfNodeMap(const std::string & name);223 224 ///Returns the maximum value of the given EdgeMap.225 226 ///EdgeMap has to be given by its name.227 ///\param name the name of map of which maximum is searched228 double maxOfEdgeMap(const std::string & name);229 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 searched234 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 searched240 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 function245 ///returns an iterator pointing to the first nodemap in246 ///the storage.247 std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};248 249 ///Returns iterator pointing to the first EdgeMap in storage.250 251 ///To be able to iterate through each maps this function252 ///returns an iterator pointing to the first edgemap in253 ///the storage.254 std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};255 256 ///Returns iterator pointing after the last NodeMap in storage.257 258 ///To be able to iterate through each maps this function259 ///returns an iterator pointing to the last nodemap in the storage.260 std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};261 262 ///Returns iterator pointing after the last EdgeMap in storage.263 264 ///To be able to iterate through each maps this function265 ///returns an iterator pointing to the last edgemap in the storage.266 std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};267 406 268 407 ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. … … 286 425 void clear(); 287 426 288 void ArrowPosReadOK();289 290 427 void get_design_data(double &, double &, int &); 291 428 void set_attraction(double); … … 295 432 void redesign_data_changed(); 296 433 434 XY getNodeCoords(Node n) const; 435 void setNodeCoords(Node n, XY c); 436 XY getArrowCoords(Edge e) const; 437 void setArrowCoords(Edge e, XY c); 438 439 MapValue get(const std::string& name, Node node) const; 440 void set(const std::string& name, Node node, MapValue val); 441 MapValue get(const std::string& name, Edge edge) const; 442 void set(const std::string& name, Edge edge, MapValue val); 443 444 const std::string& getFileName() const; 445 void setFileName(const std::string& fn); 446 447 bool getModified() const; 448 void setModified(bool m = true); 449 450 Node addNode(XY); 451 Edge addEdge(Node, Node); 452 453 NumericNodeMap& getNumericNodeMap(const std::string& name); 454 StringNodeMap& getStringNodeMap(const std::string& name); 455 NumericEdgeMap& getNumericEdgeMap(const std::string& name); 456 StringEdgeMap& getStringEdgeMap(const std::string& name); 457 458 MapValueEdgeMap getEdgeMap(const std::string& name); 459 MapValueNodeMap getNodeMap(const std::string& name); 460 461 int getLabel(Node) const; 462 int getLabel(Edge) const; 463 464 GuiSectSaveDest getGUIDataSaveLocation(); 465 void setGUIDataSaveLocation(GuiSectSaveDest dest); 466 467 MapSaveDest getNodeMapSaveDest(std::string name) const; 468 MapSaveDest getEdgeMapSaveDest(std::string name) const; 469 void setNodeMapSaveDest(std::string name, MapSaveDest dest); 470 void setEdgeMapSaveDest(std::string name, MapSaveDest dest); 471 472 SpecMapSaveOpts::Dest getNodeCoordsSaveDest(); 473 SpecMapSaveOpts::Dest getArrowCoordsSaveDest(); 474 void setNodeCoordsSaveDest(SpecMapSaveOpts::Dest dest); 475 void setArrowCoordsSaveDest(SpecMapSaveOpts::Dest dest); 476 477 SpecMapSaveOpts::MapNum getNodeCoordsSaveMapNum(); 478 SpecMapSaveOpts::MapNum getArrowCoordsSaveMapNum(); 479 void setNodeCoordsSaveMapNum(SpecMapSaveOpts::MapNum num); 480 void setArrowCoordsSaveMapNum(SpecMapSaveOpts::MapNum num); 481 482 MapValue::Type getNodeMapElementType(std::string name) const; 483 MapValue::Type getEdgeMapElementType(std::string name) const; 484 485 const NodeLabelMap& getNodeLabelMap(); 486 const EdgeLabelMap& getEdgeLabelMap(); 487 488 bool nodeMapExists(std::string name); 489 bool edgeMapExists(std::string name); 490 491 std::vector<std::string> getEdgeMaps(MapType type = ALL); 492 std::vector<std::string> getNodeMaps(MapType type = ALL); 493 494 NodeCoordMap& getNodeCoordMap(); 495 ArrowCoordMap& getArrowCoordMap(); 496 497 const std::string& getNodeCoordsOneMapName(); 498 const std::string& getNodeCoordsTwoMaps1Name(); 499 const std::string& getNodeCoordsTwoMaps2Name(); 500 void setNodeCoordsOneMapName(const std::string& name); 501 void setNodeCoordsTwoMaps1Name(const std::string& name); 502 void setNodeCoordsTwoMaps2Name(const std::string& name); 503 504 const std::string& getArrowCoordsOneMapName(); 505 const std::string& getArrowCoordsTwoMaps1Name(); 506 const std::string& getArrowCoordsTwoMaps2Name(); 507 void setArrowCoordsOneMapName(const std::string& name); 508 void setArrowCoordsTwoMaps1Name(const std::string& name); 509 void setArrowCoordsTwoMaps2Name(const std::string& name); 510 511 private: 512 EdgeMapData* getEdgeMapData(std::string name) const; 513 NodeMapData* getNodeMapData(std::string name) const; 514 void readLGF( 515 const std::string& filename, 516 bool read_edge_label, 517 const std::vector<std::string>& node_map_names, 518 const std::vector<std::string>& edge_map_names, 519 const std::map<std::string, MapValue::Type>& node_map_types, 520 const std::map<std::string, MapValue::Type>& edge_map_types, 521 const std::string& node_coord_xmap_name, 522 const std::string& node_coord_ymap_name, 523 const std::string& arrow_coord_xmap_name, 524 const std::string& arrow_coord_ymap_name); 525 526 public: 297 527 void exportGraphToEPS(std::vector<bool>, std::string, std::string); 298 528 };
Note: See TracChangeset
for help on using the changeset viewer.