graph_displayer_canvas.h
branchgui
changeset 118 cfd49e5c8723
parent 98 f60f89147531
child 127 656ac25e009b
     1.1 --- a/graph_displayer_canvas.h	Mon Jan 09 12:41:06 2006 +0000
     1.2 +++ b/graph_displayer_canvas.h	Tue Jan 10 15:15:57 2006 +0000
     1.3 @@ -16,67 +16,180 @@
     1.4  {
     1.5    friend class BrokenEdge;
     1.6  
     1.7 +  ///Edge displayer class
     1.8 +
     1.9 +  ///This class is responsible for displaying edges in graph.
    1.10 +  ///The displayed edge is broken in the middle. The
    1.11 +  ///aim of this is to be able to indicate direction of edges
    1.12 +  ///and to be able to display more then one edges between the
    1.13 +  ///same source and target
    1.14    class BrokenEdge : public Gnome::Canvas::Line
    1.15    {
    1.16 +    ///The edge that the class displays.
    1.17 +
    1.18 +    ///It is needed, because some datas needed from
    1.19 +    ///graph can be accessed by this or should be sent
    1.20 +    ///as parameter, but it would be complicated
    1.21      Edge edge;
    1.22 +
    1.23 +    ///Reference to the canvas, on which the graph is drawn.
    1.24 +
    1.25 +    ///It is needed, because some datas needed from
    1.26 +    ///graph can be accessed by this or should be sent
    1.27 +    ///as parameter, but it would be complicated
    1.28      GraphDisplayerCanvas & gdc;
    1.29 +
    1.30 +    ///An arrow that indicates the direction of the edges
    1.31 +
    1.32 +    ///in case of directional graph direction can be indicated
    1.33 +    ///by this polygon. The polygon formulates a red arrow.
    1.34      Gnome::Canvas::Polygon * arrow;
    1.35  
    1.36 -    ///Indicates whether the button of mouse is pressed or not
    1.37 +    ///Indicates whether the button of mouse is pressed or not at the moment.
    1.38      bool isbutton;
    1.39  
    1.40 -    ///At this location was the mousebutton pressed.
    1.41 -    ///It helps to calculate the distance of dragging.
    1.42 -    double clicked_x, clicked_y;
    1.43 +    ///At this location was the mousebutton pressed. Horizontal component.
    1.44  
    1.45 -    ///event handler for forming edges
    1.46 -    bool edgeFormerEventHandler(GdkEvent*);
    1.47 +    ///It helps to calculate the
    1.48 +    ///distance of dragging.
    1.49 +    double clicked_x;
    1.50 +
    1.51 +    ///At this location was the mousebutton pressed. Vertical component.
    1.52 +
    1.53 +    ///It helps to calculate the
    1.54 +    ///distance of dragging.
    1.55 +    double clicked_y;
    1.56 +
    1.57 +    ///event handler for forming broken edges
    1.58 +
    1.59 +    ///\param event the
    1.60 +    ///event to handle
    1.61 +    bool edgeFormerEventHandler(GdkEvent* event);
    1.62    public:
    1.63 -    BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
    1.64 +
    1.65 +    ///Constructor of broken edge class.
    1.66 +
    1.67 +    ///\param g the group to which the edge belongs
    1.68 +    ///\param _edge the represented edge
    1.69 +    ///\param gc the canvas
    1.70 +    BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc);
    1.71 +
    1.72 +    ///Destructor of broken edge class
    1.73 +
    1.74 +    ///Frees up
    1.75 +    ///reserved memory
    1.76      ~BrokenEdge();
    1.77 +
    1.78 +    ///The function that draws the edge based on collected data
    1.79      void draw();
    1.80    };
    1.81 +
    1.82 +  ///Type of canvas, on which the graph is drawn
    1.83    typedef Gnome::Canvas::CanvasAA Parent;
    1.84  
    1.85  public:
    1.86 -  GraphDisplayerCanvas(NoteBookTab &);
    1.87 +  ///Constructor
    1.88 +
    1.89 +  ///\param nbt the tab of the window, in which the graph is displayed
    1.90 +  GraphDisplayerCanvas(NoteBookTab & nbt);
    1.91 +
    1.92 +  ///destructor of the class
    1.93    virtual ~GraphDisplayerCanvas();
    1.94  
    1.95 -  ///Changes the linewidth attribute according to the given map.
    1.96 +  ///Changes the width of edge(s) according to the given map.
    1.97 +
    1.98 +  ///\param mapname is the name of the map which contains the values to be set
    1.99 +  ///\param edge if it is given, only the width of the given edge will be set, instead of all of them.
   1.100 +  int changeEdgeWidth (std::string mapname, Edge edge=INVALID);
   1.101 +
   1.102 +  ///Resets width of edge(s) to the default value
   1.103 +
   1.104 +  ///\param edge if it is given, only the width of the
   1.105 +  ///given edge will be reset, instead of all of them.
   1.106 +  int resetEdgeWidth (Edge edge=INVALID);
   1.107 +
   1.108 +  ///Changes the color of edge(s) according to the given map.
   1.109 +
   1.110    ///\param mapname is the name of the map which contains the new values
   1.111 -  int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
   1.112 -  int resetEdgeWidth (Edge new_item=INVALID);
   1.113 +  ///\param edge if it is given, only the color of the given edge will be set, instead of all of them.
   1.114 +  int changeEdgeColor (std::string mapname, Edge edge=INVALID);
   1.115  
   1.116 -  ///Changes the linecolor attribute according to the given map.
   1.117 +  ///Resets color of edge(s) to the default value
   1.118 +
   1.119 +  ///\param edge if it is given, only the color of the
   1.120 +  ///given edge will be reset, instead of all of them.
   1.121 +  int resetEdgeColor (Edge edge=INVALID);
   1.122 +
   1.123 +  ///Changes the label of edge(s) according to the given map.
   1.124 +
   1.125    ///\param mapname is the name of the map which contains the new values
   1.126 -  int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
   1.127 -  int resetEdgeColor (Edge new_item=INVALID);
   1.128 +  ///\param edge if it is given, only the label of the given edge will be set, instead of all of them.
   1.129 +  int changeEdgeText (std::string mapname, Edge edge=INVALID);
   1.130  
   1.131 -  ///Changes the text of line attribute according to the given map.
   1.132 +  ///Resets label of edge(s) to the default value
   1.133 +
   1.134 +  ///\param edge if it is given, only the color of the
   1.135 +  ///given edge will be reset, instead of all of them.
   1.136 +  int resetEdgeText (Edge edge=INVALID);
   1.137 +
   1.138 +  ///Changes the radius of node(s) according to the given map.
   1.139 +
   1.140    ///\param mapname is the name of the map which contains the new values
   1.141 -  int changeEdgeText (std::string mapname, Edge new_item=INVALID);
   1.142 -  int resetEdgeText (Edge new_item=INVALID);
   1.143 +  ///\param node if it is given, only the radius of the given node will be set, instead of all of them.
   1.144 +  int changeNodeRadius (std::string mapname, Node node=INVALID);
   1.145  
   1.146 -  ///Changes the linewidth attribute according to the given map.
   1.147 +  ///Resets radius of node(s) to the default value
   1.148 +
   1.149 +  ///\param node if it is given, only the radius of the
   1.150 +  ///given node will be reset, instead of all of them.
   1.151 +  int resetNodeRadius (Node node=INVALID);
   1.152 +
   1.153 +  ///Changes the color of node(s) according to the given map.
   1.154 +
   1.155    ///\param mapname is the name of the map which contains the new values
   1.156 -  int changeNodeRadius (std::string mapname, Node new_item=INVALID);
   1.157 -  int resetNodeRadius (Node new_item=INVALID);
   1.158 +  ///\param node if it is given, only the color of the given node will be set, instead of all of them.
   1.159 +  int changeNodeColor (std::string mapname, Node node=INVALID);
   1.160  
   1.161 -  ///Changes the linecolor attribute according to the given map.
   1.162 +  ///Resets color of node(s) to the default value
   1.163 +
   1.164 +  ///\param node if it is given, only the color of the
   1.165 +  ///given node will be reset, instead of all of them.
   1.166 +  int resetNodeColor (Node node=INVALID);
   1.167 +
   1.168 +  ///Changes the label of node(s) according to the given map.
   1.169 +
   1.170    ///\param mapname is the name of the map which contains the new values
   1.171 -  int changeNodeColor (std::string mapname, Node new_item=INVALID);
   1.172 -  int resetNodeColor (Node new_item=INVALID);
   1.173 +  ///\param node if it is given, only the label of the given node will be set, instead of all of them.
   1.174 +  int changeNodeText (std::string mapname, Node node=INVALID);
   1.175  
   1.176 -  ///Changes the text of line attribute according to the given map.
   1.177 -  ///\param mapname is the name of the map which contains the new values
   1.178 -  int changeNodeText (std::string mapname, Node new_item=INVALID);
   1.179 -  int resetNodeText (Node new_item=INVALID);
   1.180 +  ///Resets label of node(s) to the default value
   1.181  
   1.182 -  void propertyChange(bool, int);
   1.183 -  void propertyUpdate(Edge, int, int dummy=0);
   1.184 -  void propertyUpdate(Node, int, int dummy=0);
   1.185 +  ///\param node if it is given, only the label of the
   1.186 +  ///given node will be reset, instead of all of them.
   1.187 +  int resetNodeText (Node node=INVALID);
   1.188  
   1.189 +  ///This function is called, when any of the displayed attributes have to be updated, or changed
   1.190 +
   1.191 +  ///\param itisedge if true, edge property has to be changed, else node property
   1.192 +  ///\param prop the id of property that has to changed or updated
   1.193 +  void propertyChange(bool itisedge, int prop);
   1.194 +
   1.195 +  ///updates the given property
   1.196 +
   1.197 +  ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them
   1.198 +  ///\param prop the property to update
   1.199 +  void propertyUpdate(Edge edge, int prop);
   1.200 +
   1.201 +  ///updates the given property
   1.202 +
   1.203 +  ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them
   1.204 +  ///\param prop the property to update
   1.205 +  void propertyUpdate(Node node, int prop);
   1.206 +
   1.207 +  ///updates all the property for the given edge
   1.208    void propertyUpdate(Edge);
   1.209 +
   1.210 +  ///updates all the property for the given node
   1.211    void propertyUpdate(Node);
   1.212  
   1.213    ///Callback for 'ViewZoomIn' action.
   1.214 @@ -95,7 +208,7 @@
   1.215  
   1.216  protected:
   1.217  
   1.218 -  //maximizing, minimizing, restoring window, etc. 
   1.219 +  //maximizing, minimizing, restoring window, etc.
   1.220    virtual bool on_expose_event(GdkEventExpose *);
   1.221  
   1.222  private:
   1.223 @@ -127,26 +240,42 @@
   1.224  public:
   1.225    ///Moves the text to new place
   1.226    void textReposition(xy<double>);
   1.227 +
   1.228    ///Activates an edge belonging to a BrokenEdge
   1.229 -  ///
   1.230 +
   1.231    ///After we have activated an edge this way,
   1.232    ///the GDC object will know, which edge is under forming
   1.233 -  ///therefore it can redraw the necessarz elementy on the canvas,
   1.234 +  ///therefore it can redraw the necessary elements on the canvas,
   1.235    ///for example the text belonging to the \ref BrokenEdge can be
   1.236    ///redrawn (\ref textReposition).
   1.237    void toggleEdgeActivity(BrokenEdge*, bool);
   1.238  
   1.239  public:
   1.240 -  ///\return the actual tool in hand
   1.241 +
   1.242 +  ///Returns the actual tool in hand
   1.243    int getActualTool();
   1.244  
   1.245 +  ///draws the graph
   1.246 +
   1.247 +  ///Called when opening a file.
   1.248    void drawGraph();
   1.249 +
   1.250 +  ///Clears the canvas
   1.251 +
   1.252 +  ///It achieves this by deleting all data
   1.253 +  ///structure used to help handle the displayed graph.
   1.254    void clear();
   1.255  
   1.256    ///creates a new Nodemap
   1.257 -  int addNewNodeMap(double,std::string);
   1.258 +
   1.259 +  ///\param init initial value of the map
   1.260 +  ///\param mapname name of new map
   1.261 +  int addNewNodeMap(double init,std::string mapname);
   1.262    ///creates a new Edgemap
   1.263 -  int addNewEdgeMap(double,std::string);
   1.264 +
   1.265 +  ///\param init initial value of the map
   1.266 +  ///\param mapname name of new map
   1.267 +  int addNewEdgeMap(double init,std::string mapname);
   1.268  
   1.269  private:
   1.270    ///Deletes the given element.
   1.271 @@ -183,21 +312,43 @@
   1.272    double clicked_x, clicked_y;
   1.273  
   1.274    ///Remembers which Gnome::Canvas::Item was pressed.
   1.275 -  ///this variable is needed, because
   1.276 -  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
   1.277 -  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
   1.278 -  Gnome::Canvas::Item * active_item, * target_item;
   1.279 +
   1.280 +  ///this variable is needed, to work on it after selection
   1.281 +  Gnome::Canvas::Item * active_item;
   1.282 +
   1.283 +  ///Remembers which Gnome::Canvas::Item was pressed.
   1.284 +
   1.285 +  ///this variable is used at edge creation, it will
   1.286 +  ///be the secondly selected node. No local variable
   1.287 +  ///can be used for this purpose inside the function,
   1.288 +  ///because the node selected by button press, and
   1.289 +  ///the edge is created by button release. Both of
   1.290 +  ///them is different function call.
   1.291 +  Gnome::Canvas::Item * target_item;
   1.292 +
   1.293 +  ///selected node (for any editing)
   1.294    Node active_node;
   1.295 +
   1.296 +  ///selected edge (for any editing)
   1.297    Edge active_edge;
   1.298 +
   1.299 +  ///the edge that is selected by clicking on the red arrow in the middle of it
   1.300 +
   1.301 +  ///This edge is stored only for the purpose of reshape it.
   1.302 +  ///That is why it is selected in a different manner.
   1.303    Edge forming_edge;
   1.304  
   1.305 -  std::string nodemap_to_edit, edgemap_to_edit;
   1.306 +  ///Map displayed by label can be edited.
   1.307 +  std::string nodemap_to_edit;
   1.308 +
   1.309 +  ///Map displayed by label can be edited.
   1.310 +  std::string edgemap_to_edit;
   1.311  
   1.312    static const int zoom_step = 5;
   1.313  
   1.314  private:
   1.315  
   1.316 -  ///reference to the parent window
   1.317 +  ///reference to the container, in which the canvas is
   1.318    NoteBookTab & mytab;
   1.319  
   1.320    XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);