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