gui/graph_displayer_canvas.h
author hegyi
Wed, 04 Jan 2006 11:41:58 +0000
changeset 1872 3b7694cf0a08
parent 1849 a4d1362397fe
child 1888 eed01ce27087
permissions -rw-r--r--
Best feature ever\! Name of tabs are different from now on\!
     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   friend class BrokenEdge;
    18 
    19   class BrokenEdge : public Gnome::Canvas::Line
    20   {
    21     Edge edge;
    22     GraphDisplayerCanvas & gdc;
    23     Gnome::Canvas::Polygon * arrow;
    24 
    25     ///Indicates whether the button of mouse is pressed or not
    26     bool isbutton;
    27 
    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*);
    34   public:
    35     BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
    36     ~BrokenEdge();
    37     void draw();
    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   XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
   204 };
   205 
   206 #endif //GRAPH_DISPLAYER_CANVAS_H