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