graph_displayer_canvas.h
author ladanyi
Tue, 22 Nov 2005 14:35:33 +0000
branchgui
changeset 92 ee2bd58fdc30
parent 88 c397e85ec555
child 94 adfdc2f70548
permissions -rw-r--r--
clean-up
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@53
     8
#include "all_include.h"
ladanyi@53
     9
#include "mapstorage.h"
ladanyi@53
    10
#include "map_win.h"
ladanyi@6
    11
#include <libgnomecanvasmm.h>
ladanyi@6
    12
#include <libgnomecanvasmm/polygon.h>
hegyi@89
    13
#include <lemon/xy.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
{
hegyi@89
    18
  class BrokenEdge : public Gnome::Canvas::Line
hegyi@89
    19
  {
hegyi@89
    20
    GraphDisplayerCanvas & gdc;
hegyi@89
    21
    Gnome::Canvas::Polygon * arrow;
hegyi@89
    22
    Gnome::Art::Point * my_points;
hegyi@89
    23
hegyi@89
    24
hegyi@89
    25
    ///Indicates whether the button of mouse is pressed or not
hegyi@89
    26
    bool isbutton;
hegyi@89
    27
hegyi@89
    28
    ///At this location was the mousebutton pressed.
hegyi@89
    29
    ///It helps to calculate the distance of dragging.
hegyi@89
    30
    double clicked_x, clicked_y;
hegyi@89
    31
hegyi@89
    32
    ///event handler for forming edges
hegyi@89
    33
    bool edgeFormerEventHandler(GdkEvent*);
hegyi@89
    34
  public:
hegyi@89
    35
    BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
hegyi@89
    36
    ~BrokenEdge();
hegyi@89
    37
    void setPoints(Gnome::Canvas::Points, bool move=false);
hegyi@89
    38
    xy<double> getArrowPos();
hegyi@89
    39
  };
ladanyi@6
    40
  typedef Gnome::Canvas::CanvasAA Parent;
ladanyi@6
    41
ladanyi@6
    42
public:
hegyi@55
    43
  GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
ladanyi@6
    44
  virtual ~GraphDisplayerCanvas();
ladanyi@6
    45
ladanyi@6
    46
  ///Changes the linewidth attribute according to the given map.
ladanyi@6
    47
  ///\param mapname is the name of the map which contains the new values
alpar@62
    48
  int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
hegyi@81
    49
  int resetEdgeWidth (Edge new_item=INVALID);
ladanyi@6
    50
ladanyi@6
    51
  ///Changes the linecolor attribute according to the given map.
ladanyi@6
    52
  ///\param mapname is the name of the map which contains the new values
alpar@62
    53
  int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
hegyi@81
    54
  int resetEdgeColor (Edge new_item=INVALID);
ladanyi@6
    55
ladanyi@6
    56
  ///Changes the text of line attribute according to the given map.
ladanyi@6
    57
  ///\param mapname is the name of the map which contains the new values
alpar@62
    58
  int changeEdgeText (std::string mapname, Edge new_item=INVALID);
hegyi@81
    59
  int resetEdgeText (Edge new_item=INVALID);
hegyi@28
    60
hegyi@28
    61
  ///Changes the linewidth attribute according to the given map.
hegyi@28
    62
  ///\param mapname is the name of the map which contains the new values
alpar@62
    63
  int changeNodeRadius (std::string mapname, Node new_item=INVALID);
hegyi@81
    64
  int resetNodeRadius (Node new_item=INVALID);
hegyi@28
    65
hegyi@28
    66
  ///Changes the linecolor attribute according to the given map.
hegyi@28
    67
  ///\param mapname is the name of the map which contains the new values
alpar@62
    68
  int changeNodeColor (std::string mapname, Node new_item=INVALID);
hegyi@81
    69
  int resetNodeColor (Node new_item=INVALID);
hegyi@28
    70
hegyi@28
    71
  ///Changes the text of line attribute according to the given map.
hegyi@28
    72
  ///\param mapname is the name of the map which contains the new values
alpar@62
    73
  int changeNodeText (std::string mapname, Node new_item=INVALID);
hegyi@81
    74
  int resetNodeText (Node new_item=INVALID);
ladanyi@6
    75
ladanyi@6
    76
  ///Callback for 'ViewZoomIn' action.
ladanyi@6
    77
  virtual void zoomIn();
ladanyi@6
    78
  ///Callback for 'ViewZoomOut' action.
ladanyi@6
    79
  virtual void zoomOut();
ladanyi@6
    80
  ///Callback for 'ViewZoomFit' action.
ladanyi@6
    81
  virtual void zoomFit();
ladanyi@6
    82
  ///Callback for 'ViewZoom100' action.
ladanyi@6
    83
  virtual void zoom100();
ladanyi@6
    84
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@6
    85
  void updateScrollRegion();
ladanyi@6
    86
hegyi@9
    87
  ///This function changes the tool in the graph-editor's hand
hegyi@9
    88
  void changeEditorialTool(int);
hegyi@9
    89
ladanyi@6
    90
protected:
ladanyi@6
    91
ladanyi@6
    92
  //maximizing, minimizing, restoring window, etc. 
ladanyi@6
    93
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@6
    94
ladanyi@6
    95
private:
ladanyi@6
    96
ladanyi@6
    97
  ///This function is responsible for the correct
ladanyi@6
    98
  ///reaction of any action happened in the territory
ladanyi@6
    99
  ///of the canvas
hegyi@25
   100
  ///DEPRECATED!!!!
hegyi@30
   101
  bool eventHandler(GdkEvent* e, Node n);
ladanyi@6
   102
hegyi@9
   103
  ///actual event handler
hegyi@9
   104
  ///
hegyi@9
   105
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@9
   106
  sigc::connection actual_handler;
hegyi@9
   107
hegyi@9
   108
  ///event handler for the case when move-tool is active
hegyi@30
   109
  bool moveEventHandler(GdkEvent*);
hegyi@9
   110
  ///event handler for the case when create_node-tool is active
hegyi@30
   111
  bool createNodeEventHandler(GdkEvent*);
hegyi@9
   112
  ///event handler for the case when create_edge-tool is active
hegyi@30
   113
  bool createEdgeEventHandler(GdkEvent*);
hegyi@13
   114
  ///event handler for the case when eraser-tool is active
hegyi@30
   115
  bool eraserEventHandler(GdkEvent*);
hegyi@32
   116
  ///event handler for the case when edge map editor tool is active
hegyi@30
   117
  bool edgeMapEditEventHandler(GdkEvent*);
hegyi@32
   118
  ///event handler for the case when node map editor tool is active
hegyi@32
   119
  bool nodeMapEditEventHandler(GdkEvent*);
hegyi@13
   120
hegyi@21
   121
public:
hegyi@25
   122
  ///Moves the text to new place
hegyi@30
   123
  void textReposition(xy<double>);
hegyi@25
   124
  ///Activates an edge belonging to a BrokenEdge
hegyi@35
   125
  ///
hegyi@35
   126
  ///After we have activated an edge this way,
hegyi@35
   127
  ///the GDC object will know, which edge is under forming
hegyi@35
   128
  ///therefore it can redraw the necessarz elementy on the canvas,
hegyi@35
   129
  ///for example the text belonging to the \ref BrokenEdge can be
hegyi@35
   130
  ///redrawn (\ref textReposition).
hegyi@30
   131
  void toggleEdgeActivity(BrokenEdge*, bool);
hegyi@25
   132
hegyi@25
   133
public:
hegyi@21
   134
  ///\return the actual tool in hand
hegyi@30
   135
  int getActualTool();
hegyi@21
   136
ladanyi@53
   137
  void drawGraph();
ladanyi@53
   138
  void clear();
ladanyi@53
   139
hegyi@37
   140
  ///creates a new Nodemap
hegyi@46
   141
  int addNewNodeMap(double,std::string);
hegyi@37
   142
  ///creates a new Edgemap
hegyi@46
   143
  int addNewEdgeMap(double,std::string);
hegyi@37
   144
hegyi@21
   145
private:
hegyi@14
   146
  ///Deletes the given element.
alpar@62
   147
  void deleteItem(Node);
hegyi@14
   148
  ///Deletes the given element.
alpar@62
   149
  void deleteItem(Edge);
hegyi@9
   150
hegyi@21
   151
private:
hegyi@21
   152
ladanyi@6
   153
  ///Map of nodes of graph
ladanyi@6
   154
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
   155
ladanyi@6
   156
  ///Map of edges of graph
hegyi@19
   157
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@6
   158
ladanyi@6
   159
  ///Map of texts to write on edges
ladanyi@6
   160
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
   161
hegyi@28
   162
  ///Map of texts to write on nodes
hegyi@28
   163
  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
hegyi@28
   164
ladanyi@6
   165
  ///Group of graphical elements of displayed_graph
ladanyi@6
   166
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
   167
hegyi@88
   168
public:
ladanyi@6
   169
  ///Here we store the maps that can be displayed through properties.
hegyi@40
   170
  MapStorage & mapstorage;
ladanyi@6
   171
hegyi@88
   172
private:
ladanyi@6
   173
  ///Indicates whether the button of mouse is pressed or not
hegyi@20
   174
  int isbutton;
ladanyi@6
   175
hegyi@21
   176
  ///Stores the actual tool in hand
hegyi@21
   177
  int actual_tool;
hegyi@21
   178
ladanyi@6
   179
  ///At this location was the mousebutton pressed.
ladanyi@6
   180
  ///It helps to calculate the distance of dragging.
ladanyi@6
   181
  double clicked_x, clicked_y;
ladanyi@6
   182
ladanyi@6
   183
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
   184
  ///this variable is needed, because
ladanyi@6
   185
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
   186
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@11
   187
  Gnome::Canvas::Item * active_item, * target_item;
alpar@62
   188
  Node active_node;
alpar@62
   189
  Edge active_edge;
alpar@62
   190
  Edge forming_edge;
hegyi@35
   191
hegyi@35
   192
  std::string nodemap_to_edit, edgemap_to_edit;
ladanyi@6
   193
ladanyi@6
   194
  static const int zoom_step = 5;
hegyi@19
   195
hegyi@88
   196
public:
hegyi@28
   197
  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
ladanyi@53
   198
  MapWin & mapwin;
hegyi@28
   199
hegyi@88
   200
private:
hegyi@88
   201
ladanyi@66
   202
  ///pointer to the parent window
hegyi@55
   203
  Gtk::Window * parentwin;
hegyi@55
   204
ladanyi@6
   205
};
ladanyi@6
   206
ladanyi@6
   207
#endif //GRAPH_DISPLAYER_CANVAS_H