graph_displayer_canvas.h
author alpar
Thu, 18 Aug 2005 13:33:49 +0000
branchgui
changeset 62 80eefca04b1e
parent 55 e4ee805ca5fc
child 66 4ca5a537ef07
permissions -rw-r--r--
- The number of gcc-4.0 warnings has significantly decreases.
- Some code clean-up in gui
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 "broken_edge.h"
ladanyi@53
    11
#include "map_win.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@55
    21
  GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
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
alpar@62
    26
  int changeEdgeWidth (std::string mapname, 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
alpar@62
    30
  int changeEdgeColor (std::string mapname, 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
alpar@62
    34
  int changeEdgeText (std::string mapname, 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
alpar@62
    38
  int changeNodeRadius (std::string mapname, 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
alpar@62
    42
  int changeNodeColor (std::string mapname, 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
alpar@62
    46
  int changeNodeText (std::string mapname, 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!!!!
hegyi@30
    73
  bool eventHandler(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@30
    81
  bool moveEventHandler(GdkEvent*);
hegyi@9
    82
  ///event handler for the case when create_node-tool is active
hegyi@30
    83
  bool createNodeEventHandler(GdkEvent*);
hegyi@9
    84
  ///event handler for the case when create_edge-tool is active
hegyi@30
    85
  bool createEdgeEventHandler(GdkEvent*);
hegyi@13
    86
  ///event handler for the case when eraser-tool is active
hegyi@30
    87
  bool eraserEventHandler(GdkEvent*);
hegyi@32
    88
  ///event handler for the case when edge map editor tool is active
hegyi@30
    89
  bool edgeMapEditEventHandler(GdkEvent*);
hegyi@32
    90
  ///event handler for the case when node map editor tool is active
hegyi@32
    91
  bool nodeMapEditEventHandler(GdkEvent*);
hegyi@13
    92
hegyi@34
    93
  ///event handler for the case when the entry widget is changed
hegyi@34
    94
  bool entryWidgetChangeHandler(GdkEvent*);
hegyi@34
    95
hegyi@21
    96
public:
hegyi@25
    97
  ///Moves the text to new place
hegyi@30
    98
  void textReposition(xy<double>);
hegyi@25
    99
  ///Activates an edge belonging to a BrokenEdge
hegyi@35
   100
  ///
hegyi@35
   101
  ///After we have activated an edge this way,
hegyi@35
   102
  ///the GDC object will know, which edge is under forming
hegyi@35
   103
  ///therefore it can redraw the necessarz elementy on the canvas,
hegyi@35
   104
  ///for example the text belonging to the \ref BrokenEdge can be
hegyi@35
   105
  ///redrawn (\ref textReposition).
hegyi@30
   106
  void toggleEdgeActivity(BrokenEdge*, bool);
hegyi@25
   107
hegyi@25
   108
public:
hegyi@21
   109
  ///\return the actual tool in hand
hegyi@30
   110
  int getActualTool();
hegyi@21
   111
ladanyi@53
   112
  void drawGraph();
ladanyi@53
   113
  void clear();
ladanyi@53
   114
hegyi@37
   115
  ///creates a new Nodemap
hegyi@46
   116
  int addNewNodeMap(double,std::string);
hegyi@37
   117
  ///creates a new Edgemap
hegyi@46
   118
  int addNewEdgeMap(double,std::string);
hegyi@37
   119
hegyi@21
   120
private:
hegyi@14
   121
  ///Deletes the given element.
alpar@62
   122
  void deleteItem(Node);
hegyi@14
   123
  ///Deletes the given element.
alpar@62
   124
  void deleteItem(Edge);
hegyi@9
   125
hegyi@21
   126
private:
hegyi@21
   127
ladanyi@6
   128
  ///Map of nodes of graph
ladanyi@6
   129
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
   130
ladanyi@6
   131
  ///Map of edges of graph
hegyi@19
   132
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@6
   133
ladanyi@6
   134
  ///Map of texts to write on edges
ladanyi@6
   135
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
   136
hegyi@28
   137
  ///Map of texts to write on nodes
hegyi@28
   138
  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
hegyi@28
   139
ladanyi@6
   140
  ///Group of graphical elements of displayed_graph
ladanyi@6
   141
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
   142
hegyi@32
   143
  ///Map editor entry
hegyi@32
   144
  Gtk::Entry entrywidget;
hegyi@32
   145
hegyi@32
   146
  ///GnomeCanvas holder for entry
hegyi@32
   147
  Gnome::Canvas::Widget * canvasentrywidget;
hegyi@32
   148
ladanyi@6
   149
  ///Here we store the maps that can be displayed through properties.
hegyi@40
   150
  MapStorage & mapstorage;
ladanyi@6
   151
ladanyi@6
   152
  ///Indicates whether the button of mouse is pressed or not
hegyi@20
   153
  int isbutton;
ladanyi@6
   154
hegyi@21
   155
  ///Stores the actual tool in hand
hegyi@21
   156
  int actual_tool;
hegyi@21
   157
ladanyi@6
   158
  ///At this location was the mousebutton pressed.
ladanyi@6
   159
  ///It helps to calculate the distance of dragging.
ladanyi@6
   160
  double clicked_x, clicked_y;
ladanyi@6
   161
ladanyi@6
   162
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
   163
  ///this variable is needed, because
ladanyi@6
   164
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
   165
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@11
   166
  Gnome::Canvas::Item * active_item, * target_item;
alpar@62
   167
  Node active_node;
alpar@62
   168
  Edge active_edge;
alpar@62
   169
  Edge forming_edge;
hegyi@35
   170
hegyi@35
   171
  std::string nodemap_to_edit, edgemap_to_edit;
ladanyi@6
   172
ladanyi@6
   173
  static const int zoom_step = 5;
hegyi@19
   174
hegyi@28
   175
  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
ladanyi@53
   176
  MapWin & mapwin;
hegyi@28
   177
hegyi@55
   178
  ///We need to store the parent window to be able to set the focus on a given widget
hegyi@55
   179
  ///We will use this variable to activate the set focus on entry widget in the case of editing map values.
hegyi@55
   180
  Gtk::Window * parentwin;
hegyi@55
   181
ladanyi@6
   182
};
ladanyi@6
   183
ladanyi@6
   184
#endif //GRAPH_DISPLAYER_CANVAS_H