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