gui/graph_displayer_canvas.h
author deba
Fri, 16 Sep 2005 09:01:20 +0000
changeset 1686 a5b8e0fde2be
parent 1643 9285f3777553
child 1731 616bc933c2bc
permissions -rw-r--r--
Using std:: prefix for the functions in the c* headers
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
alpar@1643
    26
  int changeEdgeWidth (std::string mapname, 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
alpar@1643
    30
  int changeEdgeColor (std::string mapname, 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
alpar@1643
    34
  int changeEdgeText (std::string mapname, 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
alpar@1643
    38
  int changeNodeRadius (std::string mapname, 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
alpar@1643
    42
  int changeNodeColor (std::string mapname, 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
alpar@1643
    46
  int changeNodeText (std::string mapname, 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@1501
    93
public:
hegyi@1505
    94
  ///Moves the text to new place
hegyi@1524
    95
  void textReposition(xy<double>);
hegyi@1505
    96
  ///Activates an edge belonging to a BrokenEdge
hegyi@1579
    97
  ///
hegyi@1579
    98
  ///After we have activated an edge this way,
hegyi@1579
    99
  ///the GDC object will know, which edge is under forming
hegyi@1579
   100
  ///therefore it can redraw the necessarz elementy on the canvas,
hegyi@1579
   101
  ///for example the text belonging to the \ref BrokenEdge can be
hegyi@1579
   102
  ///redrawn (\ref textReposition).
hegyi@1524
   103
  void toggleEdgeActivity(BrokenEdge*, bool);
hegyi@1505
   104
hegyi@1505
   105
public:
hegyi@1501
   106
  ///\return the actual tool in hand
hegyi@1524
   107
  int getActualTool();
hegyi@1501
   108
ladanyi@1606
   109
  void drawGraph();
ladanyi@1606
   110
  void clear();
ladanyi@1606
   111
hegyi@1585
   112
  ///creates a new Nodemap
hegyi@1597
   113
  int addNewNodeMap(double,std::string);
hegyi@1585
   114
  ///creates a new Edgemap
hegyi@1597
   115
  int addNewEdgeMap(double,std::string);
hegyi@1585
   116
hegyi@1501
   117
private:
hegyi@1486
   118
  ///Deletes the given element.
alpar@1643
   119
  void deleteItem(Node);
hegyi@1486
   120
  ///Deletes the given element.
alpar@1643
   121
  void deleteItem(Edge);
hegyi@1468
   122
hegyi@1501
   123
private:
hegyi@1501
   124
ladanyi@1442
   125
  ///Map of nodes of graph
ladanyi@1442
   126
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@1442
   127
ladanyi@1442
   128
  ///Map of edges of graph
hegyi@1499
   129
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@1442
   130
ladanyi@1442
   131
  ///Map of texts to write on edges
ladanyi@1442
   132
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@1442
   133
hegyi@1512
   134
  ///Map of texts to write on nodes
hegyi@1512
   135
  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
hegyi@1512
   136
ladanyi@1442
   137
  ///Group of graphical elements of displayed_graph
ladanyi@1442
   138
  Gnome::Canvas::Group displayed_graph;
ladanyi@1442
   139
ladanyi@1442
   140
  ///Here we store the maps that can be displayed through properties.
hegyi@1589
   141
  MapStorage & mapstorage;
ladanyi@1442
   142
ladanyi@1442
   143
  ///Indicates whether the button of mouse is pressed or not
hegyi@1500
   144
  int isbutton;
ladanyi@1442
   145
hegyi@1501
   146
  ///Stores the actual tool in hand
hegyi@1501
   147
  int actual_tool;
hegyi@1501
   148
ladanyi@1442
   149
  ///At this location was the mousebutton pressed.
ladanyi@1442
   150
  ///It helps to calculate the distance of dragging.
ladanyi@1442
   151
  double clicked_x, clicked_y;
ladanyi@1442
   152
ladanyi@1442
   153
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@1442
   154
  ///this variable is needed, because
ladanyi@1442
   155
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@1442
   156
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@1474
   157
  Gnome::Canvas::Item * active_item, * target_item;
alpar@1643
   158
  Node active_node;
alpar@1643
   159
  Edge active_edge;
alpar@1643
   160
  Edge forming_edge;
hegyi@1579
   161
hegyi@1579
   162
  std::string nodemap_to_edit, edgemap_to_edit;
ladanyi@1442
   163
ladanyi@1442
   164
  static const int zoom_step = 5;
hegyi@1499
   165
hegyi@1512
   166
  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
ladanyi@1606
   167
  MapWin & mapwin;
hegyi@1512
   168
ladanyi@1648
   169
  ///pointer to the parent window
hegyi@1614
   170
  Gtk::Window * parentwin;
hegyi@1614
   171
ladanyi@1442
   172
};
ladanyi@1442
   173
ladanyi@1442
   174
#endif //GRAPH_DISPLAYER_CANVAS_H