graph_displayer_canvas.h
author hegyi
Thu, 16 Jun 2005 18:58:15 +0000
branchgui
changeset 20 a3bd39d50930
parent 19 164783ceb9be
child 21 44bb92014108
permissions -rw-r--r--
First of all: revision 1981 is mine, what is important me because I was born in 1981. But what is new in my revision? If you drag nodes with left button, edge-breakpoints do not change location. If you drag nodes by right button, they do, they take up their base situation at the halfpoint of the edge.
ladanyi@6
     1
// -*- C++ -*- //
ladanyi@6
     2
ladanyi@6
     3
#ifndef GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     4
#define GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     5
ladanyi@6
     6
#include <all_include.h>
ladanyi@6
     7
#include <mapstorage.h>
hegyi@19
     8
#include <broken_edge.h>
ladanyi@6
     9
#include <libgnomecanvasmm.h>
ladanyi@6
    10
#include <libgnomecanvasmm/polygon.h>
ladanyi@6
    11
ladanyi@6
    12
///This class is the canvas, on which the graph can be drawn.
ladanyi@6
    13
class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
ladanyi@6
    14
{
ladanyi@6
    15
  typedef Gnome::Canvas::CanvasAA Parent;
ladanyi@6
    16
ladanyi@6
    17
public:
ladanyi@6
    18
  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
ladanyi@6
    19
  virtual ~GraphDisplayerCanvas();
ladanyi@6
    20
ladanyi@6
    21
  ///Changes the linewidth attribute according to the given map.
ladanyi@6
    22
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    23
  int changeLineWidth (std::string mapname);
ladanyi@6
    24
ladanyi@6
    25
  ///Changes the linecolor attribute according to the given map.
ladanyi@6
    26
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    27
  int changeColor (std::string mapname);
ladanyi@6
    28
ladanyi@6
    29
  ///Changes the text of line attribute according to the given map.
ladanyi@6
    30
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    31
  int changeText (std::string mapname);
ladanyi@6
    32
ladanyi@6
    33
  ///Callback for 'ViewZoomIn' action.
ladanyi@6
    34
  virtual void zoomIn();
ladanyi@6
    35
  ///Callback for 'ViewZoomOut' action.
ladanyi@6
    36
  virtual void zoomOut();
ladanyi@6
    37
  ///Callback for 'ViewZoomFit' action.
ladanyi@6
    38
  virtual void zoomFit();
ladanyi@6
    39
  ///Callback for 'ViewZoom100' action.
ladanyi@6
    40
  virtual void zoom100();
ladanyi@6
    41
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@6
    42
  void updateScrollRegion();
ladanyi@6
    43
hegyi@9
    44
  ///This function changes the tool in the graph-editor's hand
hegyi@9
    45
  void changeEditorialTool(int);
hegyi@9
    46
ladanyi@6
    47
protected:
ladanyi@6
    48
ladanyi@6
    49
  //maximizing, minimizing, restoring window, etc. 
ladanyi@6
    50
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@6
    51
ladanyi@6
    52
private:
ladanyi@6
    53
ladanyi@6
    54
  ///This function is responsible for the correct
ladanyi@6
    55
  ///reaction of any action happened in the territory
ladanyi@6
    56
  ///of the canvas
ladanyi@6
    57
  bool event_handler(GdkEvent* e, Node n);
ladanyi@6
    58
hegyi@9
    59
  ///actual event handler
hegyi@9
    60
  ///
hegyi@9
    61
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@9
    62
  sigc::connection actual_handler;
hegyi@9
    63
hegyi@9
    64
  ///event handler for the case when move-tool is active
hegyi@9
    65
  bool move_event_handler(GdkEvent*);
hegyi@9
    66
  ///event handler for the case when create_node-tool is active
hegyi@9
    67
  bool create_node_event_handler(GdkEvent*);
hegyi@9
    68
  ///event handler for the case when create_edge-tool is active
hegyi@9
    69
  bool create_edge_event_handler(GdkEvent*);
hegyi@13
    70
  ///event handler for the case when eraser-tool is active
hegyi@13
    71
  bool eraser_event_handler(GdkEvent*);
hegyi@13
    72
hegyi@14
    73
  ///Deletes the given element.
hegyi@14
    74
  void delete_item(NodeIt);
hegyi@14
    75
  ///Deletes the given element.
hegyi@14
    76
  void delete_item(EdgeIt);
hegyi@16
    77
  ///Deletes the given element.
hegyi@16
    78
  void delete_item(Graph::Edge);
hegyi@9
    79
ladanyi@6
    80
  ///The graph, on which we work
ladanyi@6
    81
  Graph g;
ladanyi@6
    82
ladanyi@6
    83
  ///Map of nodes of graph
ladanyi@6
    84
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
    85
ladanyi@6
    86
  ///Map of edges of graph
hegyi@19
    87
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@6
    88
ladanyi@6
    89
  ///Map of texts to write on edges
ladanyi@6
    90
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
    91
ladanyi@6
    92
  ///Group of graphical elements of displayed_graph
ladanyi@6
    93
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
    94
ladanyi@6
    95
  ///Here we store the maps that can be displayed through properties.
ladanyi@6
    96
  MapStorage mapstorage;
ladanyi@6
    97
ladanyi@6
    98
  ///Indicates whether the button of mouse is pressed or not
hegyi@20
    99
  int isbutton;
ladanyi@6
   100
ladanyi@6
   101
  ///At this location was the mousebutton pressed.
ladanyi@6
   102
  ///It helps to calculate the distance of dragging.
ladanyi@6
   103
  double clicked_x, clicked_y;
ladanyi@6
   104
ladanyi@6
   105
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
   106
  ///this variable is needed, because
ladanyi@6
   107
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
   108
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@11
   109
  Gnome::Canvas::Item * active_item, * target_item;
hegyi@9
   110
  Graph::NodeIt active_node;
hegyi@11
   111
  Graph::EdgeIt active_edge;
ladanyi@6
   112
ladanyi@6
   113
  static const int zoom_step = 5;
hegyi@19
   114
ladanyi@6
   115
};
ladanyi@6
   116
ladanyi@6
   117
#endif //GRAPH_DISPLAYER_CANVAS_H