Changeset 1888:eed01ce27087 in lemon-0.x
- Timestamp:
- 01/10/06 16:15:57 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2463
- Location:
- gui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/graph_displayer_canvas.cc
r1860 r1888 60 60 } 61 61 62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop , int dummy)63 { 64 dummy=dummy;62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop) 63 { 64 //dummy=dummy; 65 65 66 66 std::string mapname=mytab.getActiveNodeMap(prop); … … 107 107 } 108 108 109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop , int dummy)110 { 111 dummy=dummy;109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop) 110 { 111 //dummy=dummy; 112 112 113 113 std::string mapname=mytab.getActiveEdgeMap(prop); -
gui/graph_displayer_canvas.h
r1860 r1888 17 17 friend class BrokenEdge; 18 18 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 19 26 class BrokenEdge : public Gnome::Canvas::Line 20 27 { 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 21 33 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 22 40 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. 23 46 Gnome::Canvas::Polygon * arrow; 24 47 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. 26 49 bool isbutton; 27 50 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); 34 68 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 36 81 ~BrokenEdge(); 82 83 ///The function that draws the edge based on collected data 37 84 void draw(); 38 85 }; 86 87 ///Type of canvas, on which the graph is drawn 39 88 typedef Gnome::Canvas::CanvasAA Parent; 40 89 41 90 public: 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 43 97 virtual ~GraphDisplayerCanvas(); 44 98 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 79 190 void propertyUpdate(Edge); 191 192 ///updates all the property for the given node 80 193 void propertyUpdate(Node); 81 194 … … 96 209 protected: 97 210 98 //maximizing, minimizing, restoring window, etc. 211 //maximizing, minimizing, restoring window, etc. 99 212 virtual bool on_expose_event(GdkEventExpose *); 100 213 … … 128 241 ///Moves the text to new place 129 242 void textReposition(xy<double>); 243 130 244 ///Activates an edge belonging to a BrokenEdge 131 /// 245 132 246 ///After we have activated an edge this way, 133 247 ///the GDC object will know, which edge is under forming 134 ///therefore it can redraw the necessar z elementyon the canvas,248 ///therefore it can redraw the necessary elements on the canvas, 135 249 ///for example the text belonging to the \ref BrokenEdge can be 136 250 ///redrawn (\ref textReposition). … … 138 252 139 253 public: 140 ///\return the actual tool in hand 254 255 ///Returns the actual tool in hand 141 256 int getActualTool(); 142 257 258 ///draws the graph 259 260 ///Called when opening a file. 143 261 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. 144 267 void clear(); 145 268 146 269 ///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); 148 274 ///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); 150 279 151 280 private: … … 184 313 185 314 ///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) 190 330 Node active_node; 331 332 ///selected edge (for any editing) 191 333 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. 192 339 Edge forming_edge; 193 340 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; 195 346 196 347 static const int zoom_step = 5; … … 198 349 private: 199 350 200 ///reference to the parent window351 ///reference to the container, in which the canvas is 201 352 NoteBookTab & mytab; 202 353 -
gui/mapstorage.cc
r1881 r1888 52 52 } 53 53 54 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0) 55 { 54 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value) 55 { 56 std::cout << default_value << std::endl; 56 57 if( nodemap_storage.find(name) == nodemap_storage.end() ) 57 58 { … … 123 124 } 124 125 125 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)126 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value) 126 127 { 127 128 if( edgemap_storage.find(name) == edgemap_storage.end() ) -
gui/mapstorage.h
r1881 r1888 9 9 #include "xymap.h" 10 10 #include <libgnomecanvasmm.h> 11 12 ///class MapStorage handles NodeMaps and EdgeMaps. 11 13 12 14 ///Class MapStorage is responsible for storing … … 23 25 public: 24 26 27 ///The graph for which the datas are stored. 25 28 Graph graph; 26 29 /// the coordinates of the nodes … … 29 32 XYMap<Graph::EdgeMap<double> > arrow_pos; 30 33 34 ///The content of the object has changed, update is needed. 31 35 bool modified; 36 37 ///Name of file loaded in object. 32 38 std::string file_name; 33 39 … … 38 44 std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage; 39 45 40 // Stores the default values for the different visualization node attributes46 ///Stores the default values for the different visualization node attributes 41 47 std::vector<Graph::NodeMap<double> > default_nodemaps; 42 48 43 // Stores the default values for the different visualization edge attributes49 ///Stores the default values for the different visualization edge attributes 44 50 std::vector<Graph::EdgeMap<double> > default_edgemaps; 45 51 46 // Stores the active maps for the different visualization node attributes52 ///Stores the active maps for the different visualization node attributes 47 53 std::vector< std::string > active_nodemaps; 48 54 49 // Stores the active maps for the different visualization edge attributes55 /// Stores the active maps for the different visualization edge attributes 50 56 std::vector< std::string > active_edgemaps; 51 57 52 // Default values for the maps58 /// Default values for the maps 53 59 std::map< std::string, double > nodemap_default; 54 60 55 // Default values for the maps61 /// Default values for the maps 56 62 std::map< std::string, double > edgemap_default; 57 63 … … 59 65 60 66 protected: 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 61 71 typedef sigc::signal<void, bool, int> Signal_Prop; 72 73 /// Signal emitted on any change made on map values 62 74 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 63 80 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 64 86 sigc::signal<void, std::string> signal_edge_map; 65 87 66 88 public: 67 ///Constructor of MapStorage. Expects the Graph of68 ///which maps will be stored in it. 89 ///Constructor of MapStorage. 90 69 91 ///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. 73 93 MapStorage(); 74 94 95 ///Destructor of MapStorage 96 97 ///Maps stored here are created with new. Destructor 98 ///deletes them to free up the reserved memory. 75 99 ~MapStorage(); 76 100 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. 82 125 std::vector<std::string> getEdgeMapList(); 126 127 /// Returns the names of the nodemaps stored here. 83 128 std::vector<std::string> getNodeMapList(); 84 129 130 ///returns \ref signal_prop to be able to connect functions to it 85 131 Signal_Prop signal_prop_ch(); 86 132 133 ///returns \ref signal_node_map to be able to connect functions to it 87 134 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 88 137 sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;}; 89 138 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 90 150 ///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. 93 157 ///\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); 101 159 102 160 ///Returns how much nodemaps is stored in \ref MapStorage … … 106 164 int numOfEdgeMaps() {return edgemap_storage.size();}; 107 165 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. 125 195 std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; 126 196 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. 128 202 std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; 129 203 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. 131 208 std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();}; 132 209 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. 134 214 std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; 135 215 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. 138 228 int readFromFile(const std::string &); 229 230 ///Save datas to the given filename. 139 231 void writeToFile(const std::string &); 140 232 233 ///Deletes all datastructures stored here. 141 234 void clear(); 142 235 -
gui/new_map_win.cc
r1887 r1888 73 73 //get and formulate text 74 74 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 } 76 94 77 95 //get name of text 78 96 std::string mapname=name.get_text(); 79 80 if(!mapname.empty()&& !polishform.empty())97 98 if(!mapname.empty()&&(!polishform.empty()||only_nums)) 81 99 { 82 100 int abortion=0; … … 84 102 { 85 103 //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) 93 111 { 94 double op1, op2; 95 bool operation=true; 96 switch(polishform[i]) 112 for(int i=0;i<(int)polishform.size();i++) 97 113 { 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; 125 116 switch(polishform[i]) 126 117 { 127 118 case '+': 128 res=op1+op2;129 break;130 119 case '-': 131 res=op2-op1;132 break;133 120 case '/': 134 res=op2/op1;135 break;136 121 case '*': 137 res=op1*op2; 122 op1=polishstack.top(); 123 polishstack.pop(); 124 op2=polishstack.top(); 125 polishstack.pop(); 138 126 break; 139 127 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; 141 140 break; 142 141 } 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 148 169 149 170 //if addition was not successful addEdgeMap returns one. … … 164 185 { 165 186 //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; 169 192 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) 173 194 { 174 double op1, op2; 175 bool operation=true; 176 switch(polishform[i]) 195 for(int i=0;i<(int)polishform.size();i++) 177 196 { 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; 204 199 switch(polishform[i]) 205 200 { 206 201 case '+': 207 res=op1+op2;208 break;209 202 case '-': 210 res=op2-op1;211 break;212 203 case '/': 213 res=op2/op1;214 break;215 204 case '*': 216 res=op1*op2; 205 op1=polishstack.top(); 206 polishstack.pop(); 207 op2=polishstack.top(); 208 polishstack.pop(); 217 209 break; 218 210 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; 220 222 break; 221 223 } 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 } 223 247 } 248 (*emptr)[k]=polishstack.top(); 224 249 } 225 (*emptr)[k]=polishstack.top(); 226 } 227 250 } 228 251 //if addition was not successful addNodeMap returns one. 229 252 //cause can be that there is already a map named like the new one
Note: See TracChangeset
for help on using the changeset viewer.