graph_displayer_canvas.h
author hegyi
Fri, 17 Jun 2005 17:08:45 +0000
branchgui
changeset 25 c45a34eaa118
parent 21 44bb92014108
child 28 fa28f1071bd6
permissions -rw-r--r--
Previous commit was also mine, but I forgot to say, that it was my younger brother's birthyear. From this commit texts of activated maps move together with red arrows.
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
hegyi@25
    59
  ///DEPRECATED!!!!
ladanyi@6
    60
  bool event_handler(GdkEvent* e, Node n);
ladanyi@6
    61
hegyi@9
    62
  ///actual event handler
hegyi@9
    63
  ///
hegyi@9
    64
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@9
    65
  sigc::connection actual_handler;
hegyi@9
    66
hegyi@9
    67
  ///event handler for the case when move-tool is active
hegyi@9
    68
  bool move_event_handler(GdkEvent*);
hegyi@9
    69
  ///event handler for the case when create_node-tool is active
hegyi@9
    70
  bool create_node_event_handler(GdkEvent*);
hegyi@9
    71
  ///event handler for the case when create_edge-tool is active
hegyi@9
    72
  bool create_edge_event_handler(GdkEvent*);
hegyi@13
    73
  ///event handler for the case when eraser-tool is active
hegyi@13
    74
  bool eraser_event_handler(GdkEvent*);
hegyi@21
    75
  ///event handler for the case when eraser-tool is active
hegyi@21
    76
  bool edge_map_edit_event_handler(GdkEvent*);
hegyi@13
    77
hegyi@21
    78
public:
hegyi@25
    79
  ///Moves the text to new place
hegyi@25
    80
  void text_reposition(xy<double>);
hegyi@25
    81
  ///Activates an edge belonging to a BrokenEdge
hegyi@25
    82
  void toggle_edge_activity(BrokenEdge*, bool);
hegyi@25
    83
hegyi@25
    84
public:
hegyi@21
    85
  ///\return the actual tool in hand
hegyi@21
    86
  int get_actual_tool();
hegyi@21
    87
hegyi@21
    88
private:
hegyi@14
    89
  ///Deletes the given element.
hegyi@14
    90
  void delete_item(NodeIt);
hegyi@14
    91
  ///Deletes the given element.
hegyi@14
    92
  void delete_item(EdgeIt);
hegyi@16
    93
  ///Deletes the given element.
hegyi@16
    94
  void delete_item(Graph::Edge);
hegyi@9
    95
hegyi@21
    96
private:
hegyi@21
    97
ladanyi@6
    98
  ///The graph, on which we work
ladanyi@6
    99
  Graph g;
ladanyi@6
   100
ladanyi@6
   101
  ///Map of nodes of graph
ladanyi@6
   102
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
   103
ladanyi@6
   104
  ///Map of edges of graph
hegyi@19
   105
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@6
   106
ladanyi@6
   107
  ///Map of texts to write on edges
ladanyi@6
   108
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
   109
ladanyi@6
   110
  ///Group of graphical elements of displayed_graph
ladanyi@6
   111
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
   112
ladanyi@6
   113
  ///Here we store the maps that can be displayed through properties.
ladanyi@6
   114
  MapStorage mapstorage;
ladanyi@6
   115
ladanyi@6
   116
  ///Indicates whether the button of mouse is pressed or not
hegyi@20
   117
  int isbutton;
ladanyi@6
   118
hegyi@21
   119
  ///Stores the actual tool in hand
hegyi@21
   120
  int actual_tool;
hegyi@21
   121
ladanyi@6
   122
  ///At this location was the mousebutton pressed.
ladanyi@6
   123
  ///It helps to calculate the distance of dragging.
ladanyi@6
   124
  double clicked_x, clicked_y;
ladanyi@6
   125
ladanyi@6
   126
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
   127
  ///this variable is needed, because
ladanyi@6
   128
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
   129
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@11
   130
  Gnome::Canvas::Item * active_item, * target_item;
hegyi@9
   131
  Graph::NodeIt active_node;
hegyi@11
   132
  Graph::EdgeIt active_edge;
ladanyi@6
   133
ladanyi@6
   134
  static const int zoom_step = 5;
hegyi@19
   135
ladanyi@6
   136
};
ladanyi@6
   137
ladanyi@6
   138
#endif //GRAPH_DISPLAYER_CANVAS_H