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