COIN-OR::LEMON - Graph Library

Changeset 1888:eed01ce27087 in lemon-0.x


Ignore:
Timestamp:
01/10/06 16:15:57 (19 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2463
Message:

If default value of a new map is constant, the newly created elements will get that value as well. Documentation is added to BrokenEdge?, MapStorage? and GraphDisplazCanvas? classes.

Location:
gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas.cc

    r1860 r1888  
    6060}
    6161
    62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
    63 {
    64   dummy=dummy;
     62void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
     63{
     64  //dummy=dummy;
    6565
    6666  std::string mapname=mytab.getActiveNodeMap(prop);
     
    107107}
    108108
    109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
    110 {
    111   dummy=dummy;
     109void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
     110{
     111  //dummy=dummy;
    112112
    113113  std::string mapname=mytab.getActiveEdgeMap(prop);
  • gui/graph_displayer_canvas.h

    r1860 r1888  
    1717  friend class BrokenEdge;
    1818
     19  ///Edge displayer class
     20
     21  ///This class is responsible for displaying edges in graph.
     22  ///The displayed edge is broken in the middle. The
     23  ///aim of this is to be able to indicate direction of edges
     24  ///and to be able to display more then one edges between the
     25  ///same source and target
    1926  class BrokenEdge : public Gnome::Canvas::Line
    2027  {
     28    ///The edge that the class displays.
     29
     30    ///It is needed, because some datas needed from
     31    ///graph can be accessed by this or should be sent
     32    ///as parameter, but it would be complicated
    2133    Edge edge;
     34
     35    ///Reference to the canvas, on which the graph is drawn.
     36
     37    ///It is needed, because some datas needed from
     38    ///graph can be accessed by this or should be sent
     39    ///as parameter, but it would be complicated
    2240    GraphDisplayerCanvas & gdc;
     41
     42    ///An arrow that indicates the direction of the edges
     43
     44    ///in case of directional graph direction can be indicated
     45    ///by this polygon. The polygon formulates a red arrow.
    2346    Gnome::Canvas::Polygon * arrow;
    2447
    25     ///Indicates whether the button of mouse is pressed or not
     48    ///Indicates whether the button of mouse is pressed or not at the moment.
    2649    bool isbutton;
    2750
    28     ///At this location was the mousebutton pressed.
    29     ///It helps to calculate the distance of dragging.
    30     double clicked_x, clicked_y;
    31 
    32     ///event handler for forming edges
    33     bool edgeFormerEventHandler(GdkEvent*);
     51    ///At this location was the mousebutton pressed. Horizontal component.
     52
     53    ///It helps to calculate the
     54    ///distance of dragging.
     55    double clicked_x;
     56
     57    ///At this location was the mousebutton pressed. Vertical component.
     58
     59    ///It helps to calculate the
     60    ///distance of dragging.
     61    double clicked_y;
     62
     63    ///event handler for forming broken edges
     64
     65    ///\param event the
     66    ///event to handle
     67    bool edgeFormerEventHandler(GdkEvent* event);
    3468  public:
    35     BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
     69
     70    ///Constructor of broken edge class.
     71
     72    ///\param g the group to which the edge belongs
     73    ///\param _edge the represented edge
     74    ///\param gc the canvas
     75    BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc);
     76
     77    ///Destructor of broken edge class
     78
     79    ///Frees up
     80    ///reserved memory
    3681    ~BrokenEdge();
     82
     83    ///The function that draws the edge based on collected data
    3784    void draw();
    3885  };
     86
     87  ///Type of canvas, on which the graph is drawn
    3988  typedef Gnome::Canvas::CanvasAA Parent;
    4089
    4190public:
    42   GraphDisplayerCanvas(NoteBookTab &);
     91  ///Constructor
     92
     93  ///\param nbt the tab of the window, in which the graph is displayed
     94  GraphDisplayerCanvas(NoteBookTab & nbt);
     95
     96  ///destructor of the class
    4397  virtual ~GraphDisplayerCanvas();
    4498
    45   ///Changes the linewidth attribute according to the given map.
    46   ///\param mapname is the name of the map which contains the new values
    47   int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
    48   int resetEdgeWidth (Edge new_item=INVALID);
    49 
    50   ///Changes the linecolor attribute according to the given map.
    51   ///\param mapname is the name of the map which contains the new values
    52   int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
    53   int resetEdgeColor (Edge new_item=INVALID);
    54 
    55   ///Changes the text of line attribute according to the given map.
    56   ///\param mapname is the name of the map which contains the new values
    57   int changeEdgeText (std::string mapname, Edge new_item=INVALID);
    58   int resetEdgeText (Edge new_item=INVALID);
    59 
    60   ///Changes the linewidth attribute according to the given map.
    61   ///\param mapname is the name of the map which contains the new values
    62   int changeNodeRadius (std::string mapname, Node new_item=INVALID);
    63   int resetNodeRadius (Node new_item=INVALID);
    64 
    65   ///Changes the linecolor attribute according to the given map.
    66   ///\param mapname is the name of the map which contains the new values
    67   int changeNodeColor (std::string mapname, Node new_item=INVALID);
    68   int resetNodeColor (Node new_item=INVALID);
    69 
    70   ///Changes the text of line attribute according to the given map.
    71   ///\param mapname is the name of the map which contains the new values
    72   int changeNodeText (std::string mapname, Node new_item=INVALID);
    73   int resetNodeText (Node new_item=INVALID);
    74 
    75   void propertyChange(bool, int);
    76   void propertyUpdate(Edge, int, int dummy=0);
    77   void propertyUpdate(Node, int, int dummy=0);
    78 
     99  ///Changes the width of edge(s) according to the given map.
     100
     101  ///\param mapname is the name of the map which contains the values to be set
     102  ///\param edge if it is given, only the width of the given edge will be set, instead of all of them.
     103  int changeEdgeWidth (std::string mapname, Edge edge=INVALID);
     104
     105  ///Resets width of edge(s) to the default value
     106
     107  ///\param edge if it is given, only the width of the
     108  ///given edge will be reset, instead of all of them.
     109  int resetEdgeWidth (Edge edge=INVALID);
     110
     111  ///Changes the color of edge(s) according to the given map.
     112
     113  ///\param mapname is the name of the map which contains the new values
     114  ///\param edge if it is given, only the color of the given edge will be set, instead of all of them.
     115  int changeEdgeColor (std::string mapname, Edge edge=INVALID);
     116
     117  ///Resets color of edge(s) to the default value
     118
     119  ///\param edge if it is given, only the color of the
     120  ///given edge will be reset, instead of all of them.
     121  int resetEdgeColor (Edge edge=INVALID);
     122
     123  ///Changes the label of edge(s) according to the given map.
     124
     125  ///\param mapname is the name of the map which contains the new values
     126  ///\param edge if it is given, only the label of the given edge will be set, instead of all of them.
     127  int changeEdgeText (std::string mapname, Edge edge=INVALID);
     128
     129  ///Resets label of edge(s) to the default value
     130
     131  ///\param edge if it is given, only the color of the
     132  ///given edge will be reset, instead of all of them.
     133  int resetEdgeText (Edge edge=INVALID);
     134
     135  ///Changes the radius of node(s) according to the given map.
     136
     137  ///\param mapname is the name of the map which contains the new values
     138  ///\param node if it is given, only the radius of the given node will be set, instead of all of them.
     139  int changeNodeRadius (std::string mapname, Node node=INVALID);
     140
     141  ///Resets radius of node(s) to the default value
     142
     143  ///\param node if it is given, only the radius of the
     144  ///given node will be reset, instead of all of them.
     145  int resetNodeRadius (Node node=INVALID);
     146
     147  ///Changes the color of node(s) according to the given map.
     148
     149  ///\param mapname is the name of the map which contains the new values
     150  ///\param node if it is given, only the color of the given node will be set, instead of all of them.
     151  int changeNodeColor (std::string mapname, Node node=INVALID);
     152
     153  ///Resets color of node(s) to the default value
     154
     155  ///\param node if it is given, only the color of the
     156  ///given node will be reset, instead of all of them.
     157  int resetNodeColor (Node node=INVALID);
     158
     159  ///Changes the label of node(s) according to the given map.
     160
     161  ///\param mapname is the name of the map which contains the new values
     162  ///\param node if it is given, only the label of the given node will be set, instead of all of them.
     163  int changeNodeText (std::string mapname, Node node=INVALID);
     164
     165  ///Resets label of node(s) to the default value
     166
     167  ///\param node if it is given, only the label of the
     168  ///given node will be reset, instead of all of them.
     169  int resetNodeText (Node node=INVALID);
     170
     171  ///This function is called, when any of the displayed attributes have to be updated, or changed
     172
     173  ///\param itisedge if true, edge property has to be changed, else node property
     174  ///\param prop the id of property that has to changed or updated
     175  void propertyChange(bool itisedge, int prop);
     176
     177  ///updates the given property
     178
     179  ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them
     180  ///\param prop the property to update
     181  void propertyUpdate(Edge edge, int prop);
     182
     183  ///updates the given property
     184
     185  ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them
     186  ///\param prop the property to update
     187  void propertyUpdate(Node node, int prop);
     188
     189  ///updates all the property for the given edge
    79190  void propertyUpdate(Edge);
     191
     192  ///updates all the property for the given node
    80193  void propertyUpdate(Node);
    81194
     
    96209protected:
    97210
    98   //maximizing, minimizing, restoring window, etc. 
     211  //maximizing, minimizing, restoring window, etc.
    99212  virtual bool on_expose_event(GdkEventExpose *);
    100213
     
    128241  ///Moves the text to new place
    129242  void textReposition(xy<double>);
     243
    130244  ///Activates an edge belonging to a BrokenEdge
    131   ///
     245
    132246  ///After we have activated an edge this way,
    133247  ///the GDC object will know, which edge is under forming
    134   ///therefore it can redraw the necessarz elementy on the canvas,
     248  ///therefore it can redraw the necessary elements on the canvas,
    135249  ///for example the text belonging to the \ref BrokenEdge can be
    136250  ///redrawn (\ref textReposition).
     
    138252
    139253public:
    140   ///\return the actual tool in hand
     254
     255  ///Returns the actual tool in hand
    141256  int getActualTool();
    142257
     258  ///draws the graph
     259
     260  ///Called when opening a file.
    143261  void drawGraph();
     262
     263  ///Clears the canvas
     264
     265  ///It achieves this by deleting all data
     266  ///structure used to help handle the displayed graph.
    144267  void clear();
    145268
    146269  ///creates a new Nodemap
    147   int addNewNodeMap(double,std::string);
     270
     271  ///\param init initial value of the map
     272  ///\param mapname name of new map
     273  int addNewNodeMap(double init,std::string mapname);
    148274  ///creates a new Edgemap
    149   int addNewEdgeMap(double,std::string);
     275
     276  ///\param init initial value of the map
     277  ///\param mapname name of new map
     278  int addNewEdgeMap(double init,std::string mapname);
    150279
    151280private:
     
    184313
    185314  ///Remembers which Gnome::Canvas::Item was pressed.
    186   ///this variable is needed, because
    187   ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
    188   ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
    189   Gnome::Canvas::Item * active_item, * target_item;
     315
     316  ///this variable is needed, to work on it after selection
     317  Gnome::Canvas::Item * active_item;
     318
     319  ///Remembers which Gnome::Canvas::Item was pressed.
     320
     321  ///this variable is used at edge creation, it will
     322  ///be the secondly selected node. No local variable
     323  ///can be used for this purpose inside the function,
     324  ///because the node selected by button press, and
     325  ///the edge is created by button release. Both of
     326  ///them is different function call.
     327  Gnome::Canvas::Item * target_item;
     328
     329  ///selected node (for any editing)
    190330  Node active_node;
     331
     332  ///selected edge (for any editing)
    191333  Edge active_edge;
     334
     335  ///the edge that is selected by clicking on the red arrow in the middle of it
     336
     337  ///This edge is stored only for the purpose of reshape it.
     338  ///That is why it is selected in a different manner.
    192339  Edge forming_edge;
    193340
    194   std::string nodemap_to_edit, edgemap_to_edit;
     341  ///Map displayed by label can be edited.
     342  std::string nodemap_to_edit;
     343
     344  ///Map displayed by label can be edited.
     345  std::string edgemap_to_edit;
    195346
    196347  static const int zoom_step = 5;
     
    198349private:
    199350
    200   ///reference to the parent window
     351  ///reference to the container, in which the canvas is
    201352  NoteBookTab & mytab;
    202353
  • gui/mapstorage.cc

    r1881 r1888  
    5252}
    5353
    54 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0)
    55 {
     54int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
     55{
     56  std::cout << default_value << std::endl;
    5657  if( nodemap_storage.find(name) == nodemap_storage.end() )
    5758    {
     
    123124}
    124125
    125 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)
     126int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
    126127{
    127128  if( edgemap_storage.find(name) == edgemap_storage.end() )
  • gui/mapstorage.h

    r1881 r1888  
    99#include "xymap.h"
    1010#include <libgnomecanvasmm.h>
     11
     12///class MapStorage handles NodeMaps and EdgeMaps.
    1113
    1214///Class MapStorage is responsible for storing
     
    2325public:
    2426
     27  ///The graph for which the datas are stored.
    2528  Graph graph;
    2629  /// the coordinates of the nodes
     
    2932  XYMap<Graph::EdgeMap<double> > arrow_pos;
    3033
     34  ///The content of the object has changed, update is needed.
    3135  bool modified;
     36
     37  ///Name of file loaded in object.
    3238  std::string file_name;
    3339
     
    3844  std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
    3945
    40   //Stores the default values for the different visualization node attributes
     46  ///Stores the default values for the different visualization node attributes
    4147  std::vector<Graph::NodeMap<double> > default_nodemaps;
    4248
    43   //Stores the default values for the different visualization edge attributes
     49  ///Stores the default values for the different visualization edge attributes
    4450  std::vector<Graph::EdgeMap<double> > default_edgemaps;
    4551
    46   //Stores the active maps for the different visualization node attributes
     52  ///Stores the active maps for the different visualization node attributes
    4753  std::vector< std::string > active_nodemaps;
    4854
    49   //Stores the active maps for the different visualization edge attributes
     55  /// Stores the active maps for the different visualization edge attributes
    5056  std::vector< std::string > active_edgemaps;
    5157
    52   // Default values for the maps
     58  /// Default values for the maps
    5359  std::map< std::string, double > nodemap_default;
    5460
    55   // Default values for the maps
     61  /// Default values for the maps
    5662  std::map< std::string, double > edgemap_default;
    5763
     
    5965
    6066protected:
     67  /// type of the signal emitted if the visualization of the maps might have to be updated.
     68
     69  /// bool shows us whether the changed map is edge or nodemap.
     70  /// int tells us the refreshed property
    6171  typedef sigc::signal<void, bool, int> Signal_Prop;
     72
     73  /// Signal emitted on any change made on map values
    6274  Signal_Prop signal_prop;
     75
     76  /// Signal emitted in the case of nodemap addition
     77
     78  /// std::string is the
     79  ///name of the new map
    6380  sigc::signal<void, std::string> signal_node_map;
     81
     82  /// Signal emitted in the case of edgemap addition
     83
     84  /// std::string is the
     85  ///name of the new map
    6486  sigc::signal<void, std::string> signal_edge_map;
    6587
    6688public:
    67   ///Constructor of MapStorage. Expects the Graph of
    68   ///which maps will be stored in it.
     89  ///Constructor of MapStorage.
     90
    6991  ///Its all activity is initializing default values
    70   ///for different visualization attributes
    71   ///
    72   ///\param graph is the graph for which the maps are stored in this object.
     92  ///for different visualization attributes.
    7393  MapStorage();
    7494
     95  ///Destructor of MapStorage
     96
     97  ///Maps stored here are created with new. Destructor
     98  ///deletes them to free up the reserved memory.
    7599  ~MapStorage();
    76100
    77   void changeActiveMap(bool, int, std::string);
    78 
    79   std::string getActiveEdgeMap(int);
    80   std::string getActiveNodeMap(int);
    81 
     101  /// Registrates if the shown map by any attribute has changed to another.
     102
     103  ///It handles the \ref active_edgemaps and
     104  ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
     105  ///know the interested objects that the visible map of a certain
     106  ///attribute has changed.
     107  ///\param itisedge edgemap or nodemap has changed
     108  ///\param prop the property of which the map is changed
     109  ///\param mapname the visible map
     110  void changeActiveMap(bool itisedge , int prop , std::string mapname);
     111
     112  /// Returns the active edgemap shown by a visualization property.
     113
     114  /// \param prop is the property
     115  ///that shows the requested map.
     116  std::string getActiveEdgeMap(int prop);
     117
     118  /// Returns the active nodemap shown by a visualization property.
     119
     120  /// \param prop is the property
     121  ///that shows the requested map.
     122  std::string getActiveNodeMap(int prop);
     123
     124  /// Returns the names of the edgemaps stored here.
    82125  std::vector<std::string> getEdgeMapList();
     126
     127  /// Returns the names of the nodemaps stored here.
    83128  std::vector<std::string> getNodeMapList();
    84129
     130  ///returns \ref signal_prop to be able to connect functions to it
    85131  Signal_Prop signal_prop_ch();
    86132
     133  ///returns \ref signal_node_map to be able to connect functions to it
    87134  sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
     135
     136  ///returns \ref signal_edge_map to be able to connect functions to it
    88137  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
    89138
     139  ///Adds given map to storage.
     140
     141  ///A name and the map itself has to be provided.
     142  ///\param mapname is the name of map
     143  ///\param nodemap is the pointer of the given nodemap
     144  ///\param def the default value of the map. If not given, it will be 0.
     145  ///If new edge is added to graph the value of it in the map will be this.
     146  ///\todo map should be given by reference!
     147  ///\todo why is default value stored?
     148  int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
     149
    90150  ///Adds given map to storage. A name and the map itself has to be provided.
    91   ///\param name is the name of map
    92   ///\nodemap is the pointer of the given nodemap
     151
     152  ///A name and the map itself has to be provided.
     153  ///\param mapname is the name of map
     154  ///\param edgemap is the pointer of the given edgemap
     155  ///\param def the default value of the map. If not given, it will be 0.
     156  ///If new edge is added to graph the value of it in the map will be this.
    93157  ///\todo map should be given by reference!
    94   int addNodeMap(const std::string &,Graph::NodeMap<double> *, double);
    95 
    96   ///Adds given map to storage. A name and the map itself has to be provided.
    97   ///\param name is the name of map
    98   ///\edgemap is the pointer of the given edgemap
    99   ///\todo map should be given by reference!
    100   int addEdgeMap(const std::string &,Graph::EdgeMap<double> *, double);
     158  int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
    101159
    102160  ///Returns how much nodemaps is stored in \ref MapStorage
     
    106164  int numOfEdgeMaps() {return edgemap_storage.size();};
    107165
    108   ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
    109   ///\param name is the name of map of which maximum is searched
    110   double maxOfNodeMap(const std::string &);
    111 
    112   ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
    113   ///\param name is the name of map of which maximum is searched
    114   double maxOfEdgeMap(const std::string &);
    115 
    116   ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
    117   ///\param name is the name of map of which minimum is searched
    118   double minOfNodeMap(const std::string &);
    119 
    120   ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
    121   ///\param name is the name of map of which minimum is searched
    122   double minOfEdgeMap(const std::string &);
    123 
    124   ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
     166  ///Returns the maximum value of the given NodeMap.
     167
     168  ///NodeMap has to be given by its name.
     169  ///\param name the name of map of which maximum is searched
     170  double maxOfNodeMap(const std::string & name);
     171
     172  ///Returns the maximum value of the given EdgeMap.
     173
     174  ///EdgeMap has to be given by its name.
     175  ///\param name the name of map of which maximum is searched
     176  double maxOfEdgeMap(const std::string & name);
     177
     178  ///Returns the minimum value of the given NodeMap.
     179
     180  ///NodeMap has to be given by its name.
     181  ///\param name the name of map of which minimum is searched
     182  double minOfNodeMap(const std::string & name);
     183
     184  ///Returns the minimum value of the given EdgeMap.
     185
     186  ///EdgeMap has to be given by its name.
     187  ///\param name the name of map of which minimum is searched
     188  double minOfEdgeMap(const std::string & name);
     189
     190  ///Returns iterator pointing to the first NodeMap in storage.
     191
     192  ///To be able to iterate through each maps this function
     193  ///returns an iterator pointing to the first nodemap in
     194  ///the storage.
    125195  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
    126196
    127   ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
     197  ///Returns iterator pointing to the first EdgeMap in storage.
     198
     199  ///To be able to iterate through each maps this function
     200  ///returns an iterator pointing to the first edgemap in
     201  ///the storage.
    128202  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
    129203
    130   ///To be able to iterate through each maps this function returns an iterator pointing to the last nodemap in the storage.
     204  ///Returns iterator pointing after the last NodeMap in storage.
     205
     206  ///To be able to iterate through each maps this function
     207  ///returns an iterator pointing to the last nodemap in the storage.
    131208  std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
    132209
    133   ///To be able to iterate through each maps this function returns an iterator pointing to the last edgemap in the storage.
     210  ///Returns iterator pointing after the last EdgeMap in storage.
     211
     212  ///To be able to iterate through each maps this function
     213  ///returns an iterator pointing to the last edgemap in the storage.
    134214  std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
    135215
    136   void mapChanged(bool, std::string);
    137 
     216  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
     217
     218  ///If values in a map have changed, this function checks, whether it is displayed.
     219  ///This check means searching the given mapname between active maps
     220  ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
     221  ///it emits a signal with the property, where the gotten mapname was found. One signal
     222  ///is emitted for each property displaying the given map.
     223  ///\param itisedge whether the map an edgemap or nodemap
     224  ///\param mapname name of map to visualize
     225  void mapChanged(bool itisedge, std::string mapname);
     226
     227  ///Read datas from the given filename.
    138228  int readFromFile(const std::string &);
     229
     230  ///Save datas to the given filename.
    139231  void writeToFile(const std::string &);
    140232
     233  ///Deletes all datastructures stored here.
    141234  void clear();
    142235
  • gui/new_map_win.cc

    r1887 r1888  
    7373      //get and formulate text
    7474      std::string def_val_str=default_value.get_text();
    75       std::string polishform=string2Polishform(def_val_str,edge.get_active());
     75
     76      bool only_nums=true;
     77      for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
     78        {
     79          if( def_val_str[i]<'0' || def_val_str[i]>'9' )
     80            {
     81              only_nums=false;
     82            }
     83        }
     84      std::string polishform;
     85
     86      if(only_nums)
     87        {
     88          def_val=atof(def_val_str.c_str());
     89        }
     90      else
     91        {
     92          polishform=string2Polishform(def_val_str,edge.get_active());
     93        }
    7694
    7795      //get name of text
    7896      std::string mapname=name.get_text();
    79 
    80       if(!mapname.empty()&&!polishform.empty())
     97     
     98      if(!mapname.empty()&&(!polishform.empty()||only_nums))
    8199        {
    82100          int abortion=0;
     
    84102            {
    85103              //create the new map
    86               Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph);
    87 
    88               std::stack<double> polishstack;
    89  
    90               for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    91                 {
    92                   for(int i=0;i<(int)polishform.size();i++)
     104              Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
     105             
     106              if(!only_nums)
     107                {
     108                  std::stack<double> polishstack;
     109                 
     110                  for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    93111                    {
    94                       double op1, op2;
    95                       bool operation=true;
    96                       switch(polishform[i])
     112                      for(int i=0;i<(int)polishform.size();i++)
    97113                        {
    98                         case '+':
    99                         case '-':
    100                         case '/':
    101                         case '*':
    102                           op1=polishstack.top();
    103                           polishstack.pop();
    104                           op2=polishstack.top();
    105                           polishstack.pop();
    106                           break;
    107                         default:
    108                           //substitute variable
    109                           std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
    110                           bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
    111                           if(itisvar)
    112                             {
    113                               polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    114                             }
    115                           else
    116                             {
    117                               polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    118                             }
    119                           operation=false;
    120                           break;
    121                         }
    122                       if(operation)
    123                         {
    124                           double res;
     114                          double op1=0, op2=0;
     115                          bool operation=true;
    125116                          switch(polishform[i])
    126117                            {
    127118                            case '+':
    128                               res=op1+op2;
    129                               break;
    130119                            case '-':
    131                               res=op2-op1;
    132                               break;
    133120                            case '/':
    134                               res=op2/op1;
    135                               break;
    136121                            case '*':
    137                               res=op1*op2;
     122                              op1=polishstack.top();
     123                              polishstack.pop();
     124                              op2=polishstack.top();
     125                              polishstack.pop();
    138126                              break;
    139127                            default:
    140                               std::cout << "How could we get here?" << std::endl;
     128                              //substitute variable
     129                              std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
     130                              bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
     131                              if(itisvar)
     132                                {
     133                                  polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     134                                }
     135                              else
     136                                {
     137                                  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     138                                }
     139                              operation=false;
    141140                              break;
    142141                            }
    143                           polishstack.push(res);
    144                         }
    145                     }
    146                   (*emptr)[k]=polishstack.top();
    147                 }
     142                          if(operation)
     143                            {
     144                              double res;
     145                              switch(polishform[i])
     146                                {
     147                                case '+':
     148                                  res=op1+op2;
     149                                  break;
     150                                case '-':
     151                                  res=op2-op1;
     152                                  break;
     153                                case '/':
     154                                  res=op2/op1;
     155                                  break;
     156                                case '*':
     157                                  res=op1*op2;
     158                                  break;
     159                                default:
     160                                  std::cout << "How could we get here?" << std::endl;
     161                                  break;
     162                                }
     163                              polishstack.push(res);
     164                            }
     165                        }//foreach letter in polishform
     166                      (*emptr)[k]=polishstack.top();
     167                    }//foreach edge
     168                }//!only_nums
    148169
    149170              //if addition was not successful addEdgeMap returns one.
     
    164185            {
    165186              //create the new map
    166               Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph);
    167 
    168               std::stack<double> polishstack;
     187              Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
     188
     189              if(!only_nums)
     190                {
     191                  std::stack<double> polishstack;
    169192 
    170               for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    171                 {
    172                   for(int i=0;i<(int)polishform.size();i++)
     193                  for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
    173194                    {
    174                       double op1, op2;
    175                       bool operation=true;
    176                       switch(polishform[i])
     195                      for(int i=0;i<(int)polishform.size();i++)
    177196                        {
    178                         case '+':
    179                         case '-':
    180                         case '/':
    181                         case '*':
    182                           op1=polishstack.top();
    183                           polishstack.pop();
    184                           op2=polishstack.top();
    185                           polishstack.pop();
    186                           break;
    187                         default:
    188                           std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
    189                           bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
    190                           if(itisvar)
    191                             {
    192                               polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    193                             }
    194                           else
    195                             {
    196                               polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    197                             }
    198                           operation=false;
    199                           break;
    200                         }
    201                       if(operation)
    202                         {
    203                           double res;
     197                          double op1=0, op2=0;
     198                          bool operation=true;
    204199                          switch(polishform[i])
    205200                            {
    206201                            case '+':
    207                               res=op1+op2;
    208                               break;
    209202                            case '-':
    210                               res=op2-op1;
    211                               break;
    212203                            case '/':
    213                               res=op2/op1;
    214                               break;
    215204                            case '*':
    216                               res=op1*op2;
     205                              op1=polishstack.top();
     206                              polishstack.pop();
     207                              op2=polishstack.top();
     208                              polishstack.pop();
    217209                              break;
    218210                            default:
    219                               std::cout << "How could we get here?" << std::endl;
     211                              std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
     212                              bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
     213                              if(itisvar)
     214                                {
     215                                  polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     216                                }
     217                              else
     218                                {
     219                                  polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     220                                }
     221                              operation=false;
    220222                              break;
    221223                            }
    222                           polishstack.push(res);
     224                          if(operation)
     225                            {
     226                              double res;
     227                              switch(polishform[i])
     228                                {
     229                                case '+':
     230                                  res=op1+op2;
     231                                  break;
     232                                case '-':
     233                                  res=op2-op1;
     234                                  break;
     235                                case '/':
     236                                  res=op2/op1;
     237                                  break;
     238                                case '*':
     239                                  res=op1*op2;
     240                                  break;
     241                                default:
     242                                  std::cout << "How could we get here?" << std::endl;
     243                                  break;
     244                                }
     245                              polishstack.push(res);
     246                            }
    223247                        }
     248                      (*emptr)[k]=polishstack.top();
    224249                    }
    225                   (*emptr)[k]=polishstack.top();
    226                 }
    227 
     250                }
    228251              //if addition was not successful addNodeMap returns one.
    229252              //cause can be that there is already a map named like the new one
Note: See TracChangeset for help on using the changeset viewer.