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