gui/graph_displayer_canvas.h
changeset 1914 7ef30a71937f
parent 1860 27a9a75b957b
child 1936 0722ea2b0907
equal deleted inserted replaced
31:48eab341126e 32:df614b454f31
    14 ///This class is the canvas, on which the graph can be drawn.
    14 ///This class is the canvas, on which the graph can be drawn.
    15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    16 {
    16 {
    17   friend class BrokenEdge;
    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   class BrokenEdge : public Gnome::Canvas::Line
    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     Edge edge;
    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     GraphDisplayerCanvas & gdc;
    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     Gnome::Canvas::Polygon * arrow;
    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     bool isbutton;
    49     bool isbutton;
    27 
    50 
    28     ///At this location was the mousebutton pressed.
    51     ///At this location was the mousebutton pressed. Horizontal component.
    29     ///It helps to calculate the distance of dragging.
    52 
    30     double clicked_x, clicked_y;
    53     ///It helps to calculate the
    31 
    54     ///distance of dragging.
    32     ///event handler for forming edges
    55     double clicked_x;
    33     bool edgeFormerEventHandler(GdkEvent*);
    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   public:
    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     ~BrokenEdge();
    81     ~BrokenEdge();
       
    82 
       
    83     ///The function that draws the edge based on collected data
    37     void draw();
    84     void draw();
    38   };
    85   };
       
    86 
       
    87   ///Type of canvas, on which the graph is drawn
    39   typedef Gnome::Canvas::CanvasAA Parent;
    88   typedef Gnome::Canvas::CanvasAA Parent;
    40 
    89 
    41 public:
    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   virtual ~GraphDisplayerCanvas();
    97   virtual ~GraphDisplayerCanvas();
    44 
    98 
    45   ///Changes the linewidth attribute according to the given map.
    99   ///Changes the width of edge(s) according to the given map.
    46   ///\param mapname is the name of the map which contains the new values
   100 
    47   int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
   101   ///\param mapname is the name of the map which contains the values to be set
    48   int resetEdgeWidth (Edge new_item=INVALID);
   102   ///\param edge if it is given, only the width of the given edge will be set, instead of all of them.
    49 
   103   int changeEdgeWidth (std::string mapname, Edge edge=INVALID);
    50   ///Changes the linecolor attribute according to the given map.
   104 
    51   ///\param mapname is the name of the map which contains the new values
   105   ///Resets width of edge(s) to the default value
    52   int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
   106 
    53   int resetEdgeColor (Edge new_item=INVALID);
   107   ///\param edge if it is given, only the width of the
    54 
   108   ///given edge will be reset, instead of all of them.
    55   ///Changes the text of line attribute according to the given map.
   109   int resetEdgeWidth (Edge edge=INVALID);
    56   ///\param mapname is the name of the map which contains the new values
   110 
    57   int changeEdgeText (std::string mapname, Edge new_item=INVALID);
   111   ///Changes the color of edge(s) according to the given map.
    58   int resetEdgeText (Edge new_item=INVALID);
   112 
    59 
   113   ///\param mapname is the name of the map which contains the new values
    60   ///Changes the linewidth attribute according to the given map.
   114   ///\param edge if it is given, only the color of the given edge will be set, instead of all of them.
    61   ///\param mapname is the name of the map which contains the new values
   115   int changeEdgeColor (std::string mapname, Edge edge=INVALID);
    62   int changeNodeRadius (std::string mapname, Node new_item=INVALID);
   116 
    63   int resetNodeRadius (Node new_item=INVALID);
   117   ///Resets color of edge(s) to the default value
    64 
   118 
    65   ///Changes the linecolor attribute according to the given map.
   119   ///\param edge if it is given, only the color of the
    66   ///\param mapname is the name of the map which contains the new values
   120   ///given edge will be reset, instead of all of them.
    67   int changeNodeColor (std::string mapname, Node new_item=INVALID);
   121   int resetEdgeColor (Edge edge=INVALID);
    68   int resetNodeColor (Node new_item=INVALID);
   122 
    69 
   123   ///Changes the label of edge(s) according to the given map.
    70   ///Changes the text of line attribute according to the given map.
   124 
    71   ///\param mapname is the name of the map which contains the new values
   125   ///\param mapname is the name of the map which contains the new values
    72   int changeNodeText (std::string mapname, Node new_item=INVALID);
   126   ///\param edge if it is given, only the label of the given edge will be set, instead of all of them.
    73   int resetNodeText (Node new_item=INVALID);
   127   int changeEdgeText (std::string mapname, Edge edge=INVALID);
    74 
   128 
    75   void propertyChange(bool, int);
   129   ///Resets label of edge(s) to the default value
    76   void propertyUpdate(Edge, int, int dummy=0);
   130 
    77   void propertyUpdate(Node, int, int dummy=0);
   131   ///\param edge if it is given, only the color of the
    78 
   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   void propertyUpdate(Edge);
   190   void propertyUpdate(Edge);
       
   191 
       
   192   ///updates all the property for the given node
    80   void propertyUpdate(Node);
   193   void propertyUpdate(Node);
    81 
   194 
    82   ///Callback for 'ViewZoomIn' action.
   195   ///Callback for 'ViewZoomIn' action.
    83   virtual void zoomIn();
   196   virtual void zoomIn();
    84   ///Callback for 'ViewZoomOut' action.
   197   ///Callback for 'ViewZoomOut' action.
    93   ///This function changes the tool in the graph-editor's hand
   206   ///This function changes the tool in the graph-editor's hand
    94   void changeEditorialTool(int);
   207   void changeEditorialTool(int);
    95 
   208 
    96 protected:
   209 protected:
    97 
   210 
    98   //maximizing, minimizing, restoring window, etc. 
   211   //maximizing, minimizing, restoring window, etc.
    99   virtual bool on_expose_event(GdkEventExpose *);
   212   virtual bool on_expose_event(GdkEventExpose *);
   100 
   213 
   101 private:
   214 private:
   102 
   215 
   103   ///This function is responsible for the correct
   216   ///This function is responsible for the correct
   125   bool nodeMapEditEventHandler(GdkEvent*);
   238   bool nodeMapEditEventHandler(GdkEvent*);
   126 
   239 
   127 public:
   240 public:
   128   ///Moves the text to new place
   241   ///Moves the text to new place
   129   void textReposition(xy<double>);
   242   void textReposition(xy<double>);
       
   243 
   130   ///Activates an edge belonging to a BrokenEdge
   244   ///Activates an edge belonging to a BrokenEdge
   131   ///
   245 
   132   ///After we have activated an edge this way,
   246   ///After we have activated an edge this way,
   133   ///the GDC object will know, which edge is under forming
   247   ///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,
   135   ///for example the text belonging to the \ref BrokenEdge can be
   249   ///for example the text belonging to the \ref BrokenEdge can be
   136   ///redrawn (\ref textReposition).
   250   ///redrawn (\ref textReposition).
   137   void toggleEdgeActivity(BrokenEdge*, bool);
   251   void toggleEdgeActivity(BrokenEdge*, bool);
   138 
   252 
   139 public:
   253 public:
   140   ///\return the actual tool in hand
   254 
       
   255   ///Returns the actual tool in hand
   141   int getActualTool();
   256   int getActualTool();
   142 
   257 
       
   258   ///draws the graph
       
   259 
       
   260   ///Called when opening a file.
   143   void drawGraph();
   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   void clear();
   267   void clear();
   145 
   268 
   146   ///creates a new Nodemap
   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   ///creates a new Edgemap
   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 private:
   280 private:
   152   ///Deletes the given element.
   281   ///Deletes the given element.
   153   void deleteItem(Node);
   282   void deleteItem(Node);
   154   ///Deletes the given element.
   283   ///Deletes the given element.
   181   ///At this location was the mousebutton pressed.
   310   ///At this location was the mousebutton pressed.
   182   ///It helps to calculate the distance of dragging.
   311   ///It helps to calculate the distance of dragging.
   183   double clicked_x, clicked_y;
   312   double clicked_x, clicked_y;
   184 
   313 
   185   ///Remembers which Gnome::Canvas::Item was pressed.
   314   ///Remembers which Gnome::Canvas::Item was pressed.
   186   ///this variable is needed, because
   315 
   187   ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
   316   ///this variable is needed, to work on it after selection
   188   ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
   317   Gnome::Canvas::Item * active_item;
   189   Gnome::Canvas::Item * active_item, * target_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   Node active_node;
   330   Node active_node;
       
   331 
       
   332   ///selected edge (for any editing)
   191   Edge active_edge;
   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   Edge forming_edge;
   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   static const int zoom_step = 5;
   347   static const int zoom_step = 5;
   197 
   348 
   198 private:
   349 private:
   199 
   350 
   200   ///reference to the parent window
   351   ///reference to the container, in which the canvas is
   201   NoteBookTab & mytab;
   352   NoteBookTab & mytab;
   202 
   353 
   203   XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
   354   XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
   204 };
   355 };
   205 
   356