COIN-OR::LEMON - Graph Library

Changeset 201:879e47e5b731 in glemon-0.x for mapstorage.h


Ignore:
Timestamp:
01/02/08 22:03:09 (13 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
Message:

Merge branches/akos to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mapstorage.h

    r198 r201  
    2020#define MAPSTORAGE_H
    2121
    22 #include <all_include.h>
    23 #include <xymap.h>
     22class Mapstorage;
     23
     24#include <vector>
     25#include <map>
     26#include <string>
     27#include "all_include.h"
     28#include "xymap.h"
    2429#include <libgnomecanvasmm.h>
     30#include "map_value.h"
     31#include "map_value_map.h"
    2532
    2633///class MapStorage handles NodeMaps and EdgeMaps.
     
    4249  double background_scaling;
    4350public:
     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
    4464  void setBackground(const std::string& file_name);
    4565  const std::string& getBackgroundFilename();
     
    4767  double getBackgroundScaling();
    4868  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  };
     235public:
    49236  ///The graph for which the datas are stored.
    50237  Graph graph;
     238  const Graph& getGraph();
     239
     240private:
     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
    51254  /// 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
    53259  /// 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;
    55263
    56264  ///The content of the object has changed, update is needed.
     
    60268  std::string file_name;
    61269
    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
     284public:
    68285  ///Stores the default values for the different visualization node attributes
    69286  std::vector<Graph::NodeMap<double> > default_nodemaps;
     
    77294  /// Stores the active maps for the different visualization edge attributes
    78295  std::vector< std::string > active_edgemaps;
    79 
    80   /// Default values for the maps
    81   std::map< std::string, double > nodemap_default;
    82 
    83   /// Default values for the maps
    84   std::map< std::string, double > edgemap_default;
    85 
    86   bool arrow_pos_read_ok;
    87296
    88297protected:
     
    99308  /// std::string is the
    100309  ///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;
    102311
    103312  /// Signal emitted in the case of edgemap addition
     
    105314  /// std::string is the
    106315  ///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;
    108317
    109318  /// Signal emitted, when entry in \ref MapWin should be changed.
     
    165374
    166375  /// Returns the names of the edgemaps stored here.
    167   std::vector<std::string> getEdgeMapList();
     376  std::vector<std::string> getEdgeMapList(MapType type = ALL);
    168377
    169378  /// Returns the names of the nodemaps stored here.
    170   std::vector<std::string> getNodeMapList();
     379  std::vector<std::string> getNodeMapList(MapType type = ALL);
    171380
    172381  ///returns \ref signal_prop to be able to connect functions to it
     
    174383
    175384  ///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;};
    177386
    178387  ///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;};
    180389
    181390  ///returns \ref signal_map_win to be able to connect functions to it
     
    185394  sigc::signal<void, double, double, int> signal_design_win_ch(){return signal_design_win;};
    186395
     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
    187401  ///returns \ref signal_background to be able to connect functions to it
    188402  sigc::signal<void> signal_background_ch(){return signal_background;};
     
    190404
    191405  ///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.
    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 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.
    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 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 
    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 searched
    222   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 searched
    228   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 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.
    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 function
    252   ///returns an iterator pointing to the first edgemap in
    253   ///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 function
    259   ///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 function
    265   ///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();};
    267406
    268407  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
     
    286425  void clear();
    287426
    288   void ArrowPosReadOK();
    289 
    290427  void get_design_data(double &, double &, int &);
    291428  void set_attraction(double);
     
    295432  void redesign_data_changed();
    296433
     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
     511private:
     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
     526public:
    297527  void exportGraphToEPS(std::vector<bool>, std::string, std::string);
    298528};
Note: See TracChangeset for help on using the changeset viewer.