gui/graph_displayer_canvas.h
author deba
Wed, 14 Dec 2005 18:11:03 +0000
changeset 1859 075aaa0a4e6f
parent 1837 8dd6160ff699
child 1860 27a9a75b957b
permissions -rw-r--r--
Bug fix
and doc fix
     1 // -*- C++ -*- //
     2 
     3 #ifndef GRAPH_DISPLAYER_CANVAS_H
     4 #define GRAPH_DISPLAYER_CANVAS_H
     5 
     6 class GraphDisplayerCanvas;
     7 
     8 #include "all_include.h"
     9 #include "nbtab.h"
    10 #include <libgnomecanvasmm.h>
    11 #include <libgnomecanvasmm/polygon.h>
    12 #include <lemon/xy.h>
    13 
    14 ///This class is the canvas, on which the graph can be drawn.
    15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    16 {
    17   class BrokenEdge : public Gnome::Canvas::Line
    18   {
    19     GraphDisplayerCanvas & gdc;
    20     Gnome::Canvas::Polygon * arrow;
    21     Gnome::Art::Point * my_points;
    22 
    23 
    24     ///Indicates whether the button of mouse is pressed or not
    25     bool isbutton;
    26 
    27     ///At this location was the mousebutton pressed.
    28     ///It helps to calculate the distance of dragging.
    29     double clicked_x, clicked_y;
    30 
    31     ///event handler for forming edges
    32     bool edgeFormerEventHandler(GdkEvent*);
    33   public:
    34     BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
    35     ~BrokenEdge();
    36     void setPoints(Gnome::Canvas::Points, bool move=false);
    37     xy<double> getArrowPos();
    38   };
    39   typedef Gnome::Canvas::CanvasAA Parent;
    40 
    41 public:
    42   GraphDisplayerCanvas(NoteBookTab &);
    43   virtual ~GraphDisplayerCanvas();
    44 
    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 
    79   void propertyUpdate(Edge);
    80   void propertyUpdate(Node);
    81 
    82   ///Callback for 'ViewZoomIn' action.
    83   virtual void zoomIn();
    84   ///Callback for 'ViewZoomOut' action.
    85   virtual void zoomOut();
    86   ///Callback for 'ViewZoomFit' action.
    87   virtual void zoomFit();
    88   ///Callback for 'ViewZoom100' action.
    89   virtual void zoom100();
    90   ///Sets the scroll region of the convas to the bounding box of the graph.
    91   void updateScrollRegion();
    92 
    93   ///This function changes the tool in the graph-editor's hand
    94   void changeEditorialTool(int);
    95 
    96 protected:
    97 
    98   //maximizing, minimizing, restoring window, etc. 
    99   virtual bool on_expose_event(GdkEventExpose *);
   100 
   101 private:
   102 
   103   ///This function is responsible for the correct
   104   ///reaction of any action happened in the territory
   105   ///of the canvas
   106   ///DEPRECATED!!!!
   107   bool eventHandler(GdkEvent* e, Node n);
   108 
   109   ///actual event handler
   110   ///
   111   ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
   112   sigc::connection actual_handler;
   113 
   114   ///event handler for the case when move-tool is active
   115   bool moveEventHandler(GdkEvent*);
   116   ///event handler for the case when create_node-tool is active
   117   bool createNodeEventHandler(GdkEvent*);
   118   ///event handler for the case when create_edge-tool is active
   119   bool createEdgeEventHandler(GdkEvent*);
   120   ///event handler for the case when eraser-tool is active
   121   bool eraserEventHandler(GdkEvent*);
   122   ///event handler for the case when edge map editor tool is active
   123   bool edgeMapEditEventHandler(GdkEvent*);
   124   ///event handler for the case when node map editor tool is active
   125   bool nodeMapEditEventHandler(GdkEvent*);
   126 
   127 public:
   128   ///Moves the text to new place
   129   void textReposition(xy<double>);
   130   ///Activates an edge belonging to a BrokenEdge
   131   ///
   132   ///After we have activated an edge this way,
   133   ///the GDC object will know, which edge is under forming
   134   ///therefore it can redraw the necessarz elementy on the canvas,
   135   ///for example the text belonging to the \ref BrokenEdge can be
   136   ///redrawn (\ref textReposition).
   137   void toggleEdgeActivity(BrokenEdge*, bool);
   138 
   139 public:
   140   ///\return the actual tool in hand
   141   int getActualTool();
   142 
   143   void drawGraph();
   144   void clear();
   145 
   146   ///creates a new Nodemap
   147   int addNewNodeMap(double,std::string);
   148   ///creates a new Edgemap
   149   int addNewEdgeMap(double,std::string);
   150 
   151 private:
   152   ///Deletes the given element.
   153   void deleteItem(Node);
   154   ///Deletes the given element.
   155   void deleteItem(Edge);
   156 
   157 private:
   158 
   159   ///Map of nodes of graph
   160   Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
   161 
   162   ///Map of edges of graph
   163   Graph::EdgeMap<BrokenEdge *> edgesmap;
   164 
   165   ///Map of texts to write on edges
   166   Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
   167 
   168   ///Map of texts to write on nodes
   169   Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
   170 
   171   ///Group of graphical elements of displayed_graph
   172   Gnome::Canvas::Group displayed_graph;
   173 
   174 private:
   175   ///Indicates whether the button of mouse is pressed or not
   176   int isbutton;
   177 
   178   ///Stores the actual tool in hand
   179   int actual_tool;
   180 
   181   ///At this location was the mousebutton pressed.
   182   ///It helps to calculate the distance of dragging.
   183   double clicked_x, clicked_y;
   184 
   185   ///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;
   190   Node active_node;
   191   Edge active_edge;
   192   Edge forming_edge;
   193 
   194   std::string nodemap_to_edit, edgemap_to_edit;
   195 
   196   static const int zoom_step = 5;
   197 
   198 private:
   199 
   200   ///reference to the parent window
   201   NoteBookTab & mytab;
   202 
   203 };
   204 
   205 #endif //GRAPH_DISPLAYER_CANVAS_H